Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit dae4723

Browse files
committed
Run tests on PSv2.0. Fix some behaviour that was discovered from test runs. Change temp path to include runtime name.
1 parent f5c2fdf commit dae4723

File tree

4 files changed

+86
-30
lines changed

4 files changed

+86
-30
lines changed

src/dnvm.ps1

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx"
8585
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
8686
Set-Variable -Option Constant "RuntimePackageName" "dnx"
8787
Set-Variable -Option Constant "DefaultFeed" "https://www.nuget.org/api/v2"
88-
Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetrelease/api/v2"
88+
Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
8989
Set-Variable -Option Constant "CrossGenCommand" "dnx-crossgen"
90+
Set-Variable -Option Constant "OldCrossGenCommand" "k-crossgen"
9091
Set-Variable -Option Constant "CommandPrefix" "dnvm-"
9192
Set-Variable -Option Constant "DefaultArchitecture" "x86"
9293
Set-Variable -Option Constant "DefaultRuntime" "clr"
@@ -896,31 +897,26 @@ function dnvm-list {
896897
function dnvm-alias {
897898
param(
898899
[Alias("d")]
899-
[Parameter(ParameterSetName="Delete",Mandatory=$true)]
900900
[switch]$Delete,
901901

902-
[Parameter(ParameterSetName="Read",Mandatory=$false,Position=0)]
903-
[Parameter(ParameterSetName="Write",Mandatory=$true,Position=0)]
904-
[Parameter(ParameterSetName="Delete",Mandatory=$true,Position=0)]
905902
[string]$Name,
906-
907-
[Parameter(ParameterSetName="Write",Mandatory=$true,Position=1)]
903+
908904
[string]$Version,
909905

910906
[Alias("arch")]
911907
[ValidateSet("", "x86","x64")]
912-
[Parameter(ParameterSetName="Write", Mandatory=$false)]
913908
[string]$Architecture = "",
914909

915910
[Alias("r")]
916911
[ValidateSet("", "clr","coreclr")]
917-
[Parameter(ParameterSetName="Write")]
918912
[string]$Runtime = "")
919913

920-
switch($PSCmdlet.ParameterSetName) {
921-
"Read" { Read-Alias $Name }
922-
"Write" { Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime }
923-
"Delete" { Delete-Alias $Name }
914+
if($Version) {
915+
Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime
916+
} elseif ($Delete) {
917+
Delete-Alias $Name
918+
} else {
919+
Read-Alias $Name
924920
}
925921
}
926922

@@ -1124,7 +1120,8 @@ function dnvm-install {
11241120
else {
11251121
$Architecture = GetArch $Architecture
11261122
$Runtime = GetRuntime $Runtime
1127-
$UnpackFolder = Join-Path $RuntimesDir "temp"
1123+
$TempFolder = Join-Path $RuntimesDir "temp"
1124+
$UnpackFolder = Join-Path $TempFolder $runtimeFullName
11281125
$DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg"
11291126

11301127
if(Test-Path $UnpackFolder) {
@@ -1155,7 +1152,19 @@ function dnvm-install {
11551152
else {
11561153
_WriteOut "Installing to $RuntimeFolder"
11571154
_WriteDebug "Moving package contents to $RuntimeFolder"
1158-
Move-Item $UnpackFolder $RuntimeFolder
1155+
try {
1156+
Move-Item $UnpackFolder $RuntimeFolder
1157+
} catch {
1158+
if(Test-Path $RuntimeFolder) {
1159+
#Attempt to cleanup the runtime folder if it is there after a fail.
1160+
Remove-Item $RuntimeFolder -Recurse -Force
1161+
throw
1162+
}
1163+
}
1164+
#If there is nothing left in the temp folder remove it. There could be other installs happening at the same time as this.
1165+
if(-Not(Test-Path $(Join-Path $TempFolder "*"))) {
1166+
Remove-Item $TempFolder -Recurse
1167+
}
11591168
}
11601169

11611170
dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime -Persistent:$Persistent
@@ -1179,11 +1188,18 @@ function dnvm-install {
11791188
else {
11801189
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
11811190
Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
1191+
1192+
if(Get-Command $CrossGenCommand -ErrorAction SilentlyContinue) {
1193+
$crossGenCommand = $CrossGenCommand
1194+
} else {
1195+
$crossGenCommand = $OldCrossGenCommand
1196+
}
1197+
11821198
if ($DebugPreference -eq 'SilentlyContinue') {
1183-
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden
1199+
Start-Process $crossGenCommand -Wait -WindowStyle Hidden
11841200
}
11851201
else {
1186-
Start-Process $CrossGenCommand -Wait -NoNewWindow
1202+
Start-Process $crossGenCommand -Wait -NoNewWindow
11871203
}
11881204
_WriteOut "Finished native image compilation."
11891205
}

test/ps1/Run-Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ $PSBoundParameters.Keys | ForEach-Object {
9191
}
9292

9393
# Launch the script that will actually run the tests in a new shell
94+
& powershell -Version 2 -NoProfile -NoLogo -Command "& `"$PSScriptRoot\_Execute-Tests.ps1`" $childArgs -RunningInNewPowershell"
9495
& powershell -NoProfile -NoLogo -Command "& `"$PSScriptRoot\_Execute-Tests.ps1`" $childArgs -RunningInNewPowershell"
95-
9696
exit $LASTEXITCODE

test/ps1/_Common.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,34 @@ param(
8888
$wc.Proxy = $wp
8989
}
9090
}
91+
92+
function Get-FileHash
93+
{
94+
param ([string] $Path)
95+
96+
if (-not (Test-Path -LiteralPath $Path -PathType Leaf))
97+
{
98+
return $null
99+
}
100+
101+
$item = Get-Item -LiteralPath $Path
102+
if ($item -isnot [System.IO.FileSystemInfo])
103+
{
104+
return $null
105+
}
106+
107+
$stream = $null
108+
109+
try
110+
{
111+
$sha = New-Object System.Security.Cryptography.SHA256CryptoServiceProvider
112+
$stream = $item.OpenRead()
113+
$bytes = $sha.ComputeHash($stream)
114+
return [convert]::ToBase64String($bytes)
115+
}
116+
finally
117+
{
118+
if ($null -ne $stream) { $stream.Close() }
119+
if ($null -ne $sha) { $sha.Clear() }
120+
}
121+
}

test/ps1/_Execute-Tests.ps1

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 3
1+
#Requires -Version 2
22
param(
33
[string]$PesterPath = $null,
44
[string]$PesterRef = "anurse/teamcity",
@@ -23,22 +23,32 @@ if(!$RunningInNewPowershell) {
2323
throw "Don't use this script to run the tests! Use Run-Tests.ps1, it sets up a new powershell instance in which to run the tests!"
2424
}
2525

26-
. "$PSScriptRoot\_Common.ps1"
26+
$scriptDir = $PSScriptRoot
27+
if (!$scriptDir) {
28+
if ($MyInvocation.MyCommand.Path) {
29+
$scriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
30+
}
31+
}
32+
33+
Write-Host "Script Dir: $scriptDir"
34+
35+
. "$scriptDir\_Common.ps1"
2736

2837
# Set defaults
29-
if(!$PesterPath) { $PesterPath = Join-Path $PSScriptRoot ".pester" }
30-
if(!$TestsPath) { $TestsPath = Join-Path $PSScriptRoot "tests" }
31-
if(!$TargetPath) { $TargetPath = Convert-Path (Join-Path $PSScriptRoot "../../src/dnvm.ps1") }
32-
if(!$TestWorkingDir) { $TestWorkingDir = Join-Path $PSScriptRoot "testwork" }
33-
if(!$TestAppsDir) { $TestAppsDir = Convert-Path (Join-Path $PSScriptRoot "../apps") }
38+
if(!$PesterPath) { $PesterPath = Join-Path $scriptDir ".pester" }
39+
if(!$TestsPath) { $TestsPath = Join-Path $scriptDir "tests" }
40+
if(!$TargetPath) { $TargetPath = Convert-Path (Join-Path $scriptDir "../../src/dnvm.ps1") }
41+
if(!$TestWorkingDir) { $TestWorkingDir = Join-Path $scriptDir "testwork" }
42+
if(!$TestAppsDir) { $TestAppsDir = Convert-Path (Join-Path $scriptDir "../apps") }
43+
3444

3545
# Configure the Runtimes we're going to use in testing. The actual runtime doesn't matter since we're only testing
3646
# that dnvm can find it, download it and unpack it successfully. We do run an app in the runtime to do that sanity
3747
# test, but all we care about in these tests is that the app executes.
3848
$env:DNX_FEED = "https://www.myget.org/F/aspnetrelease/api/v2"
3949
$TestRuntimeVersion = "1.0.0-beta4-11566"
4050
$specificNupkgUrl = "$($env:DNX_FEED)/package/dnx-coreclr-win-x64/$TestRuntimeVersion"
41-
$specificNupkgHash = "0081E0E5F98D9DE3BD078932AED162DA8611B4A904137C74F489E1BBC379C6DE"
51+
$specificNupkgHash = "AIHg5fmNneO9B4kyrtFi2oYRtKkEE3x09Inhu8N5xt4="
4252
$specificNupkgName = "dnx-coreclr-win-x64.$TestRuntimeVersion.nupkg"
4353
$specificNuPkgFxName = "Asp.Net,Version=v5.0"
4454

@@ -109,7 +119,7 @@ $specificNupkgPath = Join-Path $downloadDir $specificNupkgName
109119
# If the test package exists
110120
if(Test-Path $specificNupkgPath) {
111121
# Test it against the expected hash
112-
if((Get-FileHash -Algorithm SHA256 $specificNupkgPath).Hash -ne $specificNupkgHash) {
122+
if((Get-FileHash $specificNupkgPath) -ne $specificNupkgHash) {
113123
# Failed to match, kill it with fire!
114124
Write-Host "Test prerequisites are corrupt, redownloading."
115125
rm -for $specificNupkgPath
@@ -123,7 +133,7 @@ if(!(Test-Path $specificNupkgPath)) {
123133
$wc.DownloadFile($specificNupkgUrl, $specificNupkgPath)
124134

125135
# Test it against the expected hash
126-
$actualHash = (Get-FileHash -Algorithm SHA256 $specificNupkgPath).Hash
136+
$actualHash = (Get-FileHash $specificNupkgPath)
127137
if($actualHash -ne $specificNupkgHash) {
128138
# Failed to match, we downloaded a corrupt package??
129139
throw "Test prerequisite $specificNupkgUrl failed to download. The hash '$actualHash' does not match the expected value."
@@ -161,7 +171,7 @@ function TeamCityEscape($str) {
161171

162172
# Generate TeamCity Output
163173
if($TeamCity) {
164-
Write-Host "##teamcity[testSuiteStarted name='$CommandName.ps1']"
174+
Write-Host "##teamcity[testSuiteStarted name='$CommandName.ps1 on PSv$($Host.Version.Major)']"
165175
$result.TestResult | Group-Object Describe | ForEach-Object {
166176
$describe = TeamCityEscape $_.Name
167177
Write-Host "##teamcity[testSuiteStarted name='$describe']"
@@ -196,5 +206,4 @@ if($TeamCity) {
196206
}
197207

198208
# Set the exit code!
199-
200209
$host.SetShouldExit($result.FailedCount)

0 commit comments

Comments
 (0)