Skip to content
45 changes: 27 additions & 18 deletions tests/xharness/BCLTestImportTargetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ public BCLTestImportTargetFactory (string outputDirectory, string monoRootPath)
/// 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);
public GeneratedProjects GenerateTestProjects (IEnumerable<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> projects, Platform platform)
=> TemplatedProject.GenerateTestProjects (projects, platform);

List<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> GetProjectDefinitions (ProjectsDefinitions definitions, Platform platform)
{
Expand Down Expand Up @@ -318,35 +318,34 @@ public Task<GeneratedProjects> GenerateTestProjectsAsync (IEnumerable<(string Na
return testProjects;
}

async Task<List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier)>> GenerateAlliOSTestProjectsAsync ()
List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier, Task GenerationCompleted)> GenerateAlliOSTestProjects ()
{
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)> ();
var projectPaths = new List<(string Name, string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier, Task GenerationCompleted)> ();
var projects = new Dictionary<string, (string Path, bool XUnit, string ExtraArgs, List<Platform> Platforms, string Failure, double TimeoutMultiplier, Task GenerationCompleted)> ();
foreach (var platform in new [] { Platform.iOS, Platform.TvOS, Platform.WatchOS }) {
var generated = await GenerateTestProjectsAsync (GetProjectDefinitions (commoniOSTestProjects, platform), platform);
var generated = GenerateTestProjects (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);
projects [tp.Name] = (tp.Path, tp.XUnit, tp.ExtraArgs, new List<Platform> { platform }, tp.Failure, tp.TimeoutMultiplier, tp.GenerationCompleted);
} else {
var project = projects [tp.Name];
project.Platforms.Add (platform);
project.TimeoutMultiplier += (tp.TimeoutMultiplier - 1);
project.GenerationCompleted = Task.WhenAll (project.GenerationCompleted, tp.GenerationCompleted);
}
}
} // 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));
foreach (var kvp in projects) {
var name = kvp.Key;
var proj = kvp.Value;
projectPaths.Add ((kvp.Key, proj.Path, proj.XUnit, proj.ExtraArgs, proj.Platforms, proj.Failure, proj.TimeoutMultiplier, proj.GenerationCompleted));
}
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;
public GeneratedProjects GenerateAllMacTestProjects (Platform platform) => GenerateTestProjects (GetProjectDefinitions (macTestProjects, platform), platform);

// Map from the projects understood from the test importer to those that AppRunner and friends understand:
public List<iOSTestProject> GetiOSBclTargets ()
Expand All @@ -356,7 +355,7 @@ public List<iOSTestProject> GetiOSBclTargets ()
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) {
var proj = new iOSTestProject (tp.Path) {
Name = finalName,
SkipiOSVariation = !tp.Platforms.Contains (Platform.iOS),
SkiptvOSVariation = !tp.Platforms.Contains (Platform.TvOS),
Expand All @@ -366,7 +365,12 @@ public List<iOSTestProject> GetiOSBclTargets ()
RestoreNugetsInProject = true,
MTouchExtraArgs = tp.ExtraArgs,
TimeoutMultiplier = tp.TimeoutMultiplier,
});
};
proj.Dependency = async () => {
await tp.GenerationCompleted;
proj.FailureMessage = tp.Failure;
};
result.Add (proj);
}
return result;
}
Expand All @@ -382,14 +386,19 @@ public List<MacTestProject> GetMacBclTargets (MacFlavors flavor)
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) {
var proj = new MacTestProject (tp.Path, targetFrameworkFlavor: flavor) {
Name = finalName,
Platform = "AnyCPU",
IsExecutableProject = true,
FailureMessage = tp.Failure,
RestoreNugetsInProject = true,
MTouchExtraArgs = tp.ExtraArgs,
});
};
proj.Dependency = async () => {
await tp.GenerationCompleted;
proj.FailureMessage = tp.Failure;
};
result.Add (proj);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

namespace Microsoft.DotNet.XHarness.iOS.Shared.TestImporter.Templates {

public class GeneratedProject {
public string Name;
public string Path;
public bool XUnit;
public string ExtraArgs;
public string Failure;
public double TimeoutMultiplier;
public Task GenerationCompleted;
}
// less typing
public class GeneratedProjects : List<(string Name, string Path, bool XUnit, string ExtraArgs, string Failure, double TimeoutMultiplier)> {
public class GeneratedProjects : List<GeneratedProject> {
}

// interface that represent a project that is created from a template.
Expand All @@ -28,6 +37,6 @@ public interface ITemplatedProject {
/// has its own details.</param>
/// <param name="generatedDir">The dir where the projects will be saved.</param>
/// <returns></returns>
Task<GeneratedProjects> GenerateTestProjectsAsync (IEnumerable<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> projects, Platform platform);
GeneratedProjects GenerateTestProjects (IEnumerable<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> projects, Platform platform);
}
}
Loading