Skip to content

Commit

Permalink
[Harness] Move the project templates out of the harness dir. (#8088)
Browse files Browse the repository at this point in the history
Move the project templates to be a resource in the dll. That way we can
move all the code outside of xharness and used it outside. This is not a
fill refactor but a first step to decouple the bcl test generation from
the xamarin-macios project.

XHarness should not see a difference, everythign works and simply makes
the dlls larger due to the new resources.

The code is going to take into account that the mono team will want to
use and unmanaged template with no dependencies on Xamarin.iOS and
Xamarin.Mac.
  • Loading branch information
mandel-macaque authored Mar 12, 2020
1 parent ed77f3b commit 16a84bd
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Collections.Generic;

namespace BCLTestImporter {
namespace Xharness.BCLTestImporter {
public struct BCLTestAssemblyDefinition {

#region static vars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Collections.Generic;
using BCLTestImporter;

namespace Xharness.BCLTestImporter {
// Class that is use as the connection between xharness and the BCLImporter
Expand Down
12 changes: 6 additions & 6 deletions tests/xharness/BCLTestImporter/BCLTestInfoPlistGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Threading.Tasks;

namespace BCLTestImporter {
namespace Xharness.BCLTestImporter {
/// <summary>
/// Class that knows how to generate the plist of a test project.
/// </summary>
Expand All @@ -11,14 +11,14 @@ public class BCLTestInfoPlistGenerator {
internal static string IndentifierReplacement = "%BUNDLE INDENTIFIER%";
internal static string WatchAppIndentifierReplacement = "%WATCHAPP INDENTIFIER%";

public static async Task<string> GenerateCodeAsync (string templatePath, string projectName)
public static async Task<string> GenerateCodeAsync (Stream template, string projectName)
{
if (templatePath == null)
throw new ArgumentNullException (nameof (templatePath));
if (template == null)
throw new ArgumentNullException (nameof (template));
if (projectName == null)
throw new ArgumentNullException (nameof (projectName));
// got the lines we want to add, read the template and substitute
using (var reader = new StreamReader(templatePath)) {
using (var reader = new StreamReader(template)) {
var result = await reader.ReadToEndAsync ();
result = result.Replace (ApplicationNameReplacement, projectName);
result = result.Replace (IndentifierReplacement, $"com.xamarin.bcltests.{projectName}");
Expand All @@ -28,6 +28,6 @@ public static async Task<string> GenerateCodeAsync (string templatePath, string
}

// Generates the code for the type registration using the give path to the template to use
public static string GenerateCode (string templatePath, string projectName) => GenerateCodeAsync (templatePath, projectName).Result;
public static string GenerateCode (Stream template, string projectName) => GenerateCodeAsync (template, projectName).Result;
}
}
2 changes: 1 addition & 1 deletion tests/xharness/BCLTestImporter/BCLTestProjectDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using System.Collections.Generic;

namespace BCLTestImporter {
namespace Xharness.BCLTestImporter {
/// <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
99 changes: 32 additions & 67 deletions tests/xharness/BCLTestImporter/BCLTestProjectGenerator.cs

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion tests/xharness/BCLTestImporter/Platform.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BCLTestImporter {
namespace Xharness.BCLTestImporter {
/// <summary>
/// Represents the supported platforms to which we can create projects.
/// </summary>
Expand All @@ -9,4 +9,12 @@ public enum Platform {
MacOSFull,
MacOSModern,
}

/// <summary>
/// Represents the different types of wathcOS apps.
/// </summary>
public enum WatchAppType {
App,
Extension
}
}
4 changes: 1 addition & 3 deletions tests/xharness/BCLTestImporter/RegisterTypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;

namespace BCLTestImporter {
namespace Xharness.BCLTestImporter {
public static class RegisterTypeGenerator {

static readonly string UsingReplacement = "%USING%";
Expand Down
14 changes: 14 additions & 0 deletions tests/xharness/BCLTestImporter/Templates/ITemplatedProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.IO;

namespace Xharness.BCLTestImporter.Templates {
// interface that represent a project that is created from a template.
// The interface should be able to generate a project that will later be
// used by the AppRunner to execute tests.
public interface ITemplatedProject {
Stream GetProjectTemplate (Platform platform);
Stream GetProjectTemplate (WatchAppType appType);
Stream GetPlistTemplate (Platform platform);
Stream GetPlistTemplate (WatchAppType appType);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Xharness.BCLTestImporter.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
public class XamariniOSTemplate : ITemplatedProject {
static readonly Dictionary<Platform, string> plistTemplateMatches = new Dictionary<Platform, string> {
{Platform.iOS, "Managed.iOS.plist.in"},
{Platform.TvOS, "Managed.tvOS.plist.in"},
{Platform.WatchOS, "Managed.watchOS.plist.in"},
{Platform.MacOSFull, "Managed.macOS.plist.in"},
{Platform.MacOSModern, "Managed.macOS.plist.in"},
};
static readonly Dictionary<Platform, string> projectTemplateMatches = new Dictionary<Platform, string> {
{Platform.iOS, "Managed.iOS.csproj.in"},
{Platform.TvOS, "Managed.tvOS.csproj.in"},
{Platform.WatchOS, "Managed.watchOS.csproj.in"},
{Platform.MacOSFull, "Managed.macOS.csproj.in"},
{Platform.MacOSModern, "Managed.macOS.csproj.in"},
};
static readonly Dictionary<WatchAppType, string> watchOSProjectTemplateMatches = new Dictionary<WatchAppType, string>
{
{ WatchAppType.App, "Managed.watchOS.App.csproj.in"},
{ WatchAppType.Extension, "Managed.watchOS.Extension.csproj.in"}
};



static readonly Dictionary<WatchAppType, string> watchOSPlistTemplateMatches = new Dictionary<WatchAppType, string> {
{WatchAppType.App, "Managed.watchOS.App.plist.in"},
{WatchAppType.Extension, "Managed.watchOS.Extension.plist.in"}
};

Stream GetTemplateStream (string templateName)
{
var name = GetType ().Assembly.GetManifestResourceNames ().Where (a => a.EndsWith (templateName, StringComparison.Ordinal)).FirstOrDefault ();
return GetType ().Assembly.GetManifestResourceStream (name);
}

public Stream GetPlistTemplate (Platform platform) => GetTemplateStream (plistTemplateMatches [platform]);

public Stream GetPlistTemplate (WatchAppType appType) => GetTemplateStream (watchOSPlistTemplateMatches [appType]);

public Stream GetProjectTemplate (Platform platform) => GetTemplateStream (projectTemplateMatches [platform]);

public Stream GetProjectTemplate (WatchAppType appType) => GetTemplateStream (watchOSProjectTemplateMatches [appType]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

using NUnit.Framework;

using BCLTestImporter;
using System.Threading.Tasks;
using Xharness.BCLTestImporter;

namespace Xharness.Tests.BCLTestImporter.Tests {
public class BCLTestInfoPlistGeneratorTest {
Expand All @@ -19,8 +19,10 @@ public void GenerateCodeNullTemplateFile ()
[Test]
public void GenerateCodeNullProjectName ()
{
var tmp = Path.GetTempFileName ();
Assert.ThrowsAsync <ArgumentNullException> (() =>
BCLTestInfoPlistGenerator.GenerateCodeAsync ("A/path", null));
BCLTestInfoPlistGenerator.GenerateCodeAsync (File.Create (tmp), null));
File.Delete (tmp);
}

[Test]
Expand All @@ -34,7 +36,7 @@ public async Task GenerateCode ()
await file.WriteAsync (fakeTemplate);
}

var result = await BCLTestInfoPlistGenerator.GenerateCodeAsync (templatePath, projectName);
var result = await BCLTestInfoPlistGenerator.GenerateCodeAsync (File.OpenRead (templatePath), projectName);
try {
StringAssert.DoesNotContain (BCLTestInfoPlistGenerator.ApplicationNameReplacement, result);
StringAssert.DoesNotContain (BCLTestInfoPlistGenerator.IndentifierReplacement, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using System.IO;
using System.Text;
using NUnit.Framework;

using BCLTestImporter;

using Xharness.BCLTestImporter;

namespace Xharness.Tests.BCLTestImporter.Tests {

public class BCLTestProjectGeneratorTest
Expand Down Expand Up @@ -51,9 +50,9 @@ public void GetProjectPath (string projectName, Platform platform, string expect
Assert.AreEqual (Path.Combine (generator.OutputDirectoryPath, expectedName), path);
}

[TestCase ("WatchApp", BCLTestProjectGenerator.WatchAppType.App, "WatchApp-watchos-app.csproj")]
[TestCase ("WatchExtension", BCLTestProjectGenerator.WatchAppType.Extension, "WatchExtension-watchos-extension.csproj")]
public void GetProjectPathWatchOS (string projectName, BCLTestProjectGenerator.WatchAppType appType, string expectedName)
[TestCase ("WatchApp", WatchAppType.App, "WatchApp-watchos-app.csproj")]
[TestCase ("WatchExtension", WatchAppType.Extension, "WatchExtension-watchos-extension.csproj")]
public void GetProjectPathWatchOS (string projectName, WatchAppType appType, string expectedName)
{
// ignore the fact that all params are the same, we do not care
var generator = new BCLTestProjectGenerator (outputdir, outputdir, outputdir, outputdir, outputdir);
Expand All @@ -71,9 +70,9 @@ public void GetPListPath (string rootDir, Platform platform, string expectedName
Assert.AreEqual (Path.Combine (rootDir, expectedName), path);
}

[TestCase ("/usr/bin", BCLTestProjectGenerator.WatchAppType.App, "Info-watchos-app.plist")]
[TestCase ("/usr/local", BCLTestProjectGenerator.WatchAppType.Extension, "Info-watchos-extension.plist")]
public void GetPListPathWatchOS (string rootDir, BCLTestProjectGenerator.WatchAppType appType, string expectedName)
[TestCase ("/usr/bin", WatchAppType.App, "Info-watchos-app.plist")]
[TestCase ("/usr/local", WatchAppType.Extension, "Info-watchos-extension.plist")]
public void GetPListPathWatchOS (string rootDir, WatchAppType appType, string expectedName)
{
var path = BCLTestProjectGenerator.GetPListPath (rootDir, appType);
Assert.AreEqual (Path.Combine (rootDir, expectedName), path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.IO;

using NUnit.Framework;


using BCLTestImporter;
using Xharness.BCLTestImporter;

namespace Xharness.Tests.BCLTestImporter.Tests {
public class TestAssemblyDefinitionTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Collections.Generic;

using NUnit.Framework;


using BCLTestImporter;
using Xharness.BCLTestImporter;

namespace Xharness.Tests.BCLTestImporter.Tests {
public class TestProjectDefinitionTest {
Expand Down
21 changes: 21 additions & 0 deletions tests/xharness/xharness.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
<Compile Include="Utilities\StringUtils.cs" />
<Compile Include="Utilities\TempDirectory.cs" />
<Compile Include="XmlResultParser.cs" />
<Compile Include="BCLTestImporter\Templates\ITemplatedProject.cs" />
<Compile Include="BCLTestImporter\Templates\Managed\XamariniOSTemplate.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\tools\mtouch\SdkVersions.cs">
Expand All @@ -164,5 +166,24 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="BCLTestImporter\Templates\" />
<Folder Include="BCLTestImporter\Templates\Managed\" />
<Folder Include="BCLTestImporter\Templates\Managed\Resources\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.iOS.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.macOS.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.tvOS.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.App.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.iOS.plist.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.macOS.plist.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.plist.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.Extension.csproj.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.tvOS.plist.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.App.plist.in" />
<EmbeddedResource Include="BCLTestImporter\Templates\Managed\Resources\Managed.watchOS.Extension.plist.in" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

2 comments on commit 16a84bd

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚧 Experimental DDFun pipeline

🔥 Device tests completed (Failed) on iOS-DDFun on Azure DevOps(iOS-DDFun) 🔥

Test results

14 tests failed, 136 tests passed.

Failed tests

  • monotouch-test/iOS Unified 64-bits - device/Debug: Crashed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug): Crashed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Crashed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Crashed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Release: Crashed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (release): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Debug (dynamic registrar): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Release (all optimizations): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Debug (all optimizations): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Debug: SGenConc: Crashed
  • monotouch-test/iOS Unified 64-bits - device/Debug (interpreter): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Debug (interpreter -mscorlib): Crashed
  • monotouch-test/iOS Unified 64-bits - device/Release (interpreter -mscorlib): Crashed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Running XM tests on '10.11', Running XM tests on '10.10', Running XM tests on '10.10'' 🔥

Build succeeded
✅ Packages:

API Diff (from stable)
API Diff (from PR only) (no change)
Generator Diff (no change)
🔥 Xamarin.Mac tests on 10.11 failed: Xamarin.Mac tests on macOS 10.11 failed (xammac_tests) 🔥
🔥 Xamarin.Mac tests on 10.10 failed: Xamarin.Mac tests on macOS 10.10 failed (xammac_tests) 🔥
🔥 Test run failed 🔥

Test results

2 tests failed, 182 tests passed.

Failed tests

  • xammac tests/Mac Modern/Debug: Failed (Test run failed.)
  • monotouch-test/tvOS - simulator/Release (all optimizations): Failed

Please sign in to comment.