diff --git a/tests/xharness/MacTestProject.cs b/tests/xharness/MacTestProject.cs index 78ccf1439e..4d45eac716 100644 --- a/tests/xharness/MacTestProject.cs +++ b/tests/xharness/MacTestProject.cs @@ -32,10 +32,6 @@ namespace Xharness { public string Platform = "x86"; - public MacTestProject () : base () - { - } - public MacTestProject (string path, bool isExecutableProject = true, MacFlavors targetFrameworkFlavor = MacFlavors.Full | MacFlavors.Modern) : base (path, isExecutableProject) { TargetFrameworkFlavors = targetFrameworkFlavor; @@ -43,10 +39,14 @@ namespace Xharness { public override TestProject Clone () { - var rv = (MacTestProject) base.Clone (); - rv.TargetFrameworkFlavors = TargetFrameworkFlavors; + return CompleteClone (new MacTestProject (Path, IsExecutableProject, TargetFrameworkFlavors)); + } + + protected override TestProject CompleteClone (TestProject project) + { + var rv = (MacTestProject) project; rv.Platform = Platform; - return rv; + return base.CompleteClone (rv); } public override string ToString () diff --git a/tests/xharness/TestProject.cs b/tests/xharness/TestProject.cs index 2b984fe6d2..9b69ce639c 100644 --- a/tests/xharness/TestProject.cs +++ b/tests/xharness/TestProject.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -13,32 +15,28 @@ using Xharness.Jenkins.TestTasks; namespace Xharness { public class TestProject { - XmlDocument xml; + XmlDocument? xml; bool generate_variations = true; public TestPlatform TestPlatform; public string Path; - public string SolutionPath; - public string Name; + public string? SolutionPath; + public string? Name; public bool IsExecutableProject; public bool IsNUnitProject; public bool IsDotNetProject; - public string [] Configurations; - public Func Dependency; - public string FailureMessage; + public string []? Configurations; + public Func? Dependency; + public string? FailureMessage; public bool RestoreNugetsInProject = true; - public string MTouchExtraArgs; + public string? MTouchExtraArgs; public double TimeoutMultiplier = 1; public bool? Ignore; - public IEnumerable ProjectReferences; + public IEnumerable? ProjectReferences; // Optional - public MonoNativeInfo MonoNativeInfo { get; set; } - - public TestProject () - { - } + public MonoNativeInfo? MonoNativeInfo { get; set; } public TestProject (string path, bool isExecutableProject = true) { @@ -60,7 +58,11 @@ namespace Xharness { public virtual TestProject Clone () { - TestProject rv = (TestProject) Activator.CreateInstance (GetType ()); + return CompleteClone (new TestProject (Path, IsExecutableProject)); + } + + protected virtual TestProject CompleteClone (TestProject rv) + { rv.Path = Path; rv.IsExecutableProject = IsExecutableProject; rv.IsDotNetProject = IsDotNetProject; @@ -73,13 +75,6 @@ namespace Xharness { return rv; } - internal async Task CreateCloneAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) - { - var rv = Clone (); - await rv.CreateCopyAsync (log, processManager, test, rootDirectory); - return rv; - } - public Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) { var pr = new Dictionary (); @@ -88,7 +83,7 @@ namespace Xharness { async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory, Dictionary allProjectReferences) { - var directory = Cache.CreateTemporaryDirectory (test?.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path)); + var directory = Cache.CreateTemporaryDirectory (test.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path)); Directory.CreateDirectory (directory); var original_path = Path; Path = System.IO.Path.Combine (directory, System.IO.Path.GetFileName (Path)); @@ -244,7 +239,7 @@ namespace Xharness { public override string ToString () { - return Name; + return Name ?? base.ToString (); } } diff --git a/tests/xharness/TestProjectExtensions.cs b/tests/xharness/TestProjectExtensions.cs index 5ca1ea759c..160c304c77 100644 --- a/tests/xharness/TestProjectExtensions.cs +++ b/tests/xharness/TestProjectExtensions.cs @@ -52,10 +52,7 @@ namespace Xharness { return null; if (extensions.Count () != 1) throw new NotImplementedException (); - return new TestProject - { - Path = Path.GetFullPath (Path.Combine (Path.GetDirectoryName (self.Path), Target.ProjectsDir, "today-extension", extensions.First ().Replace ('\\', '/'))), - }; + return new TestProject (Path.GetFullPath (Path.Combine (Path.GetDirectoryName (self.Path), Target.ProjectsDir, "today-extension", extensions.First ().Replace ('\\', '/')))); } } } diff --git a/tests/xharness/iOSTestProject.cs b/tests/xharness/iOSTestProject.cs index 2c6fca728c..f086d419e6 100644 --- a/tests/xharness/iOSTestProject.cs +++ b/tests/xharness/iOSTestProject.cs @@ -12,10 +12,6 @@ namespace Xharness { public bool SkipDeviceVariations; public bool BuildOnly; - public iOSTestProject () - { - } - public iOSTestProject (string path, bool isExecutableProject = true) : base (path, isExecutableProject) { @@ -32,7 +28,12 @@ namespace Xharness { public override TestProject Clone () { - var rv = (iOSTestProject) base.Clone (); + return CompleteClone (new iOSTestProject (Path, IsExecutableProject)); + } + + protected override TestProject CompleteClone (TestProject project) + { + var rv = (iOSTestProject) project; rv.SkipiOSVariation = SkipiOSVariation; rv.SkipwatchOSVariation = SkipwatchOSVariation; rv.SkipwatchOSARM64_32Variation = SkipwatchOSARM64_32Variation; @@ -41,7 +42,7 @@ namespace Xharness { rv.SkipTodayExtensionVariation = SkipTodayExtensionVariation; rv.SkipDeviceVariations = SkipDeviceVariations; rv.BuildOnly = BuildOnly; - return rv; + return base.CompleteClone (rv); } } }