Skip to content

Commit

Permalink
Commonize \r\n / \n handling in test cases. (#1519)
Browse files Browse the repository at this point in the history
* Commonize `r`n / `n handling in test cases.

Extracted from #1514

Rather than each test case inventing their own way of dealing with the Windows/Linux `r`n vs `n difference, this change just always makes the output collection functions to do that transformation.

* Fix damaged -contains pointed out by @ras0219-msft
  • Loading branch information
BillyONeal authored Oct 22, 2024
1 parent 87d3803 commit ffc69f0
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 95 deletions.
8 changes: 4 additions & 4 deletions azure-pipelines/end-to-end-tests-dir/build-test-ports.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ if ($output -notmatch 'Trailing comma') {
# Check for msgAlreadyInstalled vs. msgAlreadyInstalledNotHead
$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3
Throw-IfFailed
if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed') {
throw 'Wrong already installed message'
}
Throw-IfNonContains -Actual $output -Expected @"
The following packages are already installed:
vcpkg-internal-e2e-test-port3:
"@

$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3 --head
Throw-IfFailed
Expand All @@ -64,7 +65,6 @@ if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed
Refresh-TestRoot
$output = Run-VcpkgAndCaptureOutput @commonArgs --x-builtin-ports-root="$PSScriptRoot/../e2e-ports" install vcpkg-bad-spdx-license
Throw-IfFailed
$output = $output.Replace("`r`n", "`n")
$expected = @"
vcpkg.json: warning: $.license (an SPDX license expression): warning: Unknown license identifier 'BSD-new'. Known values are listed at https://spdx.org/licenses/
on expression: BSD-new
Expand Down
13 changes: 3 additions & 10 deletions azure-pipelines/end-to-end-tests-dir/ci-verify-versions.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
. "$PSScriptRoot/../end-to-end-tests-prelude.ps1"

Refresh-TestRoot

Copy-Item -Recurse "$PSScriptRoot/../e2e-assets/ci-verify-versions-registry" "$TestingRoot/ci-verify-versions-registry"
git -C "$TestingRoot/ci-verify-versions-registry" @gitConfigOptions init
git -C "$TestingRoot/ci-verify-versions-registry" @gitConfigOptions add -A
Expand Down Expand Up @@ -160,17 +158,12 @@ Throw-IfNotFailed

function Sanitize() {
Param([string]$text)
$workTreeRegex = 'error: failed to execute:[^\r\n]+' # Git command line has an unpredictable PID inside
$text = $text.Replace('\', '/').Replace("`r`n", "`n").Trim()
$workTreeRegex = 'error: failed to execute:[^\n]+' # Git command line has an unpredictable PID inside
$text = $text.Replace('\', '/').Trim()
$text = [System.Text.RegularExpressions.Regex]::Replace($text, $workTreeRegex, '')
return $text
}

$expected = Sanitize $expected
$actual = Sanitize $actual
if ($actual -ne $expected) {
Set-Content -Value $expected -LiteralPath "$TestingRoot/expected.txt"
Set-Content -Value $actual -LiteralPath "$TestingRoot/actual.txt"
git diff --no-index -- "$TestingRoot/expected.txt" "$TestingRoot/actual.txt"
throw "Bad x-ci-verify-versions output."
}
Throw-IfNonEqual -Expected $expected -Actual $actual
16 changes: 8 additions & 8 deletions azure-pipelines/end-to-end-tests-dir/cli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ error: expected the end of input parsing a package spec; this usually means the
"@

if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw 'Bad malformed port name output; it was: ' + $out
}
Expand All @@ -71,7 +71,7 @@ error: unknown binary provider type: valid providers are 'clear', 'default', 'nu
"@

if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw 'Bad malformed --binarysource output; it was: ' + $out
}
Expand All @@ -86,7 +86,7 @@ error: Invalid triplet name. Triplet names are all lowercase alphanumeric+hyphen
Built-in Triplets:
"@

if (-Not ($out.Replace("`r`n", "`n").StartsWith($expected)))
if (-Not ($out.StartsWith($expected)))
{
throw 'Bad malformed triplet output. It was: ' + $out
}
Expand All @@ -99,7 +99,7 @@ error: expected an explicit triplet
^
"@
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw ('Bad error output: ' + $out)
}
Expand All @@ -112,7 +112,7 @@ error: expected an explicit triplet
^
"@
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw ('Bad error output: ' + $out)
}
Expand All @@ -125,7 +125,7 @@ error: expected the end of input parsing a package spec; did you mean zlib[core]
^
"@
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw ('Bad error output: ' + $out)
}
Expand All @@ -138,7 +138,7 @@ error: List of features is not allowed in this context
^
"@
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw ('Bad error output: ' + $out)
}
Expand All @@ -151,7 +151,7 @@ error: Platform qualifier is not allowed in this context
^
"@
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
if (-Not ($out.EndsWith($expected)))
{
throw ('Bad error output: ' + $out)
}
4 changes: 2 additions & 2 deletions azure-pipelines/end-to-end-tests-dir/env-passthrough.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ if (-not $IsLinux -and -not $IsMacOS) {
$env:_VCPKG_TEST_UNTRACKED = "b"

$x = Run-VcpkgAndCaptureOutput "--overlay-triplets=$PSScriptRoot/../e2e-ports/env-passthrough" env "echo %_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%"
if ($x -ne "%_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%`r`n")
if ($x -ne "%_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%`n")
{
throw "env should have cleaned the environment ($x)"
}

$y = Run-VcpkgAndCaptureOutput "--overlay-triplets=$PSScriptRoot/../e2e-ports/env-passthrough" env --triplet passthrough "echo %_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%"
if ($y -ne "a %_VCPKG_TEST_TRACKED2% b %_VCPKG_TEST_UNTRACKED2%`r`n")
if ($y -ne "a %_VCPKG_TEST_TRACKED2% b %_VCPKG_TEST_UNTRACKED2%`n")
{
throw "env should have kept the environment ($y)"
}
Expand Down
Loading

0 comments on commit ffc69f0

Please sign in to comment.