Skip to content

Commit

Permalink
[msbuild] Update tests to NUnit 3.12. (dotnet#7597)
Browse files Browse the repository at this point in the history
Updating the msbuild tasks to use netstandard2.0 requires us to bump NUnit to 3+.

This requires:

* A few code changes due to breaking API changes in NUnit.
* Changes in xharness and a makefile to cope with the new location for the
  NUnit console runner (I added a helper script to make things slightly
  easier).
  • Loading branch information
rolfbjarne authored Dec 16, 2019
1 parent d5135cc commit c422869
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Compilation ()
var scenePath = Path.GetFullPath (Path.Combine (appPath, "art.scnassets", "scene.scn"));

var xml = Configuration.ReadPListAsXml (scenePath);
Assert.That (xml, Is.StringContaining ("<string>art.scnassets/texture.png</string>"), "asset with path");
Assert.That (xml, Does.Contain ("<string>art.scnassets/texture.png</string>"), "asset with path");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void BuildTest ()
BuildProject ("MyReleaseBuild", Platform, "Release");
}

[Ignore] // requires msbuild instead of xbuild
[Ignore ("requires msbuild instead of xbuild")]
[Test]
public void RebuildTest ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public void DetectAppManifest_ExecutableProject_NoPList ()
MonoTouchProjectInstance = MonoTouchProject.CreateProjectInstance ();

RunTarget_WithErrors (MonoTouchProjectInstance, TargetName.DetectAppManifest);
Assert.IsNullOrEmpty (MonoTouchProjectInstance.GetPropertyValue ("_AppManifest"), "#1");
Assert.That (MonoTouchProjectInstance.GetPropertyValue ("_AppManifest"), Is.Null.Or.Empty, "#1");
}

[Test]
Expand Down Expand Up @@ -625,7 +625,7 @@ public void DetectAppManifest_ExecutableProject_LogicalNamePList ()
public void DetectAppManifest_LibraryProject ()
{
RunTargetOnInstance (LibraryProjectInstance, TargetName.DetectAppManifest);
Assert.IsNullOrEmpty (LibraryProjectInstance.GetPropertyValue ("_AppManifest"), "#1");
Assert.That (LibraryProjectInstance.GetPropertyValue ("_AppManifest"), Is.Not.Null.Or.Empty, "#1");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void MissingDisplayName ()
public virtual void XamarinVersion ()
{
Assert.That (CompiledPlist.ContainsKey ("com.xamarin.ios"), "#1");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PDictionary> ("com.xamarin.ios").GetString ("Version").Value, "#2");
Assert.That (CompiledPlist.Get<PDictionary> ("com.xamarin.ios").GetString ("Version").Value, Is.Not.Null.Or.Empty, "#2");
}
#endregion

Expand All @@ -100,7 +100,7 @@ public virtual void XamarinVersion ()
public void BuildMachineOSBuild ()
{
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.BuildMachineOSBuild), "#1");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (ManifestKeys.BuildMachineOSBuild).Value, "#2");
Assert.That (CompiledPlist.Get<PString> (ManifestKeys.BuildMachineOSBuild).Value, Is.Not.Null.Or.Empty, "#2");
}

[Test]
Expand Down Expand Up @@ -134,7 +134,7 @@ public virtual void BundleIdentifier ()
public virtual void BundleInfoDictionaryVersion ()
{
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleInfoDictionaryVersion), "#1");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (ManifestKeys.CFBundleInfoDictionaryVersion).Value, "#2");
Assert.That (CompiledPlist.Get<PString> (ManifestKeys.CFBundleInfoDictionaryVersion).Value, Is.Not.Null.Or.Empty, "#2");
}

[Test]
Expand Down Expand Up @@ -162,7 +162,7 @@ public virtual void BundleSupportedPlatforms ()
public virtual void BundleVersion ()
{
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.CFBundleVersion), "#1");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (ManifestKeys.CFBundleVersion).Value, "#2");
Assert.That (CompiledPlist.Get<PString> (ManifestKeys.CFBundleVersion).Value, Is.Not.Null.Or.Empty, "#2");
}

[Test]
Expand All @@ -184,14 +184,14 @@ public virtual void VerifyAllDT ()
Assert.That (CompiledPlist.ContainsKey (dtSDKName), "#5");
Assert.That (CompiledPlist.ContainsKey (dtXcode), "#6");
Assert.That (CompiledPlist.ContainsKey (dtXcodeBuild), "#7");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtCompiler).Value, "#8");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtPlatformBuild).Value, "#9");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtSDKBuild).Value, "#10");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtPlatformName).Value, "#11");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtPlatformVersion).Value, "#12");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtSDKName).Value, "#13");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtXcode).Value, "#14");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (dtXcodeBuild).Value, "#15");
Assert.That (CompiledPlist.Get<PString> (dtCompiler).Value, Is.Not.Null.Or.Empty, "#8");
Assert.That (CompiledPlist.Get<PString> (dtPlatformBuild).Value, Is.Not.Null.Or.Empty, "#9");
Assert.That (CompiledPlist.Get<PString> (dtSDKBuild).Value, Is.Not.Null.Or.Empty, "#10");
Assert.That (CompiledPlist.Get<PString> (dtPlatformName).Value, Is.Not.Null.Or.Empty, "#11");
Assert.That (CompiledPlist.Get<PString> (dtPlatformVersion).Value, Is.Not.Null.Or.Empty, "#12");
Assert.That (CompiledPlist.Get<PString> (dtSDKName).Value, Is.Not.Null.Or.Empty, "#13");
Assert.That (CompiledPlist.Get<PString> (dtXcode).Value, Is.Not.Null.Or.Empty, "#14");
Assert.That (CompiledPlist.Get<PString> (dtXcodeBuild).Value, Is.Not.Null.Or.Empty, "#15");
}

