[tests] Add Platform/Configuration to TestBase.

This makes it easier to simplify some code later.
This commit is contained in:
Rolf Bjarne Kvinge 2020-10-27 15:25:44 +01:00
Родитель 915f96b885
Коммит 4d9bbaf650
27 изменённых файлов: 87 добавлений и 76 удалений

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

@ -15,12 +15,9 @@ namespace Xamarin.iOS.Tasks {
[TestFixture ("iPhoneSimulator", "Debug")]
[TestFixture ("iPhoneSimulator", "Release")]
public class DotNetTest : ProjectTest {
public string ProjectConfiguration;
public DotNetTest (string platform, string configuration)
: base (platform)
: base (platform, configuration)
{
ProjectConfiguration = configuration;
}
string tfi;

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

@ -8,10 +8,9 @@ namespace Xamarin.iOS.Tasks
[TestFixture ("iPhoneSimulator")]
public class BindingProject : TestBase
{
string Platform;
public BindingProject (string platform)
: base (platform)
{
Platform = platform;
}
[Test]

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

@ -12,15 +12,14 @@ namespace Xamarin.iOS.Tasks
[TestFixture]
public class Bug60536 : ProjectTest
{
public Bug60536 () : base ("iPhoneSimulator")
public Bug60536 ()
: base ("iPhoneSimulator", "Debug")
{
}
[Test]
public void TestACToolTaskCatchesJsonException ()
{
var platform = "iPhoneSimulator";
var config = "Debug";
var target = "Build";
var mtouchPaths = SetupProjectPaths ("Bug60536", "../", true, platform, config);
@ -29,8 +28,8 @@ namespace Xamarin.iOS.Tasks
var project = SetupProject (Engine, csproj);
AppBundlePath = mtouchPaths.AppBundlePath;
Engine.ProjectCollection.SetGlobalProperty("Platform", platform);
Engine.ProjectCollection.SetGlobalProperty("Configuration", config);
Engine.ProjectCollection.SetGlobalProperty ("Platform", Platform);
Engine.ProjectCollection.SetGlobalProperty ("Configuration", Config);
RunTarget (project, "Clean");
Assert.IsFalse (Directory.Exists (AppBundlePath), "App bundle exists after cleanup: {0} ", AppBundlePath);
@ -38,8 +37,8 @@ namespace Xamarin.iOS.Tasks
Assert.IsFalse (Directory.Exists (AppBundlePath + ".mSYM"), "App bundle .mSYM exists after cleanup: {0} ", AppBundlePath + ".mSYM");
var baseDir = Path.GetDirectoryName (csproj);
var objDir = Path.Combine (baseDir, "obj", platform, config);
var binDir = Path.Combine (baseDir, "bin", platform, config);
var objDir = Path.Combine (baseDir, "obj", Platform, Config);
var binDir = Path.Combine (baseDir, "bin", Platform, Config);
if (Directory.Exists (objDir)) {
var path = Directory.EnumerateFiles (objDir, "*.*", SearchOption.AllDirectories).FirstOrDefault ();
@ -62,7 +61,7 @@ namespace Xamarin.iOS.Tasks
Assert.AreEqual (1, Engine.Logger.ErrorEvents.Count, "#RunTarget-ErrorCount" + messages);
}
var expectedFile = Path.Combine ("obj", platform, config, "actool", "cloned-assets", "Assets.xcassets", "AppIcon.appiconset", "Contents.json");
var expectedFile = Path.Combine ("obj", Platform, Config, "actool", "cloned-assets", "Assets.xcassets", "AppIcon.appiconset", "Contents.json");
Assert.AreEqual (expectedFile, Engine.Logger.ErrorEvents[0].File, "File");
Assert.AreEqual (197, Engine.Logger.ErrorEvents[0].LineNumber, "LineNumber");
Assert.AreEqual (4, Engine.Logger.ErrorEvents[0].ColumnNumber, "ColumnNumber");

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

@ -18,11 +18,9 @@ namespace Xamarin.iOS.Tasks
//[TestFixture ("iPhoneSimulator", "Release")]
public class CodesignAppBundle : ProjectTest
{
readonly string config;
public CodesignAppBundle (string platform, string configuration) : base (platform)
public CodesignAppBundle (string platform, string configuration)
: base (platform, configuration)
{
config = configuration;
}
static bool IsCodesigned (string path)
@ -61,7 +59,7 @@ namespace Xamarin.iOS.Tasks
{
bool expectedCodesignResults = Platform != "iPhoneSimulator";
BuildProject ("MyTabbedApplication", Platform, config, clean: true);
BuildProject ("MyTabbedApplication");
AssertProperlyCodesigned (expectedCodesignResults);
@ -79,7 +77,7 @@ namespace Xamarin.iOS.Tasks
EnsureFilestampChange ();
// Rebuild w/ no changes
BuildProject ("MyTabbedApplication", Platform, config, clean: false);
BuildProject ("MyTabbedApplication", clean: false);
AssertProperlyCodesigned (expectedCodesignResults);
@ -119,7 +117,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void CodesignAfterModifyingAppExtensionTest ()
{
var csproj = BuildProject ("MyTabbedApplication", Platform, config, clean: true);
var csproj = BuildProject ("MyTabbedApplication", clean: true).ProjectCSProjPath;
var testsDir = Path.GetDirectoryName (Path.GetDirectoryName (csproj));
var appexProjectDir = Path.Combine (testsDir, "MyActionExtension");
var viewController = Path.Combine (appexProjectDir, "ActionViewController.cs");
@ -137,7 +135,7 @@ namespace Xamarin.iOS.Tasks
File.WriteAllText (viewController, text);
try {
BuildProject ("MyTabbedApplication", Platform, config, clean: false);
BuildProject ("MyTabbedApplication", clean: false);
var newTimestamp = File.GetLastWriteTimeUtc (mainExecutable);
// make sure that the main app bundle was codesigned due to the changes in the appex
@ -156,14 +154,14 @@ namespace Xamarin.iOS.Tasks
{
bool expectedCodesignResults = Platform != "iPhoneSimulator";
BuildProject ("MyWatch2Container", Platform, config, clean: true);
BuildProject ("MyWatch2Container");
AssertProperlyCodesigned (expectedCodesignResults);
EnsureFilestampChange ();
// Rebuild w/ no changes
BuildProject ("MyWatch2Container", Platform, config, clean: false);
BuildProject ("MyWatch2Container", clean: false);
// make sure everything is still codesigned properly
AssertProperlyCodesigned (expectedCodesignResults);
@ -172,7 +170,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void CodesignAfterModifyingWatchApp2Test ()
{
var csproj = BuildProject ("MyWatch2Container", Platform, config, clean: true);
var csproj = BuildProject ("MyWatch2Container", clean: true).ProjectCSProjPath;
var testsDir = Path.GetDirectoryName (Path.GetDirectoryName (csproj));
var appexProjectDir = Path.Combine (testsDir, "MyWatchKit2Extension");
var viewController = Path.Combine (appexProjectDir, "InterfaceController.cs");
@ -190,7 +188,7 @@ namespace Xamarin.iOS.Tasks
File.WriteAllText (viewController, text);
try {
BuildProject ("MyWatch2Container", Platform, config, clean: false);
BuildProject ("MyWatch2Container", clean: false);
AssertProperlyCodesigned (expectedCodesignResults);

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

@ -34,14 +34,13 @@ namespace Xamarin.iOS.Tasks
public void LibraryCompilation ()
{
var appName = "MySceneKitLibrary";
var platform = "AnyCPU";
var config = "Debug";
var mtouchPaths = SetupProjectPaths (appName, "../", true, platform, config);
var proj = SetupProject (Engine, mtouchPaths.ProjectCSProjPath);
Platform = "AnyCPU";
Engine.ProjectCollection.SetGlobalProperty ("Platform", platform);
Engine.ProjectCollection.SetGlobalProperty ("Configuration", config);
Engine.ProjectCollection.SetGlobalProperty ("Platform", Platform);
Engine.ProjectCollection.SetGlobalProperty ("Configuration", Config);
RunTarget (proj, "Build", 0);
}

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

@ -43,14 +43,14 @@ namespace Xamarin.iOS.Tasks
[Test]
public void RebuildTest ()
{
BuildProject ("MyCoreMLApp", Platform, "Debug", clean: true);
BuildProject ("MyCoreMLApp");
AssertCompiledModelExists ("SqueezeNet");
EnsureFilestampChange ();
// Rebuild w/ no changes
BuildProject ("MyCoreMLApp", Platform, "Debug", clean: false);
BuildProject ("MyCoreMLApp", clean: false);
AssertCompiledModelExists ("SqueezeNet");
}

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

@ -12,7 +12,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
BuildExtension ("MyTabbedApplication", "MyActionExtension", Platform, "Debug");
BuildExtension ("MyTabbedApplication", "MyActionExtension");
}
}
}

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

@ -19,7 +19,7 @@ namespace Xamarin.iOS.Tasks {
{
if (Platform == "iPhoneSimulator" && Environment.OSVersion.Version.Major < 19) // Environment.OSVersion = 19.* in macOS Catalina.
Assert.Ignore ("Metal support is not available in the simulator until macOS 10.15.");
this.BuildExtension ("MyMetalGame", "MyKeyboardExtension", Platform, "Debug");
this.BuildExtension ("MyMetalGame", "MyKeyboardExtension");
this.TestStoryboardC (AppBundlePath);
}

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

@ -13,7 +13,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
this.BuildExtension ("MyWebViewApp", "MyDocumentPickerExtension", Platform, "Debug");
this.BuildExtension ("MyWebViewApp", "MyDocumentPickerExtension");
this.TestStoryboardC (AppBundlePath);
}
}

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

@ -8,13 +8,11 @@ using Microsoft.Build.Evaluation;
namespace Xamarin.iOS.Tasks
{
public class ExtensionTestBase : TestBase {
public string Platform;
public ExtensionTestBase () { }
public ExtensionTestBase (string platform)
: base (platform)
{
Platform = platform;
}
public Project BuildExtension (string hostAppName, string extensionName, string platform, string config, int expectedErrorCount = 0, System.Action<ProjectPaths> additionalAsserts = null)
@ -53,15 +51,15 @@ namespace Xamarin.iOS.Tasks
var basedirs = new List<string> ();
if (IsWatchOS) {
basedirs.Add (extensionPath);
coreFiles = GetCoreAppFiles (platform, config, extensionName + ".dll", Path.GetFileNameWithoutExtension (extensionPath));
coreFiles = GetCoreAppFiles (extensionName + ".dll", Path.GetFileNameWithoutExtension (extensionPath));
} else {
basedirs.Add (AppBundlePath);
if (platform == "iPhone") {
if (Platform == "iPhone") {
basedirs.Add (Path.Combine (AppBundlePath, ".monotouch-32"));
basedirs.Add (Path.Combine (AppBundlePath, "Frameworks", "Xamarin.Sdk.framework", "MonoBundle"));
basedirs.Add (Path.Combine (AppBundlePath, "Frameworks", "Xamarin.Sdk.framework", "MonoBundle", ".monotouch-32"));
}
coreFiles = GetCoreAppFiles (platform, config, hostAppName + ".exe", hostAppName);
coreFiles = GetCoreAppFiles (hostAppName + ".exe", hostAppName);
}
TestFilesExists (basedirs.ToArray (), coreFiles);

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

@ -12,7 +12,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
this.BuildExtension ("MySpriteKitGame", "MyPhotoEditingExtension", Platform, "Debug");
this.BuildExtension ("MySpriteKitGame", "MyPhotoEditingExtension");
}
}
}

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

@ -12,7 +12,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
this.BuildExtension ("MyMasterDetailApp", "MyShareExtension", Platform, "Debug");
this.BuildExtension ("MyMasterDetailApp", "MyShareExtension");
}
}
}

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

@ -12,7 +12,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
this.BuildExtension ("MyOpenGLApp", "MyTodayExtension", Platform, "Debug");
this.BuildExtension ("MyOpenGLApp", "MyTodayExtension");
}
}
}

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

@ -12,7 +12,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
BuildExtension ("MyWatchApp", "MyWatchKitExtension", Platform, "Debug", expectedErrorCount: 1);
BuildExtension ("MyWatchApp", "MyWatchKitExtension", expectedErrorCount: 1);
Assert.AreEqual ("Xamarin.iOS 14+ does not support watchOS 1 apps. Please migrate your project to watchOS 2+.", Engine.Logger.ErrorEvents[0].Message, "WK 1 error message");
}
}

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

