This commit is contained in:
Charlie Poole 2016-09-23 17:36:33 -07:00
Родитель 65ffce1e34
Коммит f74b7c8219
11 изменённых файлов: 483 добавлений и 3 удалений

4
.gitignore поставляемый
Просмотреть файл

@ -176,4 +176,6 @@ test-results
package
images
MockAssemblyResult.xml
PortabilityAnalysis*.html
PortabilityAnalysis*.html
tools
!tools/packages.config

12
appveyor.yml Normal file
Просмотреть файл

@ -0,0 +1,12 @@
version: 3.5.{build}
image: Visual Studio 2015
build_script:
- ps: .\build.ps1 -Target "Appveyor"
# disable built-in tests.
test: off
artifacts:
- path: package\*.nupkg
- path: package\*.zip

2
build Normal file
Просмотреть файл

@ -0,0 +1,2 @@
#!/bin/bash
./build.sh $CAKE_ARGS "$@"

233
build.cake Normal file
Просмотреть файл

@ -0,0 +1,233 @@
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.1
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////
var version = "3.5.0";
var modifier = "";
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
if (BuildSystem.IsRunningOnAppVeyor)
{
var tag = AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
{
packageVersion = tag.Name;
}
else
{
var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000");
var branch = AppVeyor.Environment.Repository.Branch;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
if (branch == "master" && !isPullRequest)
{
packageVersion = version + "-dev-" + buildNumber + dbgSuffix;
}
else
{
var suffix = "-ci-" + buildNumber + dbgSuffix;
if (isPullRequest)
suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number;
else
suffix += "-" + branch;
// Nuget limits "special version part" to 20 chars. Add one for the hyphen.
if (suffix.Length > 21)
suffix = suffix.Substring(0, 21);
suffix = suffix.Replace(".", "");
packageVersion = version + suffix;
}
}
AppVeyor.UpdateBuildVersion(packageVersion);
}
var packageName = "NUnitV2Driver-" + packageVersion;
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// Directories
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
var PACKAGE_IMAGE_DIR = PACKAGE_DIR + packageName + "/";
var TOOLS_DIR = PROJECT_DIR + "tools/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
// Solution
var SOLUTION_FILE = PROJECT_DIR + "nunit.v2.driver.sln";
// Test Runner
var NUNIT3_CONSOLE = TOOLS_DIR + "NUnit.ConsoleRunner/tools/nunit3-console.exe";
// Test Assembly
var DRIVER_TESTS = BIN_DIR + "nunit.v2.driver.tests.dll";
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(BIN_DIR);
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
//////////////////////////////////////////////////////////////////////
Task("NuGetRestore")
.Does(() =>
{
NuGetRestore(SOLUTION_FILE);
});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("NuGetRestore")
.Does(() =>
{
BuildSolution(SOLUTION_FILE, configuration);
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT3_CONSOLE,
new ProcessSettings()
{
Arguments = DRIVER_TESTS
});
if (rc != 0)
{
var message = rc > 0
? string.Format("Test failure: {0} tests failed", rc)
: string.Format("Test exited with rc = {0}", rc);
throw new CakeException(message);
}
});
//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Task("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
});
Task("CreateWorkingImage")
.IsDependentOn("Build")
.IsDependentOn("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_IMAGE_DIR);
CleanDirectory(PACKAGE_IMAGE_DIR);
CopyFileToDirectory("LICENSE.txt", PACKAGE_IMAGE_DIR);
var binFiles = new FilePath[]
{
BIN_DIR + "NUnit3.TestAdapter.dll",
BIN_DIR + "nunit.engine.dll",
BIN_DIR + "nunit.engine.api.dll",
BIN_DIR + "Mono.Cecil.dll",
BIN_DIR + "Mono.Cecil.Pdb.dll",
BIN_DIR + "Mono.Cecil.Mdb.dll",
BIN_DIR + "Mono.Cecil.Rocks.dll"
};
var binDir = PACKAGE_IMAGE_DIR + "bin/";
CreateDirectory(binDir);
CopyFiles(binFiles, binDir);
});
Task("PackageZip")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
Zip(PACKAGE_IMAGE_DIR, File(PACKAGE_DIR + packageName + ".zip"));
});
Task("PackageNuGet")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
NuGetPack("nuget/NUnit3TestAdapter.nuspec", new NuGetPackSettings()
{
Version = packageVersion,
BasePath = PACKAGE_IMAGE_DIR,
OutputDirectory = PACKAGE_DIR
});
});
//////////////////////////////////////////////////////////////////////
// HELPER METHODS
//////////////////////////////////////////////////////////////////////
void BuildSolution(string solutionPath, string configuration)
{
MSBuild(solutionPath, new MSBuildSettings()
.SetConfiguration(configuration)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false)
);
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Package")
.IsDependentOn("Build")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageNuGet");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);

2
build.cmd Normal file
Просмотреть файл

@ -0,0 +1,2 @@
@echo off
powershell ./build.ps1 %CAKE_ARGS% %*

145
build.ps1 Normal file
Просмотреть файл

