Skip to content

Commit 66df351

Browse files
committed
CSHARP-1846: Run tests against .NET Core in Evergreen.
1 parent 14ce687 commit 66df351

File tree

5 files changed

+107
-139
lines changed

5 files changed

+107
-139
lines changed

Tools/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Addins/
2-
Cake/
2+
Cake*/
33
GitVersion.CommandLine/
44
packages/
55
nuget.exe

build.cake

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#addin "nuget:?package=Cake.Git"
2+
#addin "nuget:?package=Cake.Incubator"
23
#tool "nuget:?package=GitVersion.CommandLine"
34
#tool "nuget:?package=xunit.runner.console"
45
#load buildhelpers.cake
@@ -66,14 +67,39 @@ Task("TestNet45")
6667
.Does(() =>
6768
{
6869
var testAssemblies = GetFiles("./tests/**/bin/" + configuration + "/*Tests.dll");
69-
Console.WriteLine(string.Join("\n", testAssemblies));
70-
XUnit2(testAssemblies);
70+
var testSettings = new XUnit2Settings
71+
{
72+
Parallelism = ParallelismOption.None,
73+
ToolTimeout = TimeSpan.FromMinutes(30)
74+
};
75+
XUnit2(testAssemblies, testSettings);
7176
});
7277

7378
Task("TestNetStandard15")
79+
.IsDependentOn("BuildNetStandard15")
7480
.Does(() =>
7581
{
76-
Console.WriteLine("Run tests on .NET Core 1.0 here");
82+
var testsDirectory = solutionDirectory + Directory("tests");
83+
var testProjectNames = new []
84+
{
85+
"MongoDB.Bson.Tests.Dotnet",
86+
"MongoDB.Driver.Core.Tests.Dotnet",
87+
"MongoDB.Driver.Tests.Dotnet",
88+
"MongoDB.Driver.GridFS.Tests.Dotnet",
89+
"MongoDB.Driver.Legacy.Tests.Dotnet"
90+
};
91+
foreach (var testProjectName in testProjectNames)
92+
{
93+
var testProjectDirectory = testsDirectory + Directory(testProjectName);
94+
var testProjectFile = testProjectDirectory + File("project.json");
95+
var testSettings = new DotNetCoreTestSettings();
96+
var xunitSettings = new XUnit2Settings
97+
{
98+
Parallelism = ParallelismOption.None,
99+
ToolTimeout = TimeSpan.FromMinutes(30)
100+
};
101+
DotNetCoreTest(testSettings, testProjectFile, xunitSettings);
102+
}
77103
});
78104

79105
Task("TestWindows")

build.ps1

Lines changed: 71 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,129 @@
1-
##########################################################################
2-
# This is the Cake bootstrapper script for PowerShell.
3-
# This file was downloaded from https://github.com/cake-build/resources
4-
# Feel free to change this file to fit your needs.
5-
##########################################################################
6-
71
<#
8-
92
.SYNOPSIS
103
This is a Powershell script to bootstrap a Cake build.
11-
124
.DESCRIPTION
135
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
146
and execute your Cake build script with the parameters you provide.
15-
16-
.PARAMETER Script
17-
The build script to execute.
187
.PARAMETER Target
198
The build script target to run.
209
.PARAMETER Configuration
2110
The build configuration to use.
2211
.PARAMETER Verbosity
2312
Specifies the amount of information to be displayed.
24-
.PARAMETER Experimental
25-
Tells Cake to use the latest Roslyn release.
2613
.PARAMETER WhatIf
2714
Performs a dry run of the build script.
2815
No tasks will be executed.
29-
.PARAMETER Mono
30-
Tells Cake to use the Mono scripting engine.
31-
.PARAMETER SkipToolPackageRestore
32-
Skips restoring of packages.
3316
.PARAMETER ScriptArgs
3417
Remaining arguments are added here.
35-
3618
.LINK
3719
http://cakebuild.net
38-
3920
#>
4021

