Skip to content

Commit

Permalink
ccnet#286 Fix PR: Change NUnit v2 to v3
Browse files Browse the repository at this point in the history
- fix some broken tests
- detect latest MSBuild available
- fix cake script
  • Loading branch information
savornicesei committed Jan 26, 2020
1 parent 531d3c7 commit add2d1c
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 43 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ docgen/
wiki/
**/CommonAssemblyInfo.cs

#ignore NuGet tools
[Tt]ools/EWSoftware.SHFB*
[Tt]ools/vswhere*
[Tt]ools/NUnit.ConsoleRunner*

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down Expand Up @@ -366,4 +371,6 @@ _site/

#cake
[Tt]ools/Cake/*
![Tt]ools/Cake/packages.config
![Tt]ools/Cake/packages.config

thelabelprefix.txt
102 changes: 101 additions & 1 deletion Tools/ccnet-utils.inc.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,105 @@
</delete>

</target>


<!--***********************************
Determines the path to MSBuild based on the same logic as NuGet (see NuGetClient.CommandLine.MsBuildUtility)
*********************************** -->
<script language="C#" prefix="framework">
<references>
<include name="System.dll" />
</references>
<imports>
<import namespace="System.Diagnostics" />
</imports>
<code>
<![CDATA[
[Function("get-msbuild-path")]
public static string getMSBuildPath(string vswherePath)
{
string msBuildPath = string.Empty;
try
{
var platform = (int)Environment.OSVersion.Platform;
var isLinux = platform == 4;
var isWindows = (platform != 4) && (platform != 6) && (platform != 128);
var isMono = Type.GetType("Mono.Runtime") != null;
if(isLinux && isMono)
{
var libPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
//path to msbuild folder is /usr/lib/mono/msbuild
//path to xbuild folder is /usr/lib/mono/xbuild
string[] buildExecutables = new string[4]{
Path.Combine(libPath, "..", "msbuild", "15.0", "bin", "MSBuild.dll"),
Path.Combine(libPath, "..", "msbuild", "14.1", "bin", "MSBuild.dll"),
Path.Combine(libPath, "..", "xbuild", "14.0", "bin", "xbuild.exe"),
Path.Combine(libPath, "..", "xbuild", "12.0", "bin", "xbuild.exe")
};
foreach(var buildExe in buildExecutables)
{
if(File.Exists(buildExe))
{
msBuildPath = buildExe;
break;
}
}
}
if(isWindows)
{
string vswhere = @"d:\Share\OSS\CruiseControl.NET\CruiseControl.NET_2\Tools\vswhere.2.8.4\tools\vswhere.exe";
if(!File.Exists(vswhere))
{
Console.WriteLine("Path to vswhere is invalid!!!");
}
else
{
Process process = null;
try
{
using (process = new Process())
{
process.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
process.StartInfo.FileName = vswhere;
process.StartInfo.Arguments = @" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine("Detected MSBuild: " + output);
string error = process.StandardError.ReadToEnd();
Console.WriteLine("Error: " + error);
process.WaitForExit();
msBuildPath = output.Replace(Environment.NewLine, "");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
return msBuildPath;
}
]]>
</code>
</script>

</project>
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Task("build-all")
//Tools\NAnt\NAnt.exe clean build -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " all -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build.log.txt" ,
Arguments = " all -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build-all.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Silent = false
Expand Down
86 changes: 59 additions & 27 deletions ccnet.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
<property name="ndepend.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'NDepend'), 'NDepend.Console.exe')}" />
<property name="fxcop.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'FxCop'), 'FxCopCmd.exe')}" />
<property name="nsis.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'NSIS'), 'makensis.exe')}" />
<property name="nuget.executable" readonly="true" value="${environment::get-variable('NUGET_EXE')}" />
<!-- If NUGET_EXE env. variable does not exist, fallback to the one provided by Cake -->
<property name="nuget.executable" value="${environment::get-variable('NUGET_EXE')}" if="${environment::variable-exists('NUGET_EXE')}" />
<property name="nuget.executable" value="${path::combine( path::combine(tools.dir, 'Cake'), 'nuget.exe')}" if="${not environment::variable-exists('NUGET_EXE')}" />

<property name="nunit.executable" value="${path::combine( path::combine(tools.dir, 'NUnit.ConsoleRunner'), 'tools')}" unless="${property::exists('nunit.executable')}" />
<!-- NuGet tools retrieved at restore time -->
<property name="vswhere.executable" value="${path::combine( path::combine(tools.dir, 'vswhere.2.8.4'), 'tools')}" unless="${property::exists('vswhere.path')}" />
<property name="shfb.path" value="${path::combine( path::combine(tools.dir, 'EWSoftware.SHFB.2019.11.17'), 'tools')}" unless="${property::exists('shfb.path')}" />
<property name="nunit.executable" value="${path::combine( path::combine( path::combine(tools.dir, 'NUnit.ConsoleRunner.3.10.0'), 'tools'), 'nunit3-console.exe')}" unless="${property::exists('nunit.executable')}" />

<!-- common assembly info properties -->
<property name="assembly.company" readonly="true" value="ThoughtWorks Inc." />
Expand Down Expand Up @@ -90,6 +95,28 @@
</if>

<!-- Restore NuGet tools -->
<exec program="${nuget.executable}" if="${file::exists(nuget.executable)}">
<arg value="install"/>
<arg value="vswhere" />
<arg value="-Version" />
<arg value="2.8.4" />
<arg value="-OutputDirectory"/>
<arg value="${tools.dir}"/>
<arg value="-verbosity" />
<arg value="quiet" /> <!-- Specifies the amount of detail displayed in the output: normal, quiet, detailed -->
</exec>

<exec program="${nuget.executable}" if="${file::exists(nuget.executable)}">
<arg value="install"/>
<arg value="EWSoftware.SHFB" />
<arg value="-Version" />
<arg value="2019.11.17" />
<arg value="-OutputDirectory"/>
<arg value="${tools.dir}"/>
<arg value="-verbosity" />
<arg value="quiet" /> <!-- Specifies the amount of detail displayed in the output: normal, quiet, detailed -->
</exec>

<exec program="${nuget.executable}" if="${file::exists(nuget.executable)}">
<arg value="install"/>
<arg value="NUnit.ConsoleRunner" />
Expand Down Expand Up @@ -138,23 +165,40 @@
<echo message="Build configuration: ${build.configuration}" />
<echo message="Source Directory: ${src.dir}" />
<echo message="Build Directory: ${build.dir}" />
<echo message="MSBuild path: ${build.dir}" />

<!-- build for Linux - msbuild task still uses xbuild that was deprecated starting with mono 5.0 -->
<exec program="mono" if="${platform::is-unix()}" basedir="${src.dir}" workingdir="${src.dir}" verbose="true">
<arg value="${framework::get-msbuild-path('')}" />
<arg value="${path::combine(src.dir, build.project)}" />
<arg value="/t:${build.target}" />
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>
<!-- Ignore error CS0619: 'TestFixtureAttribute' is obsolete: 'The NUnit framework shipped with Mono is deprecated and will be removed in a future release' -->
<arg value="/p:WarningsNotAsErrors=619" />
<!-- Sandcastle help file required parameters -->
<arg value="/p:SHFBROOT=${shfb.path}" />
<!-- This is a hack until CCTrayLib uses plugins for Windows only stuff -->
<arg value="/p:DISABLE_COM=${platform::is-unix()}" />
<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<arg value="/p:DISABLE_JSCRIPT=${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<!-- Hack for current xbuild issues on Mono 2.5 -->
<arg value="/p:MONO_IOMAP=all" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<arg value="/p:MONO_PATH=${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</exec>

<msbuild projectFile="${path::combine(src.dir, build.project)}" targets="${build.target}" verbosity="Minimal">
<exec program="${framework::get-msbuild-path(vswhere.executable)}" if="${platform::is-windows()}" basedir="${src.dir}" workingdir="${src.dir}" verbose="true">
<arg value="${path::combine(src.dir, build.project)}" />
<arg value="/t:${build.target}" />
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>

<!-- This is a hack until CCTrayLib uses plugins for Windows only stuff -->
<property name="DISABLE_COM" value="${platform::is-unix()}" />
<arg value="/p:DISABLE_COM=${platform::is-unix()}" />

<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<property name="DISABLE_JSCRIPT" value="${framework::get-family(nant.settings.currentframework) == 'mono'}" />

<!-- Hack for current xbuild issues on Mono 2.5 -->
<environment>
<variable name="MONO_IOMAP" value="all" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<variable name="MONO_PATH" value="${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</environment>
</msbuild>
<arg value="/p:DISABLE_JSCRIPT=${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</exec>

<!-- copy ccnet.config into the server dictionary -->
<copy file="${path::combine( path::combine(src.dir, 'service'), 'ccnet.config')}" tofile="${path::combine( path::combine(build.dir, 'Server'), 'ccnet.config')}" verbose="${nant.verbosity}"/>
Expand Down Expand Up @@ -223,23 +267,11 @@
<copy file="${path::combine( path::combine(src.dir, 'UnitTests'), 'test.config')}" tofile="${path::combine( path::combine(build.dir, 'UnitTests'), 'ThoughtWorks.CruiseControl.UnitTests.dll.config')}" verbose="${nant.verbosity}" />
</if>

<!--
<nunitTest executable="${nunit.executable}" workingDirectory="${path::combine(build.dir, 'UnitTests')}" outputFile="${path::combine(build.metrics.dir, 'nunit-result.xml')}" commandLineParameterFlag="-" showLabels="true" verbose="${nant.verbosity}">
<assemblies>
<include name="${path::combine( path::combine(build.dir, 'UnitTests'), 'ThoughtWorks.CruiseControl.UnitTests.dll')}" />
</assemblies>
<environment>
<variable name="MONO_PATH" value="${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</environment>
</nunitTest>
-->
<exec program="${nunit.executable}" >
<arg value="${path::combine( path::combine(build.dir, 'UnitTests'), 'ThoughtWorks.CruiseControl.UnitTests.dll')}" />
<arg value="/result=${path::combine(build.metrics.dir, 'nunit-result.xml')}" />
<arg value="/exclude=Integration" />
<arg value="/framework:v4.0" />
<arg value="--result=${path::combine(build.metrics.dir, 'nunit-result.xml')}" />
<arg value="--where &quot;cat != Integration&quot;" />

</exec>


Expand Down
5 changes: 3 additions & 2 deletions project/UnitTests/CCnetDeploymentTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using NUnit.Framework;

namespace ThoughtWorks.CruiseControl.UnitTests
Expand All @@ -18,9 +19,9 @@ public class CCnetDeploymentTests
public void TestForAdminPackageOfWebDashboardIsEmpty()
{
#if DEBUG
string configFile = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"..\..\..\Webdashboard\dashboard.config");
string configFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\Webdashboard\dashboard.config");
#else
string configFile = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"..\..\Project\Webdashboard\dashboard.config");
string configFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"..\..\Project\Webdashboard\dashboard.config");
#endif
Assert.IsTrue(System.IO.File.Exists(configFile), "Dashboard.config not found at {0}", configFile);

Expand Down
4 changes: 2 additions & 2 deletions project/UnitTests/Core/Label/DefaultLabellerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void GeneratePrefixedLabelFromLabelPrefixFileAndLabelPrefixsFileSearchPat
[Test]
public void MustThrowExceptionWhenSpecifyingNonExistentFile()
{
var ex = Assert.Throws<System.Exception>(() =>
var ex = Assert.Throws<CruiseControl.Core.Config.ConfigurationException>(() =>
{
string lblFile = "DummyFile.txt";
Expand All @@ -278,7 +278,7 @@ public void MustThrowExceptionWhenSpecifyingNonExistentFile()
[Test]
public void MustThrowExceptionWhenContentsOfLabelPrefixFileDoesNotMatchLabelPrefixsFileSearchPattern()
{
var ex = Assert.Throws<System.Exception>(() =>
var ex = Assert.Throws<CruiseControl.Core.Config.ConfigurationException>(() =>
{
string lblFile = "thelabelprefix.txt";
System.IO.File.WriteAllText(lblFile, "ho ho ho");
Expand Down
18 changes: 18 additions & 0 deletions project/UnitTests/GlobalSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.IO;
using NUnit.Framework;

namespace ThoughtWorks.CruiseControl.UnitTests
{
[SetUpFixture]
public class GlobalSetup
{
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
// or identically under the hoods
//Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
}
}
}
14 changes: 7 additions & 7 deletions project/UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace ThoughtWorks.CruiseControl.UnitTests
{
/// <summary>
/// Helper methods for testing the serialisation/deserialisation of objects.
/// Helper methods for testing the serialization / serialization of objects.
/// </summary>
public static class TestHelpers
{
Expand All @@ -21,13 +21,13 @@ public static void EnsureLanguageIsValid()
}

/// <summary>
/// Tests that an object can be serialised and de-serialised.
/// Tests that an object can be serialized and deserialized.
/// </summary>
/// <param name="value">The value to test.</param>
/// <returns>The de-serialised object.</returns>
/// <returns>The deserialized object.</returns>
/// <remarks>
/// This does not test that the de-serialised object is the same as the source, it only tests
/// that the object can actually be serialised and de-serialised.
/// This does not test that the deserialized object is the same as the source, it only tests
/// that the object can actually be serialized and deserialized.
/// </remarks>
public static object RunSerialisationTest(object value)
{
Expand All @@ -40,7 +40,7 @@ public static object RunSerialisationTest(object value)
}
catch (Exception error)
{
Assert.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Unable to serialise: {0}", error.Message));
Assert.Fail(string.Format(CultureInfo.CurrentCulture,"Unable to serialize: {0}", error.Message));
}

stream.Position = 0;
Expand All @@ -50,7 +50,7 @@ public static object RunSerialisationTest(object value)
}
catch (Exception error)
{
Assert.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Unable to deserialise: {0}", error.Message));
Assert.Fail(string.Format(CultureInfo.CurrentCulture,"Unable to serialize: {0}", error.Message));
}
return result;
}
Expand Down
1 change: 1 addition & 0 deletions project/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
<Compile Include="Core\Util\PrivateStringTests.cs" />
<Compile Include="Core\Util\RemoteServerUriTests.cs" />
<Compile Include="Core\Util\ZipCompressionServiceTests.cs" />
<Compile Include="GlobalSetup.cs" />
<Compile Include="IntegrationTests\CCNet_1902.cs" />
<Compile Include="IntegrationTests\CruiseServerHarness.cs" />
<Compile Include="IntegrationTests\DynamicValuesTests.cs" />
Expand Down
4 changes: 2 additions & 2 deletions project/UnitTests/WebDashboard/IO/FingerprintFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void ShouldBuildAFingerprintWithValuesFromRequestIfBothHeadersAreAvailabl
}

[Test]
[Ignore]
[Ignore("TODO: provide a reason")]
public void ShouldFailGracefullyWithDatesFromBrowserWhichAreNotInRfc1123FormatByReturningValidButIncorrectFingerprint()
{
DateTime lastModifiedDate = new DateTime(2007, 4, 20);
Expand Down Expand Up @@ -81,4 +81,4 @@ public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFrom
Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag);
}
}
}
}

0 comments on commit add2d1c

Please sign in to comment.