@ -0,0 +1,145 @@
##########################################################################
# This is the Cake bootstrapper script for PowerShell.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################
<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
and execute your Cake build script with the parameters you provide.
.PARAMETER Script
The build script to execute.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER Experimental
Tells Cake to use the latest Roslyn release.
.PARAMETER WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER Mono
Tells Cake to use the Mono scripting engine.
.PARAMETER SkipToolPackageRestore
Skips restoring of packages.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
http://cakebuild.net
#>
[CmdletBinding()]
Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
Write-Host "Preparing to run build script..."
$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition;
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
# Should we use mono?
$UseMono = "";
if($Mono.IsPresent) {
Write-Verbose -Message "Using the Mono based scripting engine."
$UseMono = "-mono"
}
# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
Write-Verbose -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}
# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}
# Make sure tools folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
Write-Verbose -Message "Creating tools directory..."
New-Item -Path $TOOLS_DIR -Type directory | out-null
}
# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
Write-Verbose -Message "Downloading packages.config..."
try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
Throw "Could not download packages.config."
}
}
# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
}
}
# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Downloading NuGet.exe..."
try {
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
} catch {
Throw "Could not download NuGet.exe."
}
}
# Save nuget.exe path to environment to be available to child processed
$ENV:NUGET_EXE = $NUGET_EXE
# Restore tools from NuGet?
if(-Not $SkipToolPackageRestore.IsPresent) {
Push-Location
Set-Location $TOOLS_DIR
Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
}
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}
# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
}
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE

73
build.sh Normal file
Просмотреть файл

@ -0,0 +1,73 @@
#!/bin/bash
###############################################################
# This is the Cake bootstrapper script that is responsible for
# downloading Cake and all specified tools from NuGet.
###############################################################
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
NUGET_EXE=$TOOLS_DIR/nuget.exe
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
NUNIT_CONSOLE_EXE=$TOOLS_DIR/NUnit.ConsoleRunner/tools/nunit3-console.exe
NUNIT_AGENT_EXE=$TOOLS_DIR/NUnit.ConsoleRunner/tools/nunit-agent.exe
NUNIT_AGENT_X86_EXE=$TOOLS_DIR/NUnit.ConsoleRunner/tools/nunit-agent-x86.exe
# Define default arguments.
SCRIPT="build.cake"
TARGET="Default"
CONFIGURATION="Release"
VERBOSITY="verbose"
DRYRUN=false
SHOW_VERSION=false
# Parse arguments.
for i in "$@"; do
case $1 in
-s|--script) SCRIPT="$2"; shift ;;
-t|--target) TARGET="$2"; shift ;;
-c|--configuration) CONFIGURATION="$2"; shift ;;
-v|--verbosity) VERBOSITY="$2"; shift ;;
-d|--dryrun) DRYRUN=true ;;
--version) SHOW_VERSION=true ;;
esac
shift
done
chmod +x $NUNIT_CONSOLE_EXE
chmod +x $NUNIT_AGENT_EXE
chmod +x $NUNIT_AGENT_X86_EXE
# Download NuGet if it does not exist.
if [ ! -f $NUGET_EXE ]; then
echo "Downloading NuGet..."
curl -Lsfo $NUGET_EXE https://www.nuget.org/nuget.exe
chmod +x $NUGET_EXE
if [ $? -ne 0 ]; then
echo "An error occured while downloading nuget.exe."
exit 1
fi
fi
# Restore tools from NuGet.
pushd $TOOLS_DIR >/dev/null
mono $NUGET_EXE install -ExcludeVersion
popd >/dev/null
# Make sure that Cake has been installed.
if [ ! -f $CAKE_EXE ]; then
echo "Could not find Cake.exe."
exit 1
fi
# Start Cake
if $SHOW_VERSION; then
mono $CAKE_EXE -version
elif $DRYRUN; then
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET -dryrun
else
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET
fi
exit $?

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

@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.v2.driver", "src\exte
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{90F23995-721F-40CB-9D64-28FF5FD98250}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build = build
build.cake = build.cake
build.cmd = build.cmd
build.ps1 = build.ps1
build.sh = build.sh
README.md = README.md
EndProjectSection
EndProject

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

@ -75,7 +75,7 @@ namespace NUnit.Engine.Drivers
public string Load(string testAssemblyPath, IDictionary<string, object> settings)
{
if (!File.Exists(testAssemblyPath))
throw new ArgumentException("testAssemblyPath", "Framework driver Load called with a file name that doesn't exist.");
throw new ArgumentException("Framework driver Load called with a file name that doesn't exist.", "testAssemblyPath");
_testAssemblyPath = testAssemblyPath;
_name = Escape(Path.GetFileName(_testAssemblyPath));

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

@ -37,7 +37,7 @@ namespace NUnit.Engine.Drivers.Tests
private const string EMPTY_FILTER = "<filter/>";
private const int TESTCASECOUNT = 74;
private static readonly string V2_TEST_PATH = Path.GetFullPath(V2_TEST_DIR);
private static readonly string V2_TEST_PATH = Path.Combine(TestContext.CurrentContext.TestDirectory, V2_TEST_DIR);
private static readonly string ASSEMBLY_PATH = Path.Combine(V2_TEST_PATH, ASSEMBLY_NAME);
private NUnit2FrameworkDriver _driver;
@ -45,6 +45,7 @@ namespace NUnit.Engine.Drivers.Tests
[OneTimeSetUp]
public void CreateDriver()
{
Console.WriteLine(ASSEMBLY_PATH);
var domain = AppDomain.CreateDomain(V2_DOMAIN_NAME, null, V2_TEST_PATH, null, false);
_driver = new NUnit2FrameworkDriver(domain);

4
tools/packages.config Normal file
Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.15.2" />
</packages>