4122
[CmdletBinding()]
4223
Param(
43-
[string]$Script = "build.cake",
4424
[string]$Target = "Default",
4525
[ValidateSet("Release", "Debug")]
4626
[string]$Configuration = "Release",
4727
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
4828
[string]$Verbosity = "Verbose",
49-
[switch]$Experimental,
50-
[Alias("DryRun","Noop")]
5129
[switch]$WhatIf,
52-
[switch]$Mono,
53-
[switch]$SkipToolPackageRestore,
5430
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
5531
[string[]]$ScriptArgs
5632
)
5733

58-
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
59-
function MD5HashFile([string] $filePath)
34+
$CakeVersion = "0.17.0"
35+
$DotNetChannel = "preview";
36+
$DotNetVersion = "1.0.0-preview2-003121";
37+
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1";
38+
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
39+
40+
# Make sure tools folder exists
41+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
42+
$ToolPath = Join-Path $PSScriptRoot "tools"
43+
if (!(Test-Path $ToolPath)) {
44+
Write-Verbose "Creating tools directory..."
45+
New-Item -Path $ToolPath -Type directory | out-null
46+
}
47+
48+
###########################################################################
49+
# INSTALL .NET CORE CLI
50+
###########################################################################
51+
52+
Function Remove-PathVariable([string]$VariableToRemove)
6053
{
61-
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
54+
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
55+
if ($path -ne $null)
6256
{
63-
return $null
57+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
58+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
6459
}
6560

66-
[System.IO.Stream] $file = $null;
67-
[System.Security.Cryptography.MD5] $md5 = $null;
68-
try
61+
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
62+
if ($path -ne $null)
6963
{
70-
$md5 = [System.Security.Cryptography.MD5]::Create()
71-
$file = [System.IO.File]::OpenRead($filePath)
72-
return [System.BitConverter]::ToString($md5.ComputeHash($file))
64+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
65+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
7366
}
74-
finally
75-
{
76-
if ($file -ne $null)
77-
{
78-
$file.Dispose()
79-
}
80-
}
81-
}
82-
83-
Write-Host "Preparing to run build script..."
84-
85-
if(!$PSScriptRoot){
86-
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
87-
}
88-
89-
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
90-
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
91-
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
92-
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
93-
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
94-
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
95-
96-
# Should we use mono?
97-
$UseMono = "";
98-
if($Mono.IsPresent) {
99-
Write-Verbose -Message "Using the Mono based scripting engine."
100-
$UseMono = "-mono"
10167
}
10268

103-
# Should we use the new Roslyn?
104-
$UseExperimental = "";
105-
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
106-
Write-Verbose -Message "Using experimental version of Roslyn."
107-
$UseExperimental = "-experimental"
69+
# Get .NET Core CLI path if installed.
70+
$FoundDotNetCliVersion = $null;
71+
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
72+
$FoundDotNetCliVersion = dotnet --version;
10873
}
10974

110-
# Is this a dry run?
111-
$UseDryRun = "";
112-
if($WhatIf.IsPresent) {
113-
$UseDryRun = "-dryrun"
114-
}
115-
116-
# Make sure tools folder exists
117-
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
118-
Write-Verbose -Message "Creating tools directory..."
119-
New-Item -Path $TOOLS_DIR -Type directory | out-null
120-
}
121-
122-
# Make sure that packages.config exist.
123-
if (!(Test-Path $PACKAGES_CONFIG)) {
124-
Write-Verbose -Message "Downloading packages.config..."
125-
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
126-
Throw "Could not download packages.config."
75+
if($FoundDotNetCliVersion -ne $DotNetVersion) {
76+
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
77+
if (!(Test-Path $InstallPath)) {
78+
mkdir -Force $InstallPath | Out-Null;
12779
}
128-
}
80+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
81+
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
12982

130-
# Try find NuGet.exe in path if not exists
131-
if (!(Test-Path $NUGET_EXE)) {
132-
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
133-
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
134-
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
135-
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
136-
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
137-
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
138-
}
83+
Remove-PathVariable "$InstallPath"
84+
$env:PATH = "$InstallPath;$env:PATH"
85+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
86+
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
13987
}
14088

141-
# Try download NuGet.exe if not exists
142-
if (!(Test-Path $NUGET_EXE)) {
143-
Write-Verbose -Message "Downloading NuGet.exe..."
144-
try {
145-
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
146-
} catch {
147-
Throw "Could not download NuGet.exe."
148-
}
149-
}
89+
###########################################################################
90+
# INSTALL NUGET
91+
###########################################################################
15092

151-
# Save nuget.exe path to environment to be available to child processed
152-
$ENV:NUGET_EXE = $NUGET_EXE
153-
154-
# Restore tools from NuGet?
155-
if(-Not $SkipToolPackageRestore.IsPresent) {
156-
Push-Location
157-
Set-Location $TOOLS_DIR
158-
159-
# Check for changes in packages.config and remove installed tools if true.
160-
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
161-
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
162-
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
163-
Write-Verbose -Message "Missing or changed package.config hash..."
164-
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
165-
}
93+
# Make sure nuget.exe exists.
94+
$NugetPath = Join-Path $ToolPath "nuget.exe"
95+
if (!(Test-Path $NugetPath)) {
96+
Write-Host "Downloading NuGet.exe..."
97+
(New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
98+
}
16699

167-
Write-Verbose -Message "Restoring tools from NuGet..."
168-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
100+
###########################################################################
101+
# INSTALL CAKE
102+
###########################################################################
169103

104+
# Make sure Cake has been installed.
105+
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe"
106+
if (!(Test-Path $CakePath)) {
107+
Write-Host "Installing Cake..."
108+
Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
170109
if ($LASTEXITCODE -ne 0) {
171-
Throw "An error occured while restoring NuGet tools."
110+
Throw "An error occured while restoring Cake from NuGet."
172111
}
173-
else
174-
{
175-
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
176-
}
177-
Write-Verbose -Message ($NuGetOutput | out-string)
178-
Pop-Location
179112
}
180113

181-
# Make sure that Cake has been installed.
182-
if (!(Test-Path $CAKE_EXE)) {
183-
Throw "Could not find Cake.exe at $CAKE_EXE"
184-
}
114+
###########################################################################
115+
# RUN BUILD SCRIPT
116+
###########################################################################
117+
118+
# Build the argument list.
119+
$Arguments = @{
120+
target=$Target;
121+
configuration=$Configuration;
122+
verbosity=$Verbosity;
123+
dryrun=$WhatIf;
124+
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };
185125

186126
# Start Cake
187127
Write-Host "Running build script..."
188-
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
128+
Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs"
189129
exit $LASTEXITCODE

evergreen/evergreen.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ functions:
215215
working_dir: mongo-csharp-driver
216216
script: |
217217
${PREPARE_SHELL}
218-
AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" TOPOLOGY=${TOPOLOGY} evergreen/run-tests.sh
218+
AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" TOPOLOGY=${TOPOLOGY} OS=${OS} evergreen/run-tests.sh
219219
220220
run-plain-auth-tests:
221221
- command: shell.exec
@@ -375,6 +375,8 @@ axes:
375375
values:
376376
- id: "windows-64"
377377
display_name: "Windows 64-bit"
378+
variables:
379+
OS: "windows-64"
378380
run_on: windows-64-vs2015-small
379381

380382
- id: topology

evergreen/run-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fi
5050

5151
echo "Running $AUTH tests over $SSL for $TOPOLOGY and connecting to $MONGODB_URI"
5252

53-
if [ "$FRAMEWORK" == "netcore10" ]; then
54-
export TARGET="TestNetCore10"
53+
if [ "$OS" == "windows-64" ]; then
54+
export TARGET="TestWindows"
5555
else
56-
export TARGET="TestNet45"
56+
export TARGET="TestLinux"
5757
fi
5858

5959
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do setx $var z:\\data\\tmp; export $var=z:\\data\\tmp; done

0 commit comments

Comments
 (0)