Skip to content

Commit 48cc0c7

Browse files
committed
Commonize rn / `n handling in test cases.
Extracted from microsoft#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.
1 parent ad7b71c commit 48cc0c7

File tree

8 files changed

+138
-94
lines changed

8 files changed

+138
-94
lines changed

azure-pipelines/end-to-end-tests-dir/build-test-ports.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,25 @@ if ($output -notmatch 'Trailing comma') {
5151
# Check for msgAlreadyInstalled vs. msgAlreadyInstalledNotHead
5252
$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3
5353
Throw-IfFailed
54-
if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed') {
54+
if (-not $output -contains @"
55+
The following packages are already installed:
56+
vcpkg-internal-e2e-test-port3:
57+
"@) {
5558
throw 'Wrong already installed message'
5659
}
5760

5861
$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3 --head
5962
Throw-IfFailed
60-
if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed -- not building from HEAD') {
63+
if (-not $output -contains @"
64+
The following packages are already installed, but were requested at --head version. Their installed contents will not be changed. To get updated versions, remove these packages first:
65+
vcpkg-internal-e2e-test-port3:
66+
"@) {
6167
throw 'Wrong already installed message for --head'
6268
}
6369

6470
Refresh-TestRoot
6571
$output = Run-VcpkgAndCaptureOutput @commonArgs --x-builtin-ports-root="$PSScriptRoot/../e2e-ports" install vcpkg-bad-spdx-license
6672
Throw-IfFailed
67-
$output = $output.Replace("`r`n", "`n")
6873
$expected = @"
6974
vcpkg.json: warning: $.license (an SPDX license expression): warning: Unknown license identifier 'BSD-new'. Known values are listed at https://spdx.org/licenses/
7075
on expression: BSD-new

azure-pipelines/end-to-end-tests-dir/ci-verify-versions.ps1

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
. "$PSScriptRoot/../end-to-end-tests-prelude.ps1"
22

3-
Refresh-TestRoot
4-
53
Copy-Item -Recurse "$PSScriptRoot/../e2e-assets/ci-verify-versions-registry" "$TestingRoot/ci-verify-versions-registry"
64
git -C "$TestingRoot/ci-verify-versions-registry" @gitConfigOptions init
75
git -C "$TestingRoot/ci-verify-versions-registry" @gitConfigOptions add -A
@@ -160,17 +158,12 @@ Throw-IfNotFailed
160158

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

169167
$expected = Sanitize $expected
170168
$actual = Sanitize $actual
171-
if ($actual -ne $expected) {
172-
Set-Content -Value $expected -LiteralPath "$TestingRoot/expected.txt"
173-
Set-Content -Value $actual -LiteralPath "$TestingRoot/actual.txt"
174-
git diff --no-index -- "$TestingRoot/expected.txt" "$TestingRoot/actual.txt"
175-
throw "Bad x-ci-verify-versions output."
176-
}
169+
Throw-IfNonEqual -Expected $expected -Actual $actual

azure-pipelines/end-to-end-tests-dir/cli.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ error: expected the end of input parsing a package spec; this usually means the
5656
5757
"@
5858

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

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

89-
if (-Not ($out.Replace("`r`n", "`n").StartsWith($expected)))
89+
if (-Not ($out.StartsWith($expected)))
9090
{
9191
throw 'Bad malformed triplet output. It was: ' + $out
9292
}
@@ -99,7 +99,7 @@ error: expected an explicit triplet
9999
^
100100
101101
"@
102-
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
102+
if (-Not ($out.EndsWith($expected)))
103103
{
104104
throw ('Bad error output: ' + $out)
105105
}
@@ -112,7 +112,7 @@ error: expected an explicit triplet
112112
^
113113
114114
"@
115-
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
115+
if (-Not ($out.EndsWith($expected)))
116116
{
117117
throw ('Bad error output: ' + $out)
118118
}
@@ -125,7 +125,7 @@ error: expected the end of input parsing a package spec; did you mean zlib[core]
125125
^
126126
127127
"@
128-
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
128+
if (-Not ($out.EndsWith($expected)))
129129
{
130130
throw ('Bad error output: ' + $out)
131131
}
@@ -138,7 +138,7 @@ error: List of features is not allowed in this context
138138
^
139139
140140
"@
141-
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
141+
if (-Not ($out.EndsWith($expected)))
142142
{
143143
throw ('Bad error output: ' + $out)
144144
}
@@ -151,7 +151,7 @@ error: Platform qualifier is not allowed in this context
151151
^
152152
153153
"@
154-
if (-Not ($out.Replace("`r`n", "`n").EndsWith($expected)))
154+
if (-Not ($out.EndsWith($expected)))
155155
{
156156
throw ('Bad error output: ' + $out)
157157
}

azure-pipelines/end-to-end-tests-dir/env-passthrough.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ if (-not $IsLinux -and -not $IsMacOS) {
55
$env:_VCPKG_TEST_UNTRACKED = "b"
66

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

1313
$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%"
14-
if ($y -ne "a %_VCPKG_TEST_TRACKED2% b %_VCPKG_TEST_UNTRACKED2%`r`n")
14+
if ($y -ne "a %_VCPKG_TEST_TRACKED2% b %_VCPKG_TEST_UNTRACKED2%`n")
1515
{
1616
throw "env should have kept the environment ($y)"
1717
}

0 commit comments

Comments
 (0)