[Harness] Merge the Generator and the Factory in a same object and rename namespace. (#8222)

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.
This commit is contained in:
Manuel de la Pena 2020-03-30 23:23:33 -04:00 коммит произвёл GitHub
Родитель 63fcc22bad
Коммит f383593924
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
107 изменённых файлов: 569 добавлений и 267 удалений

Просмотреть файл

@ -0,0 +1,406 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Collections.Generic;
using Xharness.TestImporter.Templates;
using Xharness.TestImporter.Templates.Managed;
using Xharness.TestImporter.Xamarin;
using Xharness.Utilities;
using Xharness.TestImporter;
namespace Xharness {
/// <summary>
/// Class that knows how to generate .csproj files based on a BCLTestProjectDefinition.
/// </summary>
public class BCLTestImportTargetFactory {
// less typing
class ProjectsDefinitions : Dictionary<string, (string ExtraArgs, double TimeoutMultiplier, (string Name, string [] Assemblies) [] Projects)> { }
// we have two different types of list, those that are for the iOS like projects (ios, tvos and watch os) and those
// for mac
static readonly ProjectsDefinitions commoniOSTestProjects = new ProjectsDefinitions {
// NUNIT TESTS
["BCL tests group 1"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
(Name: "SystemCoreTests", Assemblies: new [] { "monotouch_System.Core_test.dll" }),
(Name: "SystemNumericsTests", Assemblies: new [] { "monotouch_System.Numerics_test.dll" }),
(Name: "SystemRuntimeSerializationTests", Assemblies: new [] { "monotouch_System.Runtime.Serialization_test.dll" }),
(Name: "SystemTransactionsTests", Assemblies: new [] { "monotouch_System.Transactions_test.dll" }),
(Name: "SystemXmlTests", Assemblies: new [] { "monotouch_System.Xml_test.dll" }),
(Name: "SystemXmlLinqTests", Assemblies: new [] { "monotouch_System.Xml.Linq_test.dll" }),
(Name: "MonoSecurityTests", Assemblies: new [] { "monotouch_Mono.Security_test.dll" }),
(Name: "SystemComponentModelDataAnnotationsTests", Assemblies: new [] { "monotouch_System.ComponentModel.DataAnnotations_test.dll" }),
(Name: "SystemJsonTests", Assemblies: new [] { "monotouch_System.Json_test.dll" }),
(Name: "SystemServiceModelWebTests", Assemblies: new [] { "monotouch_System.ServiceModel.Web_test.dll" }),
(Name: "SystemIOCompressionTests", Assemblies: new [] { "monotouch_System.IO.Compression_test.dll" }),
(Name: "SystemIOCompressionFileSystemTests", Assemblies: new [] { "monotouch_System.IO.Compression.FileSystem_test.dll" }),
(Name: "MonoCSharpTests", Assemblies: new [] { "monotouch_Mono.CSharp_test.dll" }),
(Name: "SystemSecurityTests", Assemblies: new [] { "monotouch_System.Security_test.dll" }),
(Name: "MonoDataSqliteTests", Assemblies: new [] { "monotouch_Mono.Data.Sqlite_test.dll" }),
(Name: "MonoRuntimeTests", Assemblies: new [] { "monotouch_Mono.Runtime.Tests_test.dll" }),
}),
["BCL tests group 2"] = (
ExtraArgs: null,
TimeoutMultiplier: 2,
Projects: new [] {
( Name: "SystemTests", Assemblies: new[] {"monotouch_System_test.dll" }),
( Name: "SystemDataTests", Assemblies: new [] { "monotouch_System.Data_test.dll" }),
( Name: "SystemDataDataSetExtensionsTests", Assemblies: new [] { "monotouch_System.Data.DataSetExtensions_test.dll" }),
( Name: "SystemNetHttpTests", Assemblies: new [] { "monotouch_System.Net.Http_test.dll" }),
( Name: "MonoDataTdsTests", Assemblies: new [] { "monotouch_Mono.Data.Tds_test.dll" }),
( Name: "SystemServiceModelTests", Assemblies: new [] { "monotouch_System.ServiceModel_test.dll" }),
( Name: "CorlibTests", Assemblies: new [] { "monotouch_corlib_test.dll" }),
( Name: "SystemWebServicesTests", Assemblies: new [] { "monotouch_System.Web.Services_test.dll" }),
}),
// XUNIT TESTS
["BCL tests group 3"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemDataXunit", Assemblies: new [] { "monotouch_System.Data_xunit-test.dll" }),
( Name: "SystemJsonXunit", Assemblies: new [] { "monotouch_System.Json_xunit-test.dll" }),
( Name: "SystemSecurityXunit", Assemblies: new [] { "monotouch_System.Security_xunit-test.dll" }),
( Name: "SystemLinqXunit", Assemblies: new [] { "monotouch_System.Xml.Linq_xunit-test.dll" }),
( Name: "SystemComponentModelCompositionXunit", Assemblies: new [] { "monotouch_System.ComponentModel.Composition_xunit-test.dll" }),
( Name: "SystemRuntimeSerializationXunit", Assemblies: new [] { "monotouch_System.Runtime.Serialization_xunit-test.dll" }),
( Name: "SystemXmlXunit", Assemblies: new [] { "monotouch_System.Xml_xunit-test.dll" }),
( Name: "SystemRuntimeCompilerServicesUnsafeXunit", Assemblies: new [] { "monotouch_System.Runtime.CompilerServices.Unsafe_xunit-test.dll" }),
}),
["BCL tests group 4"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemNumericsXunit", Assemblies: new [] { "monotouch_System.Numerics_xunit-test.dll" }),
( Name: "MicrosoftCSharpXunit", Assemblies: new [] { "monotouch_Microsoft.CSharp_xunit-test.dll" }),
}),
// BCL tests group 5
["BCL tests group 5"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemNetHttpUnitTestsXunit", Assemblies: new [] { "monotouch_System.Net.Http.UnitTests_xunit-test.dll" }),
( Name: "SystemNetHttpFunctionalTestsXunit", Assemblies: new [] { "monotouch_System.Net.Http.FunctionalTests_xunit-test.dll" }),
}),
// Special assemblies that are in a single application due to their size being to large for the iOS 32b.
["mscorlib Part 1"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "mscorlib Part 1", Assemblies: new [] { "monotouch_corlib_xunit-test.part1.dll" }), // special testcase for the corlib which is later used in xHarness for diff config options
}),
["mscorlib Part 2"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "mscorlib Part 2", Assemblies: new [] { "monotouch_corlib_xunit-test.part2.dll" }),
}),
["mscorlib Part 3"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "mscorlib Part 3", Assemblies: new [] { "monotouch_corlib_xunit-test.part3.dll" }),
}),
["SystemCoreXunit Part 1"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemCoreXunit Part 1", Assemblies: new [] { "monotouch_System.Core_xunit-test.part1.dll" }),
}),
["SystemCoreXunit Part 2"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemCoreXunit Part 2", Assemblies: new [] { "monotouch_System.Core_xunit-test.part2.dll" }),
}),
["SystemXunit"] = (
ExtraArgs: $"--xml={Path.Combine (Harness.RootDirectory, "bcl-test", "SystemXunitLinker.xml")} --optimize=-custom-attributes-removal", // special case due to the need of the extra args,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemXunit", Assemblies: new [] { "monotouch_System_xunit-test.dll" }),
}),
};
private static readonly ProjectsDefinitions macTestProjects = new ProjectsDefinitions {
// NUNIT Projects
["Mac OS X BCL tests group 1"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "MonoDataSqliteTests", Assemblies: new [] { "xammac_net_4_5_Mono.Data.Sqlite_test.dll" }),
( Name: "MonoDataTdsTests", Assemblies: new [] { "xammac_net_4_5_Mono.Data.Tds_test.dll" }),
( Name: "MonoMessagingTests", Assemblies: new [] { "xammac_net_4_5_Mono.Messaging_test.dll" }),
( Name: "MonoPoxisTests", Assemblies: new [] { "xammac_net_4_5_Mono.Posix_test.dll" }),
( Name: "MonoSecurityTests", Assemblies: new [] { "xammac_net_4_5_Mono.Security_test.dll" }),
( Name: "SystemConfigurationTests", Assemblies: new [] { "xammac_net_4_5_System.Configuration_test.dll" }),
( Name: "SystemDataLinqTests", Assemblies: new [] { "xammac_net_4_5_System.Data.Linq_test.dll" }),
( Name: "SystemDataTests", Assemblies: new [] { "xammac_net_4_5_System.Data_test.dll" }),
( Name: "SystemIOCompressionFileSystemTests", Assemblies: new [] { "xammac_net_4_5_System.IO.Compression.FileSystem_test.dll" }),
( Name: "SystemIOCompressionTests", Assemblies: new [] { "xammac_net_4_5_System.IO.Compression_test.dll" }),
( Name: "SystemIdentityModelTests", Assemblies: new [] { "xammac_net_4_5_System.IdentityModel_test.dll" }),
( Name: "SystemJsonTests", Assemblies: new [] { "xammac_net_4_5_System.Json_test.dll" }),
( Name: "SystemMessagingTests", Assemblies: new [] { "xammac_net_4_5_System.Messaging_test.dll" }),
( Name: "SystemNetHttpWebRequestTests", Assemblies: new [] { "xammac_net_4_5_System.Net.Http.WebRequest_test.dll" }),
( Name: "SystemNumericsTests", Assemblies: new [] { "xammac_net_4_5_System.Numerics_test.dll" }),
( Name: "SystemRuntimeSerializationFormattersSoapTests", Assemblies: new [] { "xammac_net_4_5_System.Runtime.Serialization.Formatters.Soap_test.dll" }),
( Name: "SystemRuntimeSerializationTests", Assemblies: new [] { "xammac_net_4_5_System.Runtime.Serialization_test.dll" }),
( Name: "SystemServiceModelWebTest", Assemblies: new [] { "xammac_net_4_5_System.ServiceModel.Web_test.dll" }),
( Name: "SystemServiceModelTests", Assemblies: new [] { "xammac_net_4_5_System.ServiceModel_test.dll" }),
( Name: "SystemTransactionsTests", Assemblies: new [] { "xammac_net_4_5_System.Transactions_test.dll" }),
( Name: "SystemWebServicesTests", Assemblies: new [] { "xammac_net_4_5_System.Web.Services_test.dll" }),
( Name: "SystemXmlLinqTests", Assemblies: new [] { "xammac_net_4_5_System.Xml.Linq_test.dll" }),
( Name: "SystemDataDataSetExtensionsTests", Assemblies: new [] { "xammac_net_4_5_System.Data.DataSetExtensions_test.dll" }),
}),
["Mac OS X BCL tests group 2"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "SystemNetHttpTests", Assemblies: new [] { "xammac_net_4_5_System.Net.Http_test.dll" }), // do not mix with SystemNetHttpWebRequestTests since there is a type collision
( Name: "SystemComponentModelDataAnnotationsTests", Assemblies: new [] { "xammac_net_4_5_System.ComponentModel.DataAnnotations_test.dll" }),
( Name: "SystemCoreTests", Assemblies: new [] { "xammac_net_4_5_System.Core_test.dll" }),
( Name: "SystemSecurityTests", Assemblies: new [] { "xammac_net_4_5_System.Security_test.dll" }),
( Name: "SystemXmlTests", Assemblies: new [] { "xammac_net_4_5_System.Xml_test.dll" }),
( Name: "SystemTests", Assemblies: new [] { "xammac_net_4_5_System_test.dll" }),
( Name: "MonoCSharpTests", Assemblies: new [] { "xammac_net_4_5_Mono.CSharp_test.dll" }), // if add to the first group, it blocks 'til a timeout, mono issue
}),
["Mac OS X BCL tests group 3"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "CorlibTests", Assemblies: new [] { "xammac_net_4_5_corlib_test.dll" }),
}),
// xUnit Projects
["Mac OS X BCL tests group 4"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "MicrosoftCSharpXunit", Assemblies: new [] { "xammac_net_4_5_Microsoft.CSharp_xunit-test.dll" }),
( Name: "SystemComponentModelCompositionXunit", Assemblies: new [] { "xammac_net_4_5_System.ComponentModel.Composition_xunit-test.dll" }),
( Name: "SystemCoreXunit", Assemblies: new [] { "xammac_net_4_5_System.Core_xunit-test.dll" }),
( Name: "SystemDataXunit", Assemblies: new [] { "xammac_net_4_5_System.Data_xunit-test.dll" }),
( Name: "SystemJsonXunit", Assemblies: new [] { "xammac_net_4_5_System.Json_xunit-test.dll" }),
( Name: "SystemNetHttpFunctionalTestsXunit", Assemblies: new [] { "xammac_net_4_5_System.Net.Http.FunctionalTests_xunit-test.dll" }),
( Name: "SystemNetHttpUnitTestsXunit", Assemblies: new [] { "xammac_net_4_5_System.Net.Http.UnitTests_xunit-test.dll" }),
( Name: "SystemNumericsXunit", Assemblies: new [] { "xammac_net_4_5_System.Numerics_xunit-test.dll" }),
( Name: "SystemRuntimeCompilerServicesUnsafeXunit", Assemblies: new [] { "xammac_net_4_5_System.Runtime.CompilerServices.Unsafe_xunit-test.dll" }),
( Name: "SystemSecurityXunit", Assemblies: new [] { "xammac_net_4_5_System.Security_xunit-test.dll" }),
( Name: "SystemXmlLinqXunit", Assemblies: new [] { "xammac_net_4_5_System.Xml.Linq_xunit-test.dll" }),
( Name: "SystemXmlXunit", Assemblies: new [] { "xammac_net_4_5_System.Xml_xunit-test.dll" }),
( Name: "SystemXunit", Assemblies: new [] { "xammac_net_4_5_System_xunit-test.dll" }),
}),
// special testcase for the corlib which is later used in xHarness for diff config options
["mscorlib"] = (
ExtraArgs: null,
TimeoutMultiplier: 1,
Projects: new [] {
( Name: "mscorlib", Assemblies: new [] { "xammac_net_4_5_corlib_xunit-test.dll" }),
}),
};
public bool GroupTests { get; set; }
public string OutputDirectoryPath { get; private set; }
public string MonoRootPath { get; private set; }
public Func<string, Guid> GuidGenerator {
get => TemplatedProject.GuidGenerator;
set => TemplatedProject.GuidGenerator = value;
}
public string iOSMonoSDKPath {
get {
var locator = AssemblyLocator as AssemblyLocator;
return locator?.iOSMonoSDKPath;
}
set {
var locator = AssemblyLocator as AssemblyLocator;
if (locator != null)
locator.iOSMonoSDKPath = value;
}
}
public string MacMonoSDKPath {
get {
var locator = AssemblyLocator as AssemblyLocator;
return locator?.MacMonoSDKPath;
}
set {
var locator = TemplatedProject.AssemblyLocator as AssemblyLocator;
if (locator != null)
locator.MacMonoSDKPath = value;
}
}
public IAssemblyLocator AssemblyLocator { get; set; }
public IProjectFilter ProjectFilter { get; set; }
public ITemplatedProject TemplatedProject { get; set; }
public ITestAssemblyDefinitionFactory AssemblyDefinitionFactory { get; set; }
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 ();
ProjectFilter = new ProjectFilter { AssemblyLocator = AssemblyLocator, IgnoreFilesRootDir = outputDirectory };
AssemblyDefinitionFactory = new AssemblyDefinitionFactory ();
TemplatedProject = new XamariniOSTemplate {
AssemblyLocator = AssemblyLocator,
OutputDirectoryPath = outputDirectory,
IgnoreFilesRootDirectory = outputDirectory,
ProjectFilter = ProjectFilter,
AssemblyDefinitionFactory = AssemblyDefinitionFactory,
};
}
public BCLTestImportTargetFactory (string outputDirectory, string monoRootPath) : this (outputDirectory)
{
MonoRootPath = monoRootPath ?? throw new ArgumentNullException (nameof (monoRootPath));
}
/// <summary>
/// Generates all the project files for the given projects and platform
/// </summary>
/// <param name="projects">The list of projects to be generated.</param>
/// <param name="platform">The platform to which the projects have to be generated. Each platform
/// has its own details.</param>
/// <param name="generatedDir">The dir where the projects will be saved.</param>
/// <returns></returns>
public Task<GeneratedProjects> GenerateTestProjectsAsync (IEnumerable<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> projects, Platform platform)
=> TemplatedProject.GenerateTestProjectsAsync (projects, platform);
List<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> GetProjectDefinitions (ProjectsDefinitions definitions, Platform platform)
{
var testProjects = new List<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> ();
if (platform == Platform.WatchOS || !GroupTests) {
// go over the keys which define the groups, and split them
foreach (var groupName in definitions.Keys) {
var (ExtraArgs, TimeoutMultiplier, Projects) = definitions [groupName];
foreach (var (Name, Assemblies) in Projects) {
testProjects.Add ((Name, Assemblies, ExtraArgs, TimeoutMultiplier));
}
}
} else {
// go over the keys, which define the groups and join all the asseblies in a single array
foreach (var groupName in definitions.Keys) {
var groupedAssemblies = new List<string> ();
var (ExtraArgs, TimeoutMultiplier, Projects) = definitions [groupName];
foreach (var (_, Assemblies) in Projects) {
foreach (var a in Assemblies) {
if (ProjectFilter == null || !ProjectFilter.ExcludeDll (platform, a))
groupedAssemblies.AddRange (Assemblies);
}
}
testProjects.Add ((Name: groupName, Assemblies: groupedAssemblies.ToArray (), ExtraArgs, TimeoutMultiplier));
}
}
return testProjects;
}
async Task<List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier)>> GenerateAlliOSTestProjectsAsync ()
{
var projectPaths = new List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier)> ();
var projects = new Dictionary<string, (string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier)> ();
foreach (var platform in new [] { Platform.iOS, Platform.TvOS, Platform.WatchOS }) {
var generated = await GenerateTestProjectsAsync (GetProjectDefinitions (commoniOSTestProjects, platform), platform);
foreach (var tp in generated) {
if (!projects.ContainsKey (tp.Name)) {
projects [tp.Name] = (tp.Path, tp.XUnit, tp.ExtraArgs, new List<Platform> { platform }, tp.Failure, tp.TimeoutMultiplier);
} else {
var project = projects [tp.Name];
project.Platforms.Add (platform);
project.TimeoutMultiplier += (tp.TimeoutMultiplier - 1);
}
}
} // foreach platform
// return the grouped projects
foreach (var name in projects.Keys) {
projectPaths.Add ((name, projects [name].Path, projects [name].XUnit, projects [name].ExtraArgs, projects [name].Platforms, projects [name].Failure, projects [name].TimeoutMultiplier));
}
return projectPaths;
}
public List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier)> GenerateAlliOSTestProjects () => GenerateAlliOSTestProjectsAsync ().Result;
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;
}
}
}