@ -18,7 +18,7 @@ namespace Xamarin.iOS.Tasks {
if (!Xamarin.Tests.Configuration.include_watchos)
Assert.Ignore ("WatchOS is not enabled");
BuildExtension ("MyWatchApp2", "MyWatchKit2Extension", Platform, "Debug");
BuildExtension ("MyWatchApp2", "MyWatchKit2Extension");
if (Platform == "iPhone") {
// make sure the dSYMs exist

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

@ -13,7 +13,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void BuildTest ()
{
BuildProject ("MyIBToolLinkTest", Platform, "Debug");
BuildProject ("MyIBToolLinkTest");
}
}
}

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

@ -17,7 +17,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void BuildTest ()
{
BuildProject ("MyLinkedAssets", Platform, "Debug");
BuildProject ("MyLinkedAssets");
foreach (var name in IconNames) {
var path = Path.Combine (AppBundlePath, name);

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

@ -8,17 +8,16 @@ namespace Xamarin.iOS.Tasks
{
public class ProjectTest : TestBase {
public string BundlePath;
public string Platform;
public ProjectTest (string platform)
: base (platform)
{
Platform = platform;
}
public ProjectTest (string bundlePath, string platform)
: base (platform)
{
BundlePath = bundlePath;
Platform = platform;
}
@ -52,8 +51,8 @@ namespace Xamarin.iOS.Tasks
Assert.IsFalse (Directory.Exists (AppBundlePath + ".mSYM"), "App bundle .mSYM exists after cleanup: {0} ", AppBundlePath + ".mSYM");
var baseDir = Path.GetDirectoryName (csproj);
var objDir = Path.Combine (baseDir, "obj", platform, config);
var binDir = Path.Combine (baseDir, "bin", platform, config);
var objDir = Path.Combine (baseDir, "obj", Platform, Config);
var binDir = Path.Combine (baseDir, "bin", Platform, Config);
if (Directory.Exists (objDir)) {
var paths = Directory.EnumerateFiles (objDir, "*.*", SearchOption.AllDirectories)
@ -82,7 +81,7 @@ namespace Xamarin.iOS.Tasks
TestFilesDoNotExist (AppBundlePath, UnexpectedAppFiles);
if (executionMode != ExecutionMode.DotNet) {
var coreFiles = GetCoreAppFiles (platform, config, appName.Replace (" ", "") + ".exe", appName.Replace (" ", ""));
var coreFiles = GetCoreAppFiles (appName.Replace (" ", "") + ".exe", appName.Replace (" ", ""));
var baseDirs = new string [] {
Path.Combine (AppBundlePath, ".monotouch-32"),
Path.Combine (AppBundlePath, ".monotouch-64"),
@ -94,7 +93,7 @@ namespace Xamarin.iOS.Tasks
TestFilesExists (baseDirs, coreFiles);
}
if (platform == "iPhone") {
if (Platform == "iPhone") {
var dSYMInfoPlist = Path.Combine (AppBundlePath + ".dSYM", "Contents", "Info.plist");
var nativeExecutable = Path.Combine (AppBundlePath, appName);

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

@ -13,7 +13,7 @@ namespace Xamarin.iOS.Tasks {
[Test]
public void BasicTest ()
{
this.BuildExtension ("MyMasterDetailApp", "MyShareExtension", Platform, "Debug");
this.BuildExtension ("MyMasterDetailApp", "MyShareExtension");
// Verify that Mono.frameworks is in the app
Assert.That (Directory.Exists (Path.Combine (AppBundlePath, "Frameworks")), "Frameworks exists");

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

@ -15,7 +15,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void BasicTest ()
{
this.BuildProject ("My Spaced App", Platform, "Debug", clean: false);
this.BuildProject ("My Spaced App", clean: false);
// Message of the form:
// Property reassignment: $(AssemblySearchPaths)="..." (previous value: "...") at Xamarin.iOS.Common.props (106,3)

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

@ -11,14 +11,15 @@ namespace Xamarin.iOS.Tasks
[TestFixture ("iPhone")]
public class ReleaseBuild : ProjectTest
{
public ReleaseBuild (string platform) : base (platform)
public ReleaseBuild (string platform)
: base (platform, "Release")
{
}
[Test]
public void BuildTest ()
{
BuildProject ("MyReleaseBuild", Platform, "Release");
BuildProject ("MyReleaseBuild");
var args = new List<string> { "-r", "UIWebView", AppBundlePath };
ExecutionHelper.Execute ("grep", args, out var output);
@ -29,7 +30,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void RebuildTest ()
{
var csproj = BuildProject ("MyReleaseBuild", Platform, "Release", clean: true);
var csproj = BuildProject ("MyReleaseBuild").ProjectCSProjPath;
var bak = Path.Combine (Path.GetDirectoryName (csproj), "MyReleaseBuild.csproj.bak");
var llvm = Path.Combine (Path.GetDirectoryName (csproj), "MyReleaseBuildLlvm.csproj");
@ -41,7 +42,7 @@ namespace Xamarin.iOS.Tasks
EnsureFilestampChange ();
// Rebuild w/ no changes
BuildProject ("MyReleaseBuild", Platform, "Release", clean: false);
BuildProject ("MyReleaseBuild", clean: false);
var newTimestamps = Directory.EnumerateFiles (AppBundlePath, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
var newDSymTimestamps = Directory.EnumerateFiles (dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
@ -60,7 +61,7 @@ namespace Xamarin.iOS.Tasks
File.Copy (llvm, csproj, true);
File.SetLastWriteTimeUtc (csproj, DateTime.UtcNow);
BuildProject ("MyReleaseBuild", Platform, "Release", clean: false);
BuildProject ("MyReleaseBuild", clean: false);
} finally {
File.Copy (bak, csproj, true);
File.Delete (bak);

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

@ -14,7 +14,7 @@ namespace Xamarin.iOS.Tasks
[Test]
public void ProjectWithExtraArgment_CorrectlyOverridesLinkingParam ()
{
BuildProject ("AppWithExtraArgumentThatOverrides", Platform, "Debug", clean: true);
BuildProject ("AppWithExtraArgumentThatOverrides");
Assert.True (Engine.Logger.MessageEvents.Any (x => x.Message.Contains ("using mode 'SDKOnly'")));
}
}

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

@ -17,7 +17,7 @@ namespace Xamarin.iOS.Tasks
{
if (Platform == "iPhoneSimulator" && Environment.OSVersion.Version.Major < 19) // Environment.OSVersion = 19.* in macOS Catalina.
Assert.Ignore ("Metal support is not available in the simulator until macOS 10.15.");
BuildExtension ("MyTVApp", "MyTVServicesExtension", Platform, "Debug");
BuildExtension ("MyTVApp", "MyTVServicesExtension");
}
public override string TargetFrameworkIdentifier {

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

@ -15,7 +15,7 @@ namespace Xamarin.iOS.Tasks {
{
if (Platform == "iPhoneSimulator" && Environment.OSVersion.Version.Major < 19) // Environment.OSVersion = 19.* in macOS Catalina.
Assert.Ignore ("Metal support is not available in the simulator until macOS 10.15.");
BuildProject ("MyTVMetalGame", Platform, "Debug");
BuildProject ("MyTVMetalGame");
}
public override string TargetFrameworkIdentifier {

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

@ -19,18 +19,16 @@ namespace Xamarin.iOS.Tasks
NugetRestore (Path.Combine (testdir, "MyXamarinFormsApp", "MyXamarinFormsAppNS", "MyXamarinFormsAppNS.csproj"));
// First build
BuildProject ("MyXamarinFormsApp", Platform, "Debug");
BuildProject ("MyXamarinFormsApp");
Assert.IsFalse (IsTargetSkipped ("_CompileToNative"), "_CompileToNative should *not* be skipped on first build.");
// Build with no changes
Engine.Logger.Clear ();
BuildProject ("MyXamarinFormsApp", Platform, "Debug", clean: false);
BuildProject ("MyXamarinFormsApp", clean: false);
Assert.IsTrue (IsTargetSkipped ("_CompileToNative"), "_CompileToNative should be skipped on a build with no changes.");
// Build with XAML change
Touch (Path.Combine (testdir, "MyXamarinFormsApp", "MyXamarinFormsAppNS", "App.xaml"));
Engine.Logger.Clear ();
BuildProject ("MyXamarinFormsApp", Platform, "Debug", clean: false);
BuildProject ("MyXamarinFormsApp", clean: false);
Assert.IsFalse (IsTargetSkipped ("_CompileToNative"), "_CompileToNative should *not* be skipped on a build with a XAML change.");
}

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

@ -13,6 +13,11 @@ namespace Xamarin.iOS.Tasks
[TestFixture]
public class TargetTests : TestBase
{
public TargetTests ()
: base ("iPhoneSimulator")
{
}
string[] ExpectedExecutableBundleResources {
get {
var files = new [] {

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

@ -25,6 +25,24 @@ namespace Xamarin.iOS.Tasks
public abstract class TestBase
{
public string Platform;
public string Config = "Debug";
public TestBase ()
{
}
public TestBase (string platform)
{
Platform = platform;
}
public TestBase (string platform, string config)
{
Platform = platform;
Config = config;
}
protected static class TargetName
{
public static string Build = "Build";
@ -62,30 +80,30 @@ namespace Xamarin.iOS.Tasks
public string [] ExpectedAppFiles = { };
public string [] UnexpectedAppFiles = { "monotouch.dll" };
public string[] GetCoreAppFiles (string platform, string config, string managedExe, string nativeExe)
public string[] GetCoreAppFiles (string managedExe, string nativeExe)
{
var coreFiles = new List<string> ();
if (TargetFrameworkIdentifier == "Xamarin.WatchOS") {
coreFiles.Add ("Xamarin.WatchOS.dll");
if (config == "Debug")
if (Config == "Debug")
coreFiles.Add ("Xamarin.WatchOS.pdb");
} else if (TargetFrameworkIdentifier == "Xamarin.TVOS") {
coreFiles.Add ("Xamarin.TVOS.dll");
if (config == "Debug")
if (Config == "Debug")
coreFiles.Add ("Xamarin.TVOS.pdb");
} else {
coreFiles.Add ("Xamarin.iOS.dll");
if (config == "Debug")
if (Config == "Debug")
coreFiles.Add ("Xamarin.iOS.pdb");
}
coreFiles.Add ("mscorlib.dll");
if (config == "Debug")
if (Config == "Debug")
coreFiles.Add ("mscorlib.pdb");
coreFiles.Add (managedExe);
if (config == "Debug")
if (Config == "Debug")
coreFiles.Add (Path.ChangeExtension (managedExe, ".pdb"));
coreFiles.Add (nativeExe);