Skip to content

Commit

Permalink
[Harness] Merge the Generator and the Factory in a same object and re…
Browse files Browse the repository at this point in the history
…name namespace.

The Generator and the Factory classes are a xamarin-macios thing.
Initially, they were separated because the code that generated the bcl
tests was not inside xharness. That is not longer the case. We can merge
both classes, generalize the namespace and be more prepared to move out
of the xamarin-macios repo.
  • Loading branch information
mandel-macaque committed Mar 28, 2020
1 parent ab95d46 commit ef03b16
Show file tree
Hide file tree
Showing 107 changed files with 238 additions and 276 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Xharness.BCLTestImporter.Templates;
using Xharness.BCLTestImporter.Templates.Managed;
using Xharness.BCLTestImporter.Xamarin;
using Xharness.TestImporter.Templates;
using Xharness.TestImporter.Templates.Managed;
using Xharness.TestImporter.Xamarin;
using Xharness.Utilities;
using Xharness.TestImporter;

namespace Xharness.BCLTestImporter {
namespace Xharness {
/// <summary>
/// Class that knows how to generate .csproj files based on a BCLTestProjectDefinition.
/// </summary>
public class BCLTestProjectGenerator {
public class BCLTestImportTargetFactory {

// less typing
class ProjectsDefinitions : Dictionary<string, (string ExtraArgs, double TimeoutMultiplier, (string Name, string [] Assemblies) [] Projects)> { }
Expand Down Expand Up @@ -248,7 +248,17 @@ public string MacMonoSDKPath {
public ITemplatedProject TemplatedProject { get; set; }
public ITestAssemblyDefinitionFactory AssemblyDefinitionFactory { get; set; }

public BCLTestProjectGenerator (string outputDirectory)
public BCLTestImportTargetFactory (Harness harness) : this (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "bcl-test")), harness.MONO_PATH)
{
if (harness == null)
throw new ArgumentNullException (nameof (harness));
iOSMonoSDKPath = harness.MONO_IOS_SDK_DESTDIR;
MacMonoSDKPath = harness.MONO_MAC_SDK_DESTDIR;
GuidGenerator = Helpers.GenerateStableGuid;
GroupTests = harness.InCI || harness.UseGroupedApps;
}

public BCLTestImportTargetFactory (string outputDirectory)
{
OutputDirectoryPath = outputDirectory ?? throw new ArgumentNullException (nameof (outputDirectory));
AssemblyLocator = new AssemblyLocator ();
Expand All @@ -263,7 +273,7 @@ public BCLTestProjectGenerator (string outputDirectory)
};
}

public BCLTestProjectGenerator (string outputDirectory, string monoRootPath) : this (outputDirectory)
public BCLTestImportTargetFactory (string outputDirectory, string monoRootPath) : this (outputDirectory)
{
MonoRootPath = monoRootPath ?? throw new ArgumentNullException (nameof (monoRootPath));
}
Expand Down Expand Up @@ -336,5 +346,61 @@ public Task<GeneratedProjects> GenerateTestProjectsAsync (IEnumerable<(string Na
public Task<GeneratedProjects> GenerateAllMacTestProjectsAsync (Platform platform) => GenerateTestProjectsAsync (GetProjectDefinitions (macTestProjects, platform), platform);

public GeneratedProjects GenerateAllMacTestProjects (Platform platform) => GenerateAllMacTestProjectsAsync (platform).Result;

// Map from the projects understood from the test importer to those that AppRunner and friends understand:
public List<iOSTestProject> GetiOSBclTargets ()
{
var result = new List<iOSTestProject> ();
// generate all projects, then create a new iOSTarget per project
foreach (var tp in GenerateAlliOSTestProjects ()) {
var prefix = tp.XUnit ? "xUnit" : "NUnit";
var finalName = tp.Name.StartsWith ("mscorlib", StringComparison.Ordinal) ? tp.Name : $"[{prefix}] Mono {tp.Name}"; // mscorlib is our special test
result.Add (new iOSTestProject (tp.Path) {
Name = finalName,
SkipiOSVariation = !tp.Platforms.Contains (Platform.iOS),
SkiptvOSVariation = !tp.Platforms.Contains (Platform.TvOS),
SkipwatchOS32Variation = tp.Name.StartsWith ("mscorlib", StringComparison.Ordinal), // mscorlib is our special test
SkipwatchOSVariation = !tp.Platforms.Contains (Platform.WatchOS),
FailureMessage = tp.Failure,
RestoreNugetsInProject = true,
MTouchExtraArgs = tp.ExtraArgs,
TimeoutMultiplier = tp.TimeoutMultiplier,
});
}
return result;
}

public List<MacTestProject> GetMacBclTargets (MacFlavors flavor)
{
Platform platform;
if (flavor == MacFlavors.Full)
platform = Platform.MacOSFull;
else
platform = Platform.MacOSModern;
var result = new List<MacTestProject> ();
foreach (var tp in GenerateAllMacTestProjects (platform)) {
var prefix = tp.XUnit ? "xUnit" : "NUnit";
var finalName = tp.Name.StartsWith ("mscorlib", StringComparison.Ordinal) ? tp.Name : $"[{prefix}] Mono {tp.Name}"; // mscorlib is our special test
result.Add (new MacTestProject (tp.Path, targetFrameworkFlavor: flavor) {
Name = finalName,
Platform = "AnyCPU",
IsExecutableProject = true,
FailureMessage = tp.Failure,
RestoreNugetsInProject = true,
MTouchExtraArgs = tp.ExtraArgs,
});
}
return result;
}

public List<MacTestProject> GetMacBclTargets ()
{
var result = new List<MacTestProject> ();
foreach (var flavor in new [] { MacFlavors.Full, MacFlavors.Modern }) {
result.AddRange (GetMacBclTargets (flavor));
}
return result;
}

}
}
84 changes: 0 additions & 84 deletions tests/xharness/BCLTestImporter/BCLTestImportTargetFactory.cs

This file was deleted.

18 changes: 8 additions & 10 deletions tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
using System.IO;
using System.Linq;
using System.Xml;
using Xharness.BCLTestImporter;
using Xharness.TestImporter;
using Xharness.Logging;
using Xharness.Execution;
using Xharness.Targets;
using Xharness.Utilities;
using Xharness.Hardware;
using Xharness.Listeners;

namespace Xharness
{
public enum HarnessAction
{
namespace Xharness {
public enum HarnessAction {
None,
Configure,
Run,
Expand Down Expand Up @@ -196,7 +194,7 @@ public Harness (IResultParser resultParser, HarnessAction action, HarnessConfigu
EnvironmentVariables = new Dictionary<string, string> (configuration.EnvironmentVariables);

LaunchTimeout = InCI ? 3 : 120;

var config = ParseConfigFiles ();
var src_root = Path.GetDirectoryName (Path.GetFullPath (RootDirectory));

Expand All @@ -217,7 +215,7 @@ public Harness (IResultParser resultParser, HarnessAction action, HarnessConfigu

if (string.IsNullOrEmpty (SdkRoot))
SdkRoot = config ["XCODE_DEVELOPER_ROOT"] ?? configuration.SdkRoot;

processManager = new ProcessManager (XcodeRoot, MlaunchPath);
}

Expand Down Expand Up @@ -353,7 +351,7 @@ int AutoConfigureMac (bool generate_projects)
configureTarget (target, file, proj.IsNUnitProject, false);
unified_targets.Add (target);

var cloned_project = (MacTestProject) proj.Clone ();
var cloned_project = (MacTestProject)proj.Clone ();
cloned_project.TargetFrameworkFlavors = MacFlavors.Full;
cloned_project.Path = target.ProjectPath;
MacTestProjects.Add (cloned_project);
Expand All @@ -365,7 +363,7 @@ int AutoConfigureMac (bool generate_projects)
configureTarget (target, file, proj.IsNUnitProject, false);
unified_targets.Add (target);

var cloned_project = (MacTestProject) proj.Clone ();
var cloned_project = (MacTestProject)proj.Clone ();
cloned_project.TargetFrameworkFlavors = MacFlavors.System;
cloned_project.Path = target.ProjectPath;
MacTestProjects.Add (cloned_project);
Expand Down Expand Up @@ -449,7 +447,7 @@ Dictionary<string, string> ParseConfigFiles ()
return configuration;
}

IEnumerable <string> GetConfigFiles ()
IEnumerable<string> GetConfigFiles ()
{
return FindConfigFiles (useSystemXamarinIOSMac ? "test-system.config" : "test.config")
.Concat (FindConfigFiles ("Make.config"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Threading.Tasks;

namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {
/// <summary>
/// Class that knows how to generate the plist of a test project.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using Xharness.BCLTestImporter.Templates;

namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {
/// <summary>
/// Class that defines a bcl test project. A bcl test project by definition is the combination of the name
/// of the project and a set on assemblies to be tested.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {

// interface that will help locate the test assemblies that are used to create the apps. This way, we can
// point to a specific location from which the asseblies well be referenced. The idea is to allow to download
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using Xharness.BCLTestImporter.Templates;

namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {

// factory that hides the creation of the ITestAssemblyDefinition to hide the concreate class that is used by the
// template.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {
/// <summary>
/// Represents the supported platforms to which we can create projects.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace Xharness.BCLTestImporter.Templates {
namespace Xharness.TestImporter.Templates {

/// <summary>
/// There are cases in which projects are ignored in certain platforms, either because
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Xharness.BCLTestImporter.Templates {
namespace Xharness.TestImporter.Templates {

// less typing
public class GeneratedProjects : List<(string Name, string Path, bool XUnit, string ExtraArgs, string Failure, double TimeoutMultiplier)> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Xharness.BCLTestImporter.Templates.Managed {
namespace Xharness.TestImporter.Templates.Managed {
public static class RegisterTypeGenerator {

static readonly string UsingReplacement = "%USING%";
Expand Down
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Xharness.BCLTestImporter.Templates.Managed {
namespace Xharness.TestImporter.Templates.Managed {

// template project that uses the Xamarin.iOS and Xamarin.Mac frameworks
// to create a testing application for given xunit and nunit test assemblies
Expand All @@ -26,7 +26,7 @@ public class XamariniOSTemplate : ITemplatedProject {
internal static readonly string DownloadPathKey = "%DOWNLOAD PATH%";

// resource related static vars used to copy the embedded src to the hd
static string srcResourcePrefix = "Xharness.BCLTestImporter.Templates.Managed.Resources.src.";
static string srcResourcePrefix = "Xharness.TestImporter.Templates.Managed.Resources.src.";
static string registerTemplateResourceName = "RegisterType.cs";
static string [] [] srcDirectories = new [] {
new [] { "common", },
Expand Down Expand Up @@ -80,7 +80,7 @@ public class XamariniOSTemplate : ITemplatedProject {
public string OutputDirectoryPath { get; set; }
string GeneratedCodePathRoot => Path.Combine (OutputDirectoryPath, "generated");
public string IgnoreFilesRootDirectory { get; set; }
public IAssemblyLocator AssemblyLocator { get; set; }
public IAssemblyLocator AssemblyLocator { get; set; }
public IProjectFilter ProjectFilter { get; set; }
public ITestAssemblyDefinitionFactory AssemblyDefinitionFactory { get; set; }

Expand Down Expand Up @@ -625,7 +625,7 @@ async Task<GeneratedProjects> GenerateMacTestProjectsAsync (IEnumerable<(string
Directory.CreateDirectory (generatedCodeDir);
var registerTypePath = Path.Combine (generatedCodeDir, "RegisterType-mac.cs");

var typesPerAssembly = projectDefinition.GetTypeForAssemblies (AssemblyLocator.GetAssembliesRootLocation (platform), platform);
var typesPerAssembly = projectDefinition.GetTypeForAssemblies (AssemblyLocator.GetAssembliesRootLocation (platform), platform);
var registerCode = await RegisterTypeGenerator.GenerateCodeAsync (typesPerAssembly,
projectDefinition.IsXUnit, GetRegisterTypeTemplate ());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using Xharness.BCLTestImporter.Templates;

namespace Xharness.BCLTestImporter.Xamarin {
namespace Xharness.TestImporter.Xamarin {
public class AssemblyDefinitionFactory : ITestAssemblyDefinitionFactory {
public ITestAssemblyDefinition Create (string assembly, IAssemblyLocator loader) => new TestAssemblyDefinition (assembly, loader);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using Xharness.BCLTestImporter.Templates;

namespace Xharness.BCLTestImporter.Xamarin {
namespace Xharness.TestImporter.Xamarin {

/// <summary>
/// Implemenation of the assembly locator that will return the root path of the mono bcl artifact.
Expand Down
Loading

0 comments on commit ef03b16

Please sign in to comment.