[Test]
Expand All @@ -205,7 +205,7 @@ public virtual void DeviceFamily ()
public virtual void MinimumOSVersion ()
{
Assert.That (CompiledPlist.ContainsKey (ManifestKeys.MinimumOSVersion), "#1");
Assert.IsNotNullOrEmpty (CompiledPlist.Get<PString> (ManifestKeys.MinimumOSVersion).Value, "#2");
Assert.That (CompiledPlist.Get<PString> (ManifestKeys.MinimumOSVersion).Value, Is.Not.Null.Or.Empty, "#2");
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void TestBasicIBToolFunctionality ()

foreach (var bundleResource in ibtool.BundleResources) {
Assert.IsTrue (File.Exists (bundleResource.ItemSpec), "File does not exist: {0}", bundleResource.ItemSpec);
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("LogicalName"), "The 'LogicalName' metadata must be set.");
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("Optimize"), "The 'Optimize' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("LogicalName"), Is.Not.Null.Or.Empty, "The 'LogicalName' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("Optimize"), Is.Not.Null.Or.Empty, "The 'Optimize' metadata must be set.");

bundleResources.Add (bundleResource.GetMetadata ("LogicalName"));
}
Expand Down Expand Up @@ -141,10 +141,10 @@ public void TestAdvancedIBToolFunctionality ()
var tag = bundleResource.GetMetadata ("ResourceTags");

Assert.IsTrue (File.Exists (bundleResource.ItemSpec), "File does not exist: {0}", bundleResource.ItemSpec);
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("LogicalName"), "The 'LogicalName' metadata must be set.");
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("Optimize"), "The 'Optimize' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("LogicalName"), Is.Not.Null.Or.Empty, "The 'LogicalName' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("Optimize"), Is.Not.Null.Or.Empty, "The 'Optimize' metadata must be set.");

Assert.IsNotNullOrEmpty (tag, "The 'ResourceTags' metadata should be set.");
Assert.That (tag, Is.Not.Null.Or.Empty, "The 'ResourceTags' metadata should be set.");
Assert.IsTrue (bundleName.Contains (".lproj/" + tag + ".storyboardc/"), "BundleResource does not have the proper ResourceTags set: {0}", bundleName);

bundleResources.Add (bundleName);
Expand Down Expand Up @@ -233,10 +233,10 @@ static void TestGenericAndDeviceSpecificXibsGeneric (params string[] fileNames)
var tag = bundleResource.GetMetadata ("ResourceTags");

