Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade.ps1: Test without needing a whole git clone #1494

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 81 additions & 48 deletions azure-pipelines/end-to-end-tests-dir/upgrade.ps1
Original file line number Diff line number Diff line change
@@ -1,51 +1,84 @@
. "$PSScriptRoot/../end-to-end-tests-prelude.ps1"

git clone $VcpkgRoot "$TestingRoot/temp-repo" --local
try
{
$env:VCPKG_ROOT = "$TestingRoot/temp-repo"
git -C "$TestingRoot/temp-repo" switch -d e1934f4a2a0c58bb75099d89ed980832379907fa # vcpkg-cmake @ 2022-12-22
Copy-Item "$VcpkgRoot/scripts/vcpkgTools.xml" "$TestingRoot/temp-repo/scripts/vcpkgTools.xml" -Force
$output = Run-VcpkgAndCaptureOutput install vcpkg-cmake
Throw-IfFailed
if (-Not ($output -match 'vcpkg-cmake:[^ ]+@2022-12-22'))
{
throw 'Unexpected vcpkg-cmake install'
}

git -C "$TestingRoot/temp-repo" checkout -- 'scripts/vcpkgTools.xml'
git -C "$TestingRoot/temp-repo" switch -d f6a5d4e8eb7476b8d7fc12a56dff300c1c986131 # vcpkg-cmake @ 2023-05-04
Copy-Item "$VcpkgRoot/scripts/vcpkgTools.xml" "$TestingRoot/temp-repo/scripts/vcpkgTools.xml" -Force
$output = Run-VcpkgAndCaptureOutput upgrade
Throw-IfNotFailed
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
{
throw "Upgrade didn't handle dry-run correctly"
}

if (-Not ($output -match '\* vcpkg-cmake:[^ ]+@2023-05-04'))
{
throw "Upgrade didn't choose expected version"
}

$output = Run-VcpkgAndCaptureOutput upgrade --no-dry-run
Throw-IfFailed
if (-Not ($output -match '\* vcpkg-cmake:[^ ]+@2023-05-04'))
{
throw "Upgrade didn't choose expected version"
}

if (-Not ($output -match 'vcpkg-cmake:[^:]+: REMOVED:'))
{
throw "Upgrade didn't remove"
}

if (-Not ($output -match 'vcpkg-cmake:[^:]+: SUCCEEDED:'))
{
throw "Upgrade didn't install"
}
}
finally
{
$env:VCPKG_ROOT = $VcpkgRoot
Refresh-TestRoot

$portsRoot = Join-Path $TestingRoot 'ports'
New-Item -ItemType Directory -Force $portsRoot | Out-Null
Set-EmptyTestPort -Name 'upgrade-test-port' -Version '0' -PortsRoot $portsRoot
$output = Run-VcpkgAndCaptureOutput install upgrade-test-port "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfFailed
if (-Not ($output -match 'upgrade-test-port:[^ ]+@0'))
{
throw 'Unexpected upgrade-test-port install'
}

Set-EmptyTestPort -Name 'upgrade-test-port' -Version '1' -PortsRoot $portsRoot
$output = Run-VcpkgAndCaptureOutput upgrade "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfNotFailed
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
{
throw "Upgrade didn't handle dry-run correctly"
}

if (-Not ($output -match '\* upgrade-test-port:[^ ]+@1'))
{
throw "Upgrade didn't choose expected version"
}

$output = Run-VcpkgAndCaptureOutput upgrade --no-dry-run "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfFailed
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@1'))
{
throw "Upgrade didn't choose expected version"
}

if (-Not ($output -match 'upgrade-test-port:[^:]+: REMOVED:'))
{
throw "Upgrade didn't remove"
}

if (-Not ($output -match 'upgrade-test-port:[^:]+: SUCCEEDED:'))
{
throw "Upgrade didn't install"
}

# Also test explicitly providing the name

Set-EmptyTestPort -Name 'upgrade-test-port' -Version '2' -PortsRoot $portsRoot
$output = Run-VcpkgAndCaptureOutput upgrade upgrade-test-port "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfNotFailed
if (-Not ($output -match 'If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.'))
{
throw "Upgrade didn't handle dry-run correctly"
}

if (-Not ($output -match '\* upgrade-test-port:[^ ]+@2'))
{
throw "Upgrade didn't choose expected version"
}

$output = Run-VcpkgAndCaptureOutput upgrade upgrade-test-port --no-dry-run "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfFailed
if (-Not ($output -match '\* upgrade-test-port:[^ ]+@2'))
{
throw "Upgrade didn't choose expected version"
}

if (-Not ($output -match 'upgrade-test-port:[^:]+: REMOVED:'))
{
throw "Upgrade didn't remove"
}

if (-Not ($output -match 'upgrade-test-port:[^:]+: SUCCEEDED:'))
{
throw "Upgrade didn't install"
}

# Also test providing a nonexistent name

$output = Run-VcpkgAndCaptureStdErr upgrade nonexistent "--x-builtin-ports-root=$portsRoot" @commonArgs
Throw-IfNotFailed
if ($output -match 'internal error:')
{
throw "Upgrade with a nonexistent name crashed"
}
36 changes: 35 additions & 1 deletion azure-pipelines/end-to-end-tests-prelude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,51 @@ function Run-Vcpkg {
Run-VcpkgAndCaptureOutput -ForceExe:$ForceExe @TestArgs | Out-Null
}


# https://github.com/actions/toolkit/blob/main/docs/commands.md#problem-matchers
# .github/workflows/matchers.json
function Remove-Problem-Matchers {
Write-Host "::remove-matcher owner=vcpkg-msvc::"
Write-Host "::remove-matcher owner=vcpkg-gcc::"
Write-Host "::remove-matcher owner=vcpkg-catch::"
}

function Restore-Problem-Matchers {
Write-Host "::add-matcher::.github/workflows/matchers.json"
}

function Set-EmptyTestPort {
Param(
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
[string]$Name,
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
[string]$Version,
[Parameter(Mandatory)][ValidateNotNullOrWhitespace()]
[string]$PortsRoot,
[switch]$Malformed
)

$portDir = Join-Path $PortsRoot $Name

New-Item -ItemType Directory -Force -Path $portDir | Out-Null
Set-Content -Value "set(VCPKG_POLICY_EMPTY_PACKAGE enabled)" -LiteralPath (Join-Path $portDir 'portfile.cmake') -Encoding Ascii

if ($Malformed) {
# Add bad trailing comma
$json = @"
{
"name": "$Name",
"version": "$Version",
}
"@
} else {
$json = @"
{
"name": "$Name",
"version": "$Version"
}
"@
}
Set-Content -Value $json -LiteralPath (Join-Path $portDir 'vcpkg.json') -Encoding Ascii
}

Refresh-TestRoot
Loading