mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Merge pull request #11110 from GoldsteinE/fix-repl-tests
tests/functional/repl.sh: fail test on wrong stdout
This commit is contained in:
commit
03326d606f
1 changed files with 18 additions and 8 deletions
|
@ -74,21 +74,31 @@ testReplResponseGeneral () {
|
||||||
local grepMode commands expectedResponse response
|
local grepMode commands expectedResponse response
|
||||||
grepMode="$1"; shift
|
grepMode="$1"; shift
|
||||||
commands="$1"; shift
|
commands="$1"; shift
|
||||||
expectedResponse="$1"; shift
|
# Expected response can contain newlines.
|
||||||
response="$(nix repl "$@" <<< "$commands" | stripColors)"
|
# grep can't handle multiline patterns, so replace newlines with TEST_NEWLINE
|
||||||
echo "$response" | grepQuiet "$grepMode" -s "$expectedResponse" \
|
# in both expectedResponse and response.
|
||||||
|| fail "repl command set:
|
# awk ORS always adds a trailing record separator, so we strip it with sed.
|
||||||
|
expectedResponse="$(printf '%s' "$1" | awk 1 ORS=TEST_NEWLINE | sed 's/TEST_NEWLINE$//')"; shift
|
||||||
|
# We don't need to strip trailing record separator here, since extra data is ok.
|
||||||
|
response="$(nix repl "$@" <<< "$commands" 2>&1 | stripColors | awk 1 ORS=TEST_NEWLINE)"
|
||||||
|
printf '%s' "$response" | grepQuiet "$grepMode" -s "$expectedResponse" \
|
||||||
|
|| fail "$(echo "repl command set:
|
||||||
|
|
||||||
$commands
|
$commands
|
||||||
|
|
||||||
does not respond with:
|
does not respond with:
|
||||||
|
|
||||||
|
---
|
||||||
$expectedResponse
|
$expectedResponse
|
||||||
|
---
|
||||||
|
|
||||||
but with:
|
but with:
|
||||||
|
|
||||||
|
---
|
||||||
$response
|
$response
|
||||||
"
|
---
|
||||||
|
|
||||||
|
" | sed 's/TEST_NEWLINE/\n/g')"
|
||||||
}
|
}
|
||||||
|
|
||||||
testReplResponse () {
|
testReplResponse () {
|
||||||
|
@ -190,7 +200,7 @@ testReplResponseNoRegex '
|
||||||
let x = { y = { a = 1; }; inherit x; }; in x
|
let x = { y = { a = 1; }; inherit x; }; in x
|
||||||
' \
|
' \
|
||||||
'{
|
'{
|
||||||
x = { ... };
|
x = «repeated»;
|
||||||
y = { ... };
|
y = { ... };
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
@ -242,7 +252,7 @@ testReplResponseNoRegex '
|
||||||
' \
|
' \
|
||||||
'{
|
'{
|
||||||
x = «repeated»;
|
x = «repeated»;
|
||||||
y = { a = 1 };
|
y = { a = 1; };
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -256,7 +266,7 @@ runRepl () {
|
||||||
|
|
||||||
# That is right, we are also filtering out the testdir _without underscores_.
|
# That is right, we are also filtering out the testdir _without underscores_.
|
||||||
# This is crazy, but without it, GHA will fail to run the tests, showing paths
|
# This is crazy, but without it, GHA will fail to run the tests, showing paths
|
||||||
# _with_ underscores in the set -x log, but _without_ underscores in the
|
# _with_ underscores in the set -x log, but _without_ underscores in the
|
||||||
# supposed nix repl output. I have looked in a number of places, but I cannot
|
# supposed nix repl output. I have looked in a number of places, but I cannot
|
||||||
# find a mechanism that could cause this to happen.
|
# find a mechanism that could cause this to happen.
|
||||||
local testDirNoUnderscores
|
local testDirNoUnderscores
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue