Skip to content

Commit

Permalink
Merge pull request #205 from nunit/issue-10d
Browse files Browse the repository at this point in the history
Lightweight .NET Standard version of the Engine
  • Loading branch information
rprouse authored Apr 28, 2017
2 parents d51b0b1 + ba194ae commit 3f71e38
Show file tree
Hide file tree
Showing 47 changed files with 1,991 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
*.project.lock.json

# Build results

Expand Down
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
language: csharp
sudo: false
mono:
- latest
- 4.2.4
os:
- linux
- osx
sudo: required
matrix:
include:
- os: linux
dist: trusty
mono: latest
- os: linux
dist: trusty
mono: 4.2.4
- os: osx
mono: latest
allow_failures:
- mono: latest
fast_finish: true

script:
- ./build.sh --target "Travis"
58 changes: 58 additions & 0 deletions NUnit.Engine.Netstandard.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
build.cake = build.cake
BUILDING.md = BUILDING.md
CHANGES.txt = CHANGES.txt
CONTRIBUTING.md = CONTRIBUTING.md
LICENSE.txt = LICENSE.txt
NOTICES.txt = NOTICES.txt
NuGet.config = NuGet.config
nunit.ico = nunit.ico
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.tests.netstandard", "src\NUnitEngine\nunit.engine.tests.netstandard\nunit.engine.tests.netstandard.csproj", "{BC22F0E4-0862-4F82-A912-C9A447FECBAD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly.netstandard", "src\NUnitEngine\mock-assembly\mock-assembly.netstandard.csproj", "{BC6C8155-2024-4F58-A006-18A15EA22A5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.netstandard", "src\NUnitEngine\nunit.engine.netstandard\nunit.engine.netstandard.csproj", "{C26FFC46-60CE-4CBA-87BD-8E9B972C0E0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC22F0E4-0862-4F82-A912-C9A447FECBAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC22F0E4-0862-4F82-A912-C9A447FECBAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC22F0E4-0862-4F82-A912-C9A447FECBAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC22F0E4-0862-4F82-A912-C9A447FECBAD}.Release|Any CPU.Build.0 = Release|Any CPU
{BC6C8155-2024-4F58-A006-18A15EA22A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC6C8155-2024-4F58-A006-18A15EA22A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC6C8155-2024-4F58-A006-18A15EA22A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC6C8155-2024-4F58-A006-18A15EA22A5C}.Release|Any CPU.Build.0 = Release|Any CPU
{C26FFC46-60CE-4CBA-87BD-8E9B972C0E0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C26FFC46-60CE-4CBA-87BD-8E9B972C0E0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C26FFC46-60CE-4CBA-87BD-8E9B972C0E0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C26FFC46-60CE-4CBA-87BD-8E9B972C0E0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = src\NUnitFramework\tests\nunitlite.tests-2.0.csproj
{28B605B2-E2E9-417E-8369-49E263F1F31B} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
{FFF45826-991F-465B-8A03-0E1DB7E8F38C} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
{11640C9F-03A3-456B-848D-9B4A126F9506} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
EndGlobalSection
EndGlobal
138 changes: 120 additions & 18 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrorDetail = new List<string>();
//////////////////////////////////////////////////////////////////////

var version = "3.7.0";
var modifier = "";
var modifier = "-alpha1";

var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
Expand All @@ -32,6 +32,8 @@ var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var IMAGE_DIR = PROJECT_DIR + "images/";

var SOLUTION_FILE = "NUnitConsole.sln";
var DOTNETCORE_SOLUTION_FILE = "NUnit.Engine.NetStandard.sln";
var DOTNETCORE_TEST_ASSEMBLY = "src/NUnitEngine/nunit.engine.tests.netstandard/bin/" + configuration + "/netcoreapp1.1/nunit.engine.tests.netstandard.dll";

// Package sources for nuget restore
var PACKAGE_SOURCE = new string[]
Expand All @@ -47,6 +49,24 @@ var NUNIT3_CONSOLE = BIN_DIR + "nunit3-console.exe";
var ENGINE_TESTS = "nunit.engine.tests.dll";
var CONSOLE_TESTS = "nunit3-console.tests.dll";

bool IsDotNetCoreInstalled = false;

//////////////////////////////////////////////////////////////////////
// SETUP AND TEARDOWN TASKS
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
// Executed BEFORE the first task.
Information("Building version {0} of NUnit.", packageVersion);
IsDotNetCoreInstalled = CheckIfDotNetCoreInstalled();
});

Teardown(context =>
{
// Executed AFTER the last task.
CheckForError(ref ErrorDetail);
});

//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Expand All @@ -67,10 +87,18 @@ Task("InitializeBuild")
.Description("Initializes the build")
.Does(() =>
{
NuGetRestore(SOLUTION_FILE, new NuGetRestoreSettings()
{
Source = PACKAGE_SOURCE
});
Information("Restoring NuGet packages");
NuGetRestore(SOLUTION_FILE, new NuGetRestoreSettings
{
Source = PACKAGE_SOURCE,
Verbosity = NuGetVerbosity.Detailed
});
if(IsDotNetCoreInstalled && IsRunningOnWindows())
{
Information("Restoring .NET Core packages");
DotNetCoreRestore(DOTNETCORE_SOLUTION_FILE);
}
if (BuildSystem.IsRunningOnAppVeyor)
{
Expand Down Expand Up @@ -133,6 +161,32 @@ Task("BuildEngine")
BuildProject("./src/NUnitEngine/notest-assembly/notest-assembly.csproj", configuration);
});

//////////////////////////////////////////////////////////////////////
// BUILD NETSTANDARD ENGINE
//////////////////////////////////////////////////////////////////////

Task("BuildNetStandardEngine")
.Description("Builds the .NET Standard engine")
.IsDependentOn("InitializeBuild")
.WithCriteria(IsRunningOnWindows())
.Does(() =>
{
if(IsDotNetCoreInstalled)
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
EnvironmentVariables = new Dictionary<string, string>()
};
settings.EnvironmentVariables.Add("PackageVersion", packageVersion);
DotNetCoreBuild(DOTNETCORE_SOLUTION_FILE, settings);
}
else
{
Warning("Skipping .NET Standard build because .NET Core is not installed");
}
});

//////////////////////////////////////////////////////////////////////
// BUILD CONSOLE
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -204,6 +258,27 @@ Task("TestConsole")
RunTest(NUNIT3_CONSOLE, BIN_DIR, CONSOLE_TESTS, "TestConsole", ref ErrorDetail);
});

//////////////////////////////////////////////////////////////////////
// TEST NETSTANDARD ENGINE
//////////////////////////////////////////////////////////////////////

Task("TestNetStandardEngine")
.Description("Tests the .NET Standard Engine")
.IsDependentOn("BuildNetStandardEngine")
.WithCriteria(IsRunningOnWindows())
.OnError(exception => { ErrorDetail.Add(exception.Message); })
.Does(() =>
{
if(IsDotNetCoreInstalled)
{
DotNetCoreExecute(DOTNETCORE_TEST_ASSEMBLY);
}
else
{
Warning("Skipping .NET Standard tests because .NET Core is not installed");
}
});

//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -337,23 +412,47 @@ Task("PackageConsole")
});

//////////////////////////////////////////////////////////////////////
// SETUP AND TEARDOWN TASKS
// PACKAGE NETSTANDARD ENGINE
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
// Executed BEFORE the first task.
});

Teardown(context =>
{
// Executed AFTER the last task.
CheckForError(ref ErrorDetail);
});
Task("PackageNetStandardEngine")
.Description("Copies the .NET Standard Engine nuget package in the packages directory")
.WithCriteria(IsRunningOnWindows())
.Does(() =>
{
if(IsDotNetCoreInstalled)
{
var nuget = "nunit.engine.netstandard." + packageVersion + ".nupkg";
var src = "src/NUnitEngine/nunit.engine.netstandard/bin/" + configuration + "/" + nuget;
var dest = PACKAGE_DIR + nuget;
CreateDirectory(PACKAGE_DIR);
CopyFile(src, dest);
}
});

//////////////////////////////////////////////////////////////////////
// HELPER METHODS - GENERAL
//////////////////////////////////////////////////////////////////////

bool CheckIfDotNetCoreInstalled()
{
try
{
Information("Checking if .NET Core SDK is installed");
StartProcess("dotnet", new ProcessSettings
{
Arguments = "--version"
});
}
catch(Exception)
{
Warning(".NET Core SDK is not installed. It can be installed from https://www.microsoft.com/net/core");
return false;
}
return true;
}

void RunGitCommand(string arguments)
{
StartProcess("git", new ProcessSettings()
Expand Down Expand Up @@ -445,7 +544,8 @@ void RunTest(FilePath exePath, DirectoryPath workingDir, string arguments, strin
Task("Build")
.Description("Builds the engine and console runner")
.IsDependentOn("BuildEngine")
.IsDependentOn("BuildConsole");
.IsDependentOn("BuildConsole")
.IsDependentOn("BuildNetStandardEngine");

Task("Rebuild")
.Description("Rebuilds the engine and console runner")
Expand All @@ -455,13 +555,15 @@ Task("Rebuild")
Task("Test")
.Description("Builds and tests the engine and console runner")
.IsDependentOn("TestEngine")
.IsDependentOn("TestConsole");
.IsDependentOn("TestConsole")
.IsDependentOn("TestNetStandardEngine");

Task("Package")
.Description("Packages the engine and console runner")
.IsDependentOn("CheckForError")
.IsDependentOn("PackageEngine")
.IsDependentOn("PackageConsole");
.IsDependentOn("PackageConsole")
.IsDependentOn("PackageNetStandardEngine");

Task("Appveyor")
.Description("Builds, tests and packages on AppVeyor")
Expand Down
20 changes: 4 additions & 16 deletions src/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@
[assembly: AssemblyConfiguration(".NET 4.0 Debug")]
#elif NET_2_0
[assembly: AssemblyConfiguration(".NET 2.0 Debug")]
#elif SL_5_0
[assembly: AssemblyConfiguration("Silverlight 5.0 Debug")]
#elif SL_4_0
[assembly: AssemblyConfiguration("Silverlight 4.0 Debug")]
#elif SL_3_0
[assembly: AssemblyConfiguration("Silverlight 3.0 Debug")]
#elif NETCF_3_5
[assembly: AssemblyConfiguration("Compact Framework 3.5 Debug")]
#elif PORTABLE
[assembly: AssemblyConfiguration("Portable Debug")]
#elif NETSTANDARD1_3 || NETSTANDARD1_6 || NETCOREAPP1_0
[assembly: AssemblyConfiguration(".NET Standard Debug")]
#else
[assembly: AssemblyConfiguration("Debug")]
#endif
Expand All @@ -62,16 +56,10 @@
[assembly: AssemblyConfiguration(".NET 4.0")]
#elif NET_2_0
[assembly: AssemblyConfiguration(".NET 2.0")]
#elif SL_5_0
[assembly: AssemblyConfiguration("Silverlight 5.0")]
#elif SL_4_0
[assembly: AssemblyConfiguration("Silverlight 4.0")]
#elif SL_3_0
[assembly: AssemblyConfiguration("Silverlight 3.0")]
#elif NETCF_3_5
[assembly: AssemblyConfiguration("Compact Framework 3.5")]
#elif PORTABLE
[assembly: AssemblyConfiguration("Portable")]
#elif NETSTANDARD1_3 || NETSTANDARD1_6 || NETCOREAPP1_0
[assembly: AssemblyConfiguration(".NET Standard")]
#else
[assembly: AssemblyConfiguration("")]
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/NUnitEngine/mock-assembly/MockAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public class MockAssembly

public const int Inconclusive = MockTestFixture.Inconclusive;

#if !NETSTANDARD1_6
public static readonly string AssemblyPath = AssemblyHelper.GetAssemblyPath(typeof(MockAssembly).Assembly);
#endif
}

[TestFixture(Description="Fake Test Fixture")]
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitEngine/mock-assembly/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@

[assembly: AssemblyTitle("mock-assembly")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyCulture("")]
29 changes: 29 additions & 0 deletions src/NUnitEngine/mock-assembly/mock-assembly.netstandard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<RootNamespace>NUnit.Tests</RootNamespace>
<TargetFramework>netstandard1.6</TargetFramework>
<AssemblyName>mock-assembly</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\nunit.snk</AssemblyOriginatorKeyFile>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Version>$(PackageVersion)</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
<Compile Include="..\EngineVersion.cs" Link="Properties\EngineVersion.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.6.1" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\nunit.snk">
<Link>nunit.snk</Link>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit 3f71e38

Please sign in to comment.