Просмотреть файл

@ -1,84 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using Xharness.Utilities;
namespace Xharness.BCLTestImporter {
// Class that is use as the connection between xharness and the BCLImporter
// This class knows about both worlds, will get the required information,
// from xharness, that will then be passed to the importer to generate
// the different projects, once those projects are generater, the factory
// will return the iOS targets to be executed.
public class BCLTestImportTargetFactory {
public Harness Harness;
BCLTestProjectGenerator projectGenerator;
public BCLTestImportTargetFactory (Harness harness)
{
Harness = harness;
var outputDir = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "bcl-test"));
projectGenerator = new BCLTestProjectGenerator (outputDir, Harness.MONO_PATH) {
iOSMonoSDKPath = Harness.MONO_IOS_SDK_DESTDIR,
MacMonoSDKPath = Harness.MONO_MAC_SDK_DESTDIR,
GuidGenerator = Helpers.GenerateStableGuid,
GroupTests = Harness.InCI || Harness.UseGroupedApps,
};
}
// generate all the different test targets.
public List<iOSTestProject> GetiOSBclTargets ()
{
var result = new List<iOSTestProject> ();
// generate all projects, then create a new iOSTarget per project
foreach (var tp in projectGenerator.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 projectGenerator.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;
}
}
}

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using Xharness.BCLTestImporter;
using Xharness.TestImporter;
using Xharness.Logging;
using Xharness.Execution;
using Xharness.Targets;
@ -11,10 +11,8 @@ using Xharness.Utilities;
using Xharness.Hardware;
using Xharness.Listeners;
namespace Xharness
{
public enum HarnessAction
{
namespace Xharness {
public enum HarnessAction {
None,
Configure,
Run,
@ -196,7 +194,7 @@ namespace Xharness
EnvironmentVariables = new Dictionary<string, string> (configuration.EnvironmentVariables);
LaunchTimeout = InCI ? 3 : 120;
var config = ParseConfigFiles ();
var src_root = Path.GetDirectoryName (Path.GetFullPath (RootDirectory));
@ -217,7 +215,7 @@ namespace Xharness
if (string.IsNullOrEmpty (SdkRoot))
SdkRoot = config ["XCODE_DEVELOPER_ROOT"] ?? configuration.SdkRoot;
processManager = new ProcessManager (XcodeRoot, MlaunchPath);
}
@ -353,7 +351,7 @@ namespace Xharness
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);
@ -365,7 +363,7 @@ namespace Xharness
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);
@ -449,7 +447,7 @@ namespace Xharness
return configuration;
}
IEnumerable <string> GetConfigFiles ()
IEnumerable<string> GetConfigFiles ()
{
return FindConfigFiles (useSystemXamarinIOSMac ? "test-system.config" : "test.config")
.Concat (FindConfigFiles ("Make.config"))

Просмотреть файл

@ -2,7 +2,7 @@ using System;
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>

Просмотреть файл

@ -3,9 +3,8 @@ using System.IO;
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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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.

Просмотреть файл

@ -1,4 +1,4 @@
namespace Xharness.BCLTestImporter {
namespace Xharness.TestImporter {
/// <summary>
/// Represents the supported platforms to which we can create projects.
/// </summary>

Просмотреть файл

@ -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

Просмотреть файл

@ -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)> {

Просмотреть файл

@ -4,7 +4,7 @@ using System.Text;
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%";

Просмотреть файл

@ -5,7 +5,7 @@ using System.Linq;
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
@ -26,7 +26,7 @@ namespace Xharness.BCLTestImporter.Templates.Managed {
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", },
@ -80,7 +80,7 @@ namespace Xharness.BCLTestImporter.Templates.Managed {
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; }
@ -643,7 +643,7 @@ namespace Xharness.BCLTestImporter.Templates.Managed {
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 ());

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xharness.BCLTestImporter.Templates;
using Xharness.TestImporter.Templates;
namespace Xharness.BCLTestImporter.Xamarin {
namespace Xharness.TestImporter.Xamarin {
public class ProjectFilter : IProjectFilter {
static readonly string splitPattern = ".part";

Просмотреть файл

@ -1,9 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using Xharness.BCLTestImporter.Templates;
namespace Xharness.BCLTestImporter.Xamarin {
namespace Xharness.TestImporter.Xamarin {
public class TestAssemblyDefinition : ITestAssemblyDefinition{
#region properties

Просмотреть файл

@ -4,9 +4,9 @@ using System.IO;
using NUnit.Framework;
using System.Threading.Tasks;
using Xharness.BCLTestImporter;
using Xharness.TestImporter;
namespace Xharness.Tests.BCLTestImporter.Tests {
namespace Xharness.Tests.TestImporter.Tests {
public class BCLTestInfoPlistGeneratorTest {
[Test]

Просмотреть файл

@ -4,11 +4,11 @@ using System.IO;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Xharness.BCLTestImporter;
using Xharness.BCLTestImporter.Templates;
using Xharness.BCLTestImporter.Xamarin;
using Xharness.TestImporter;
using Xharness.TestImporter.Templates;
using Xharness.TestImporter.Xamarin;
namespace Xharness.Tests.BCLTestImporter.Tests {
namespace Xharness.Tests.TestImporter.Tests {
// test the class so that we ensure that we do call the template object and that we are correctly creating the
@ -18,7 +18,7 @@ namespace Xharness.Tests.BCLTestImporter.Tests {
string outputdir;
AssemblyLocator assemblyLocator;
Mock<ITemplatedProject> template;
BCLTestProjectGenerator generator;
BCLTestImportTargetFactory generator;
[SetUp]
public void SetUp ()
@ -28,7 +28,7 @@ namespace Xharness.Tests.BCLTestImporter.Tests {
Directory.CreateDirectory (outputdir);
assemblyLocator = new AssemblyLocator ();
template = new Mock<ITemplatedProject> ();
generator = new BCLTestProjectGenerator (outputdir) {
generator = new BCLTestImportTargetFactory (outputdir) {
AssemblyLocator = assemblyLocator,
TemplatedProject = template.Object
};
@ -45,13 +45,13 @@ namespace Xharness.Tests.BCLTestImporter.Tests {
[Test]
public void ConstructorNullOutputDir ()
{
Assert.Throws<ArgumentNullException> (() => new BCLTestProjectGenerator (null));
Assert.Throws<ArgumentNullException> (() => new BCLTestProjectGenerator (null, ""));
Assert.Throws<ArgumentNullException> (() => new BCLTestImportTargetFactory ((string) null));
Assert.Throws<ArgumentNullException> (() => new BCLTestImportTargetFactory (null, ""));
}
[Test]
public void ConstructorNullMonoDir () =>
Assert.Throws<ArgumentNullException> (() => new BCLTestProjectGenerator ("", null));
Assert.Throws<ArgumentNullException> (() => new BCLTestImportTargetFactory ("", null));
[Test]
public void iOSMonoSDKPathGetterTest ()

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше