[dotnet] Improve tests to verify that the linker has (or hasn't) run.
This commit is contained in:
Родитель
80d4100627
Коммит
3589a3b99d
|
@ -24,12 +24,19 @@ namespace Xamarin.Tests {
|
|||
}
|
||||
}
|
||||
|
||||
public static void AssertBuild (string project, Dictionary<string, string> properties = null, string verbosity = "diagnostic")
|
||||
public static ExecutionResult AssertBuild (string project, Dictionary<string, string> properties = null, string verbosity = "diagnostic")
|
||||
{
|
||||
Execute ("build", project, properties, out var _, verbosity, true);
|
||||
return Execute ("build", project, properties, verbosity, true);
|
||||
}
|
||||
|
||||
public static int Execute (string verb, string project, Dictionary<string, string> properties, out StringBuilder output, string verbosity = "diagnostic", bool assert_success = true)
|
||||
public static ExecutionResult AssertBuildFailure (string project, Dictionary<string, string> properties = null, string verbosity = "diagnostic")
|
||||
{
|
||||
var rv = Execute ("build", project, properties, verbosity, false);
|
||||
Assert.AreNotEqual (0, rv.ExitCode, "Unexpected success");
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static ExecutionResult Execute (string verb, string project, Dictionary<string, string> properties, string verbosity = "diagnostic", bool assert_success = true)
|
||||
{
|
||||
if (!File.Exists (project))
|
||||
throw new FileNotFoundException ($"The project file '{project}' does not exist.");
|
||||
|
@ -51,7 +58,7 @@ namespace Xamarin.Tests {
|
|||
var env = new Dictionary<string, string> ();
|
||||
env ["MSBuildSDKsPath"] = null;
|
||||
env ["MSBUILD_EXE_PATH"] = null;
|
||||
output = new StringBuilder ();
|
||||
var output = new StringBuilder ();
|
||||
var rv = ExecutionHelper.Execute (Executable, args, env, output, output, workingDirectory: Path.GetDirectoryName (project), timeout: TimeSpan.FromMinutes (10));
|
||||
if (rv != 0) {
|
||||
Console.WriteLine ($"'{Executable} {StringUtils.FormatArguments (args)}' failed with exit code {rv}.");
|
||||
|
@ -65,10 +72,21 @@ namespace Xamarin.Tests {
|
|||
msg = "\n\t" + string.Join ("\n\t", errors);
|
||||
Assert.AreEqual (0, rv, $"Exit code: {Executable} {StringUtils.FormatArguments (args)}{msg}");
|
||||
}
|
||||
return rv;
|
||||
return new ExecutionResult {
|
||||
StandardOutput = output,
|
||||
StandardError = output,
|
||||
ExitCode = rv,
|
||||
};
|
||||
default:
|
||||
throw new NotImplementedException ($"Unknown dotnet action: '{verb}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ExecutionResult {
|
||||
public StringBuilder StandardOutput;
|
||||
public StringBuilder StandardError;
|
||||
public int ExitCode;
|
||||
public bool TimedOut;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ using NUnit.Framework;
|
|||
namespace Xamarin.Tests {
|
||||
[TestFixture]
|
||||
public class DotNetProjectTest {
|
||||
void Build (string project, string subdir = null)
|
||||
string GetProjectPath (string project, string subdir = null)
|
||||
{
|
||||
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
|
||||
if (!string.IsNullOrEmpty (subdir))
|
||||
|
@ -15,31 +15,57 @@ namespace Xamarin.Tests {
|
|||
if (!File.Exists (project_path))
|
||||
project_path = Path.ChangeExtension (project_path, "sln");
|
||||
|
||||
DotNet.AssertBuild (project_path);
|
||||
if (!File.Exists (project_path))
|
||||
throw new FileNotFoundException ($"Could not find the project or solution {project}");
|
||||
|
||||
return project_path;
|
||||
}
|
||||
|
||||
void Clean (string project_path)
|
||||
{
|
||||
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path), "*", SearchOption.AllDirectories);
|
||||
foreach (var dir in dirs) {
|
||||
var name = Path.GetFileName (dir);
|
||||
if (name != "bin" && name != "obj")
|
||||
continue;
|
||||
Directory.Delete (dir, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMySingleView ()
|
||||
{
|
||||
Build ("MySingleView");
|
||||
var project_path = GetProjectPath ("MySingleView");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMyCocoaApp ()
|
||||
{
|
||||
Build ("MyCocoaApp");
|
||||
var project_path = GetProjectPath ("MyCocoaApp");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMyTVApp ()
|
||||
{
|
||||
Build ("MyTVApp");
|
||||
var project_path = GetProjectPath ("MyTVApp");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMyWatchApp ()
|
||||
{
|
||||
Build ("MyWatchApp");
|
||||
var project_path = GetProjectPath ("MyWatchApp");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuildFailure (project_path);
|
||||
Assert.That (result.StandardOutput.ToString (), Does.Contain ("The specified RuntimeIdentifier 'watchos-x86' is not recognized."), "Missing runtime pack for watchOS");
|
||||
}
|
||||
|
||||
[TestCase ("iOS")]
|
||||
|
@ -48,7 +74,17 @@ namespace Xamarin.Tests {
|
|||
[TestCase ("macOS")]
|
||||
public void BuildMyClassLibrary (string platform)
|
||||
{
|
||||
Build ("MyClassLibrary", platform);
|
||||
var project_path = GetProjectPath ("MyClassLibrary", platform);
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
Assert.That (result.StandardOutput.ToString (), Does.Not.Contain ("Task \"ILLink\""), "Linker executed unexpectedly.");
|
||||
}
|
||||
|
||||
void AssertThatLinkerExecuted (ExecutionResult result)
|
||||
{
|
||||
var output = result.StandardOutput.ToString ();
|
||||
Assert.That (output, Does.Contain ("Building target \"_RunILLink\" completely."), "Linker did not executed as expected.");
|
||||
Assert.That (output, Does.Contain ("Hello SetupStep"), "Custom steps did not run as expected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче