Skip to content

Commit fd953d1

Browse files
committed
upgrade.ps1: Test without needing a whole git clone
Removes the hack added in microsoft#1477 Tests the condition fixed by microsoft#1473
1 parent 6b07363 commit fd953d1

File tree

2 files changed

+116
-49
lines changed

2 files changed

+116
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,84 @@
11
. "$PSScriptRoot/../end-to-end-tests-prelude.ps1"
22

3-
git clone $VcpkgRoot "$TestingRoot/temp-repo" --local
4-
try
5-
{
6-
$env:VCPKG_ROOT = "$TestingRoot/temp-repo"
7-
git -C "$TestingRoot/temp-repo" switch -d e1934f4a2a0c58bb75099d89ed980832379907fa # vcpkg-cmake @ 2022-12-22
8-
Copy-Item "$VcpkgRoot/scripts/vcpkgTools.xml" "$TestingRoot/temp-repo/scripts/vcpkgTools.xml" -Force
9-
$output = Run-VcpkgAndCaptureOutput install vcpkg-cmake
10-
Throw-IfFailed
11-
if (-Not ($output -match 'vcpkg-cmake:[^ ]+@2022-12-22'))
12-
{
13-
throw 'Unexpected vcpkg-cmake install'
14-
}
15-
16-
git -C "$TestingRoot/temp-repo" checkout -- 'scripts/vcpkgTools.xml'
17-
git -C "$TestingRoot/temp-repo" switch -d f6a5d4e8eb7476b8d7fc12a56dff300c1c986131 # vcpkg-cmake @ 2023-05-04
18-
Copy-Item "$VcpkgRoot/scripts/vcpkgTools.xml" "$TestingRoot/temp-repo/scripts/vcpkgTools.xml" -Force
19-
$output = Run-VcpkgAndCaptureOutput upgrade
20-
Throw-IfNotFailed
21-
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
22-
{
23-
throw "Upgrade didn't handle dry-run correctly"
24-
}
25-
26-
if (-Not ($output -match '\* vcpkg-cmake:[^ ]+@2023-05-04'))
27-
{
28-
throw "Upgrade didn't choose expected version"
29-
}
30-
31-
$output = Run-VcpkgAndCaptureOutput upgrade --no-dry-run
32-
Throw-IfFailed
33-
if (-Not ($output -match '\* vcpkg-cmake:[^ ]+@2023-05-04'))
34-
{
35-
throw "Upgrade didn't choose expected version"
36-
}
37-
38-
if (-Not ($output -match 'vcpkg-cmake:[^:]+: REMOVED:'))
39-
{
40-
throw "Upgrade didn't remove"
41-
}
42-
43-
if (-Not ($output -match 'vcpkg-cmake:[^:]+: SUCCEEDED:'))
44-
{
45-
throw "Upgrade didn't install"
46-
}
47-
}
48-
finally
49-
{
50-
$env:VCPKG_ROOT = $VcpkgRoot
3+
Refresh-TestRoot
4+
5+
$portsRoot = Join-Path $TestingRoot 'ports'
6+
New-Item -ItemType Directory -Force $portsRoot | Out-Null
7+
Set-EmptyTestPort -Name 'upgrade-test-port' -Version '0' -PortsRoot $portsRoot
8+
$output = Run-VcpkgAndCaptureOutput install upgrade-test-port "--x-builtin-ports-root=$portsRoot" @commonArgs
9+
Throw-IfFailed
10+
if (-Not ($output -match 'upgrade-test-port:[^ ]+@0'))
11+
{
12+
throw 'Unexpected upgrade-test-port install'
13+
}
14+
15+
Set-EmptyTestPort -Name 'upgrade-test-port' -Version '1' -PortsRoot $portsRoot
16+
$output = Run-VcpkgAndCaptureOutput upgrade "--x-builtin-ports-root=$portsRoot" @commonArgs
17+
Throw-IfNotFailed
18+
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
19+
{
20+
throw "Upgrade didn't handle dry-run correctly"
21+
}
22+
23+
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@1'))
24+
{
25+
throw "Upgrade didn't choose expected version"
26+
}
27+
28+
$output = Run-VcpkgAndCaptureOutput upgrade --no-dry-run "--x-builtin-ports-root=$portsRoot" @commonArgs
29+
Throw-IfFailed
30+
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@1'))
31+
{
32+
throw "Upgrade didn't choose expected version"
33+
}
34+
35+
if (-Not ($output -match 'upgrade-test-port:[^:]+: REMOVED:'))
36+
{
37+
throw "Upgrade didn't remove"
38+
}
39+
40+
if (-Not ($output -match 'upgrade-test-port:[^:]+: SUCCEEDED:'))
41+
{
42+
throw "Upgrade didn't install"
43+
}
44+
45+
# Also test explicitly providing the name
46+
47+
Set-EmptyTestPort -Name 'upgrade-test-port' -Version '2' -PortsRoot $portsRoot
48+
$output = Run-VcpkgAndCaptureOutput upgrade upgrade-test-port "--x-builtin-ports-root=$portsRoot" @commonArgs
49+
Throw-IfNotFailed
50+
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
51+
{
52+
throw "Upgrade didn't handle dry-run correctly"
53+
}
54+
55+
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@2'))
56+
{
57+
throw "Upgrade didn't choose expected version"
58+
}
59+
60+
$output = Run-VcpkgAndCaptureOutput upgrade upgrade-test-port --no-dry-run "--x-builtin-ports-root=$portsRoot" @commonArgs
61+
Throw-IfFailed
62+
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@2'))
63+
{
64+
throw "Upgrade didn't choose expected version"
65+
}
66+
67+
if (-Not ($output -match 'upgrade-test-port:[^:]+: REMOVED:'))
68+
{
69+
throw "Upgrade didn't remove"
70+
}
71+
72+
if (-Not ($output -match 'upgrade-test-port:[^:]+: SUCCEEDED:'))
73+
{
74+
throw "Upgrade didn't install"
75+
}
76+
77+
# Also test providing a nonexistent name
78+
79+
$output = Run-VcpkgAndCaptureStdErr upgrade nonexistent "--x-builtin-ports-root=$portsRoot" @commonArgs
80+
Throw-IfNotFailed
81+
if ($output -match 'internal error:')
82+
{
83+
throw "Upgrade with a nonexistent name crashed"
5184
}

azure-pipelines/end-to-end-tests-prelude.ps1

+35-1
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,51 @@ function Run-Vcpkg {
168168
Run-VcpkgAndCaptureOutput -ForceExe:$ForceExe @TestArgs | Out-Null
169169
}
170170

171-
172171
# https://github.com/actions/toolkit/blob/main/docs/commands.md#problem-matchers
173172
# .github/workflows/matchers.json
174173
function Remove-Problem-Matchers {
175174
Write-Host "::remove-matcher owner=vcpkg-msvc::"
176175
Write-Host "::remove-matcher owner=vcpkg-gcc::"
177176
Write-Host "::remove-matcher owner=vcpkg-catch::"
178177
}
178+
179179
function Restore-Problem-Matchers {
180180
Write-Host "::add-matcher::.github/workflows/matchers.json"
181181
}
182182

183+
function Set-EmptyTestPort {
184+
Param(
185+
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
186+
[string]$Name,
187+
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
188+
[string]$Version,
189+
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
190+
[string]$PortsRoot,
191+
[switch]$Malformed
192+
)
193+
194+
$portDir = Join-Path $PortsRoot $Name
195+
196+
New-Item -ItemType Directory -Force -Path $portDir | Out-Null
197+
Set-Content -Value "set(VCPKG_POLICY_EMPTY_PACKAGE enabled)" -LiteralPath (Join-Path $portDir 'portfile.cmake') -Encoding Ascii
198+
199+
if ($Malformed) {
200+
# Add bad trailing comma
201+
$json = @"
202+
{
203+
"name": "$Name",
204+
"version": "$Version",
205+
}
206+
"@
207+
} else {
208+
$json = @"
209+
{
210+
"name": "$Name",
211+
"version": "$Version"
212+
}
213+
"@
214+
}
215+
Set-Content -Value $json -LiteralPath (Join-Path $portDir 'vcpkg.json') -Encoding Ascii
216+
}
183217

184218
Refresh-TestRoot

0 commit comments

Comments
 (0)