Assert.IsTrue (File.Exists (bundleResource.ItemSpec), "File does not exist: {0}", bundleResource.ItemSpec);
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("LogicalName"), "The 'LogicalName' metadata must be set.");
Assert.IsNotNullOrEmpty (bundleResource.GetMetadata ("Optimize"), "The 'Optimize' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("LogicalName"), Is.Not.Null.Or.Empty, "The 'LogicalName' metadata must be set.");
Assert.That (bundleResource.GetMetadata ("Optimize"), Is.Not.Null.Or.Empty, "The 'Optimize' metadata must be set.");

Assert.IsNotNullOrEmpty (tag, "The 'ResourceTags' metadata should be set.");
Assert.That (tag, Is.Not.Null.Or.Empty, "The 'ResourceTags' metadata should be set.");
Assert.AreEqual (Path.Combine (tmp, "ibtool", tag + ".nib", Path.GetFileName (bundleName)), bundleResource.ItemSpec, $"BundleResource {bundleName} is not at the expected location.");

bundleResources.Add (bundleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public void MTouchEnableBitcode (string frameworkIdentifier)
}

[Test]
[ExpectedException (typeof(InvalidOperationException), ExpectedMessage = "Bitcode is currently not supported on iOS.")]
public void StandardCommandline_WithBitcodeEnabled_iOS ()
{
MTouchEnableBitcode("Xamarin.iOS");

Task.GenerateCommandLineCommands ();
var ex = Assert.Throws<InvalidOperationException> (() => Task.GenerateCommandLineCommands (), "Exception");
Assert.AreEqual ("Bitcode is currently not supported on iOS.", ex.Message, "Message");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<Reference Include="Microsoft.Build" HintPath="$(MSBuildBinPath)\Microsoft.Build.dll" />
<Reference Include="Microsoft.Build.Utilities.Core" HintPath="$(MSBuildBinPath)\Microsoft.Build.Utilities.Core.dll" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework">
<HintPath>..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.10.0" />
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter" Version="3.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Xamarin.iOS.Tasks\Xamarin.iOS.Tasks.csproj">
Expand Down Expand Up @@ -120,7 +120,6 @@
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\Entitlements.plist">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
5 changes: 0 additions & 5 deletions msbuild/tests/Xamarin.iOS.Tasks.Tests/packages.config

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ killall:
NUNIT_MSBUILD_DIR=$(TOP)/packages/NUnit.Runners.2.6.4/tools/lib
test-ios-tasks:
$(SYSTEM_XIBUILD) -- $(TOP)/msbuild/Xamarin.MacDev.Tasks.sln
cd $(NUNIT_MSBUILD_DIR) && $(SYSTEM_XIBUILD) -t -- ../nunit-console.exe ../../../../msbuild/tests/bin/Xamarin.iOS.Tasks.Tests.dll -xml=TestResults_Xamarin.iOS.Tasks.Tests.xml -labels $(TEST_FIXTURE) || touch .failed-stamp
cd $(TOP)/msbuild/tests/Xamarin.iOS.Tasks.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.10.0) $(abspath $(TOP)/msbuild/tests/bin/Xamarin.iOS.Tasks.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.iOS.Tasks.Tests.xml);format=nunit2" -labels=All $(TEST_FIXTURE) || touch .failed-stamp
@[[ -z "$$BUILD_REPOSITORY" ]] || ( xsltproc $(TOP)/tests/HtmlTransform.xslt $(NUNIT_MSBUILD_DIR)/TestResults_Xamarin.iOS.Tasks.Tests.xml > $(TOP)/tests/index.html && echo "@MonkeyWrench: AddFile: $$PWD/index.html" )
@if test -e $(NUNIT_MSBUILD_DIR)/.failed-stamp; then rm $(NUNIT_MSBUILD_DIR)/.failed-stamp; exit 1; fi

Expand Down
25 changes: 20 additions & 5 deletions tests/xharness/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3055,11 +3055,21 @@ public void FindNUnitConsoleExecutable (Log log)

var packages_conf = Path.Combine (Path.GetDirectoryName (TestProject.Path), "packages.config");
var nunit_version = string.Empty;
var is_packageref = false;
const string default_nunit_version = "3.9.0";

if (!File.Exists (packages_conf)) {
nunit_version = default_nunit_version;
log.WriteLine ("No packages.config found for {0}: assuming nunit version is {1}", TestProject, nunit_version);
var xml = new XmlDocument ();
xml.LoadWithoutNetworkAccess (TestProject.Path);
var packageref = xml.SelectSingleNode ("//*[local-name()='PackageReference' and @Include = 'NUnit.ConsoleRunner']");
if (packageref != null) {
is_packageref = true;
nunit_version = packageref.Attributes ["Version"].InnerText;
log.WriteLine ("Found PackageReference in {0} for NUnit.ConsoleRunner {1}", TestProject, nunit_version);
} else {
nunit_version = default_nunit_version;
log.WriteLine ("No packages.config found for {0}: assuming nunit version is {1}", TestProject, nunit_version);
}
} else {
using (var str = new StreamReader (packages_conf)) {
using (var reader = System.Xml.XmlReader.Create (str)) {
Expand All @@ -3083,8 +3093,13 @@ public void FindNUnitConsoleExecutable (Log log)
log.WriteLine ("Found the NUnit.ConsoleRunner/NUnit.Runners element in {0} for {2}, version is: {1}", packages_conf, nunit_version, TestProject.Path);
}
}

if (nunit_version [0] == '2') {

if (is_packageref) {
TestExecutable = Path.Combine (Harness.RootDirectory, "..", "tools", $"nunit3-console-{nunit_version}");
if (!File.Exists (TestExecutable))
throw new FileNotFoundException ($"The helper script to execute the unit tests does not exist: {TestExecutable}");
WorkingDirectory = Path.GetDirectoryName (TestProject.Path);
} else if (nunit_version [0] == '2') {
TestExecutable = Path.Combine (Harness.RootDirectory, "..", "packages", "NUnit.Runners." + nunit_version, "tools", "nunit-console.exe");
WorkingDirectory = Path.Combine (Path.GetDirectoryName (TestExecutable), "lib");
} else {
Expand All @@ -3099,7 +3114,7 @@ public void FindNUnitConsoleExecutable (Log log)

public bool IsNUnit3 {
get {
return Path.GetFileName (TestExecutable) == "nunit3-console.exe";
return Path.GetFileName (TestExecutable).Contains ("unit3-console");
}
}
public override IEnumerable<Log> AggregatedLogs {
Expand Down
3 changes: 3 additions & 0 deletions tools/nunit3-console-3.10.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -eu

exec mono ~/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe "$@"

0 comments on commit c422869

Please sign in to comment.