[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:
Rolf Bjarne Kvinge 2020-10-29 08:59:11 +01:00 коммит произвёл GitHub
Родитель 26e720943f
Коммит 1197c67ebe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 64 добавлений и 53 удалений

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

@ -1062,7 +1062,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
$(_AppBundlePath)..\%(_ResolvedAppExtensionReferences.FileName)%(_ResolvedAppExtensionReferences.Extension).dSYM" />
</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
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"

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

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Microsoft.Build.Evaluation;
namespace Xamarin.iOS.Tasks
{
public class ExtensionTestBase : TestBase {
@ -15,7 +17,7 @@ namespace Xamarin.iOS.Tasks
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 mtouchPaths = SetupProjectPaths (hostAppName, "../", true, bundlePath, config);
@ -34,7 +36,7 @@ namespace Xamarin.iOS.Tasks
RunTarget (proj, "Build", expectedErrorCount);
if (expectedErrorCount > 0)
return;
return proj;
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)
additionalAsserts (mtouchPaths);
return proj;
}
public void SetupPaths (string appName, string platform)

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

@ -1,5 +1,9 @@
using System;
using System.IO;
using NUnit.Framework;
using Microsoft.Build.Evaluation;
using Xamarin.MacDev;
namespace Xamarin.iOS.Tasks
@ -7,70 +11,80 @@ namespace Xamarin.iOS.Tasks
[TestFixture]
public class ValidateAppBundleTaskTests : ExtensionTestBase
{
ValidateAppBundleTask task;
string extensionBundlePath;
string mainAppPlistPath;
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");
extensionPlistPath = Path.Combine (extensionBundlePath, "Info.plist");
sourcePlist = PDictionary.FromFile (mainAppPlistPath);
MissingPlist_Extension ();
MissingPlist_MainApp ();
NotMatching_VersionBuildNumbers ();
}
[Test]
public void MissingPlist_MainApp ()
void MissingPlist_MainApp ()
{
File.Delete (mainAppPlistPath);
Assert.IsFalse (task.Execute (), "#1");
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
var contents = File.ReadAllBytes (mainAppPlistPath);
try {
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]
public void MissingPlist_Extension ()
void MissingPlist_Extension ()
{
File.Delete (extensionPlistPath);
Assert.IsFalse (task.Execute (), "#1");
Assert.IsTrue (Engine.Logger.ErrorEvents.Count > 0, "#2");
var contents = File.ReadAllBytes (extensionPlistPath);
try {
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")]
public void NotMatching_VersionBuildNumbers ()
// Xambug #38673
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
// that does not match the main app bundle's CFBundleShortVersionString.
sourcePlist.SetCFBundleShortVersionString ("1");
warningCount++;
// Warning: The App Extension has a CFBundleVersion
// that does not match the main app bundle's CFBundleVersion.
sourcePlist.SetCFBundleVersion ("1");
// Warning: The App Extension has a CFBundleVersion
// that does not match the main app bundle's CFBundleVersion.
sourcePlist.SetCFBundleVersion ("1");
warningCount++;
sourcePlist.Save (mainAppPlistPath);
Assert.True (task.Execute (), "#1"); // No build error.
Assert.AreEqual (warningCount, Engine.Logger.WarningsEvents.Count, "#2");
sourcePlist.Save (mainAppPlistPath);
Engine.Logger.Clear ();
RunTarget (project, "_ValidateAppBundle", 0);
Assert.AreEqual (2, Engine.Logger.WarningsEvents.Count, "#2");
} finally {
// Restore the contents
File.WriteAllBytes (mainAppPlistPath, contents);
}
}
}
}

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

@ -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>
/// Executes the task and log its error messages.</summary>
/// <remarks>