[tests] Rewrite ValidateAppBundleTaskTests to not create a task in-process. (#9983)
This is a step towards making Xamarin.MacDev.Tests run tests out-of-process. It requires adding '_GenerateBundleName' as a dependency for the '_ValidateAppBundle' target, because we're invoking the '_ValidateAppBundle' directly, and we can't depend on any other targets executing '_GenerateBundleName', because there are no other executed targets.
This commit is contained in:
Родитель
26e720943f
Коммит
1197c67ebe
|
@ -1062,7 +1062,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
|
||||||
$(_AppBundlePath)..\%(_ResolvedAppExtensionReferences.FileName)%(_ResolvedAppExtensionReferences.Extension).dSYM" />
|
$(_AppBundlePath)..\%(_ResolvedAppExtensionReferences.FileName)%(_ResolvedAppExtensionReferences.Extension).dSYM" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="_ValidateAppBundle" Condition="'$(IsAppExtension)' == 'false' And '$(IsWatchApp)' == 'false'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetFrameworkMoniker">
|
<Target Name="_ValidateAppBundle" Condition="'$(IsAppExtension)' == 'false' And '$(IsWatchApp)' == 'false'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetFrameworkMoniker;_GenerateBundleName">
|
||||||
<ValidateAppBundleTask
|
<ValidateAppBundleTask
|
||||||
Condition="'$(IsMacEnabled)' == 'true'"
|
Condition="'$(IsMacEnabled)' == 'true'"
|
||||||
SessionId="$(BuildSessionId)"
|
SessionId="$(BuildSessionId)"
|
||||||
|
|
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
using Microsoft.Build.Evaluation;
|
||||||
|
|
||||||
namespace Xamarin.iOS.Tasks
|
namespace Xamarin.iOS.Tasks
|
||||||
{
|
{
|
||||||
public class ExtensionTestBase : TestBase {
|
public class ExtensionTestBase : TestBase {
|
||||||
|
@ -15,7 +17,7 @@ namespace Xamarin.iOS.Tasks
|
||||||
Platform = platform;
|
Platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuildExtension (string hostAppName, string extensionName, string platform, string config, int expectedErrorCount = 0, System.Action<ProjectPaths> additionalAsserts = null)
|
public Project BuildExtension (string hostAppName, string extensionName, string platform, string config, int expectedErrorCount = 0, System.Action<ProjectPaths> additionalAsserts = null)
|
||||||
{
|
{
|
||||||
var bundlePath = platform;
|
var bundlePath = platform;
|
||||||
var mtouchPaths = SetupProjectPaths (hostAppName, "../", true, bundlePath, config);
|
var mtouchPaths = SetupProjectPaths (hostAppName, "../", true, bundlePath, config);
|
||||||
|
@ -34,7 +36,7 @@ namespace Xamarin.iOS.Tasks
|
||||||
RunTarget (proj, "Build", expectedErrorCount);
|
RunTarget (proj, "Build", expectedErrorCount);
|
||||||
|
|
||||||
if (expectedErrorCount > 0)
|
if (expectedErrorCount > 0)
|
||||||
return;
|
return proj;
|
||||||
|
|
||||||
Assert.IsTrue (Directory.Exists (AppBundlePath), "{1} App Bundle does not exist: {0} ", AppBundlePath, bundlePath);
|
Assert.IsTrue (Directory.Exists (AppBundlePath), "{1} App Bundle does not exist: {0} ", AppBundlePath, bundlePath);
|
||||||
|
|
||||||
|
@ -65,6 +67,8 @@ namespace Xamarin.iOS.Tasks
|
||||||
|
|
||||||
if (additionalAsserts != null)
|
if (additionalAsserts != null)
|
||||||
additionalAsserts (mtouchPaths);
|
additionalAsserts (mtouchPaths);
|
||||||
|
|
||||||
|
return proj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetupPaths (string appName, string platform)
|
public void SetupPaths (string appName, string platform)
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
using Microsoft.Build.Evaluation;
|
||||||
|
|
||||||
using Xamarin.MacDev;
|
using Xamarin.MacDev;
|
||||||
|
|
||||||
namespace Xamarin.iOS.Tasks
|
namespace Xamarin.iOS.Tasks
|
||||||
|
@ -7,70 +11,80 @@ namespace Xamarin.iOS.Tasks
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ValidateAppBundleTaskTests : ExtensionTestBase
|
public class ValidateAppBundleTaskTests : ExtensionTestBase
|
||||||
{
|
{
|
||||||
ValidateAppBundleTask task;
|
|
||||||
|
|
||||||
string extensionBundlePath;
|
string extensionBundlePath;
|
||||||
|
|
||||||
string mainAppPlistPath;
|
string mainAppPlistPath;
|
||||||
string extensionPlistPath;
|
string extensionPlistPath;
|
||||||
|
|
||||||
PDictionary sourcePlist;
|
Project project;
|
||||||
|
|
||||||
public override void Setup ()
|
public ValidateAppBundleTaskTests ()
|
||||||
|
: base ("iPhoneSimulator")
|
||||||
{
|
{
|
||||||
base.Setup ();
|
}
|
||||||
|
|
||||||
var extensionName = "MyActionExtension";
|
|
||||||
BuildExtension ("MyTabbedApplication", extensionName, "iPhoneSimulator", "Debug");
|
|
||||||
|
|
||||||
task = CreateTask<ValidateAppBundleTask> ();
|
|
||||||
task.AppBundlePath = AppBundlePath;
|
|
||||||
task.SdkIsSimulator = true;
|
|
||||||
task.TargetFrameworkMoniker = "Xamarin.iOS,v1.0";
|
|
||||||
|
|
||||||
extensionBundlePath = Path.Combine (AppBundlePath, "PlugIns", extensionName + ".appex");
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MissingFiles ()
|
||||||
|
{
|
||||||
|
project = BuildExtension ("MyTabbedApplication", "MyActionExtension", Platform, "Debug");
|
||||||
|
extensionBundlePath = AppBundlePath;
|
||||||
mainAppPlistPath = Path.Combine (AppBundlePath, "Info.plist");
|
mainAppPlistPath = Path.Combine (AppBundlePath, "Info.plist");
|
||||||
extensionPlistPath = Path.Combine (extensionBundlePath, "Info.plist");
|
extensionPlistPath = Path.Combine (extensionBundlePath, "Info.plist");
|
||||||
|
|
||||||
sourcePlist = PDictionary.FromFile (mainAppPlistPath);
|
MissingPlist_Extension ();
|
||||||
|
MissingPlist_MainApp ();
|
||||||
|
NotMatching_VersionBuildNumbers ();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
void MissingPlist_MainApp ()
|
||||||
public void MissingPlist_MainApp ()
|
|
||||||
{
|
{
|
||||||
File.Delete (mainAppPlistPath);
|
var contents = File.ReadAllBytes (mainAppPlistPath);
|
||||||
Assert.IsFalse (task.Execute (), "#1");
|
try {
|
||||||
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
|
File.Delete (mainAppPlistPath);
|
||||||
|
Engine.Logger.Clear ();
|
||||||
|
RunTarget (project, "_ValidateAppBundle", 1);
|
||||||
|
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
|
||||||
|
} finally {
|
||||||
|
// Restore the contents
|
||||||
|
File.WriteAllBytes (mainAppPlistPath, contents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
void MissingPlist_Extension ()
|
||||||
public void MissingPlist_Extension ()
|
|
||||||
{
|
{
|
||||||
File.Delete (extensionPlistPath);
|
var contents = File.ReadAllBytes (extensionPlistPath);
|
||||||
Assert.IsFalse (task.Execute (), "#1");
|
try {
|
||||||
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
|
File.Delete (extensionPlistPath);
|
||||||
|
Engine.Logger.Clear ();
|
||||||
|
RunTarget (project, "_ValidateAppBundle", 1);
|
||||||
|
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
|
||||||
|
} finally {
|
||||||
|
// Restore the contents
|
||||||
|
File.WriteAllBytes (extensionPlistPath, contents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test (Description = "Xambug #38673")]
|
// Xambug #38673
|
||||||
public void NotMatching_VersionBuildNumbers ()
|
void NotMatching_VersionBuildNumbers ()
|
||||||
{
|
{
|
||||||
var warningCount = Engine.Logger.WarningsEvents.Count;
|
var contents = File.ReadAllBytes (mainAppPlistPath);
|
||||||
|
var sourcePlist = PDictionary.FromFile (mainAppPlistPath);
|
||||||
|
try {
|
||||||
|
// Warning: The App Extension has a CFBundleShortVersionString
|
||||||
|
// that does not match the main app bundle's CFBundleShortVersionString.
|
||||||
|
sourcePlist.SetCFBundleShortVersionString ("1");
|
||||||
|
|
||||||
// Warning: The App Extension has a CFBundleShortVersionString
|
// Warning: The App Extension has a CFBundleVersion
|
||||||
// that does not match the main app bundle's CFBundleShortVersionString.
|
// that does not match the main app bundle's CFBundleVersion.
|
||||||
sourcePlist.SetCFBundleShortVersionString ("1");
|
sourcePlist.SetCFBundleVersion ("1");
|
||||||
warningCount++;
|
|
||||||
|
|
||||||
// Warning: The App Extension has a CFBundleVersion
|
sourcePlist.Save (mainAppPlistPath);
|
||||||
// that does not match the main app bundle's CFBundleVersion.
|
Engine.Logger.Clear ();
|
||||||
sourcePlist.SetCFBundleVersion ("1");
|
RunTarget (project, "_ValidateAppBundle", 0);
|
||||||
warningCount++;
|
Assert.AreEqual (2, Engine.Logger.WarningsEvents.Count, "#2");
|
||||||
|
} finally {
|
||||||
sourcePlist.Save (mainAppPlistPath);
|
// Restore the contents
|
||||||
Assert.True (task.Execute (), "#1"); // No build error.
|
File.WriteAllBytes (mainAppPlistPath, contents);
|
||||||
Assert.AreEqual (warningCount, Engine.Logger.WarningsEvents.Count, "#2");
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -317,13 +317,6 @@ namespace Xamarin.iOS.Tasks
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public T CreateTask<T> () where T : Task, new()
|
|
||||||
{
|
|
||||||
var t = new T ();
|
|
||||||
t.BuildEngine = Engine;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the task and log its error messages.</summary>
|
/// Executes the task and log its error messages.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче