mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 08:12:29 +00:00
tests/functional/repl.sh: fail test on wrong stdout
Previous test implementation assumed that grep supports newlines in patterns. It doesn't, so tests spuriously passed, even though some tests outputs were broken. This patches output (and expected output) before grepping, so there're no newlines in pattern.
This commit is contained in:
parent
c6b5503190
commit
1bec90e3c4
@ -74,21 +74,31 @@ testReplResponseGeneral () {
|
||||
local grepMode commands expectedResponse response
|
||||
grepMode="$1"; shift
|
||||
commands="$1"; shift
|
||||
expectedResponse="$1"; shift
|
||||
response="$(nix repl "$@" <<< "$commands" | stripColors)"
|
||||
echo "$response" | grepQuiet "$grepMode" -s "$expectedResponse" \
|
||||
|| fail "repl command set:
|
||||
# Expected response can contain newlines.
|
||||
# grep can't handle multiline patterns, so replace newlines with TEST_NEWLINE
|
||||
# in both expectedResponse and response.
|
||||
# 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
|
||||
|
||||
does not respond with:
|
||||
|
||||
---
|
||||
$expectedResponse
|
||||
---
|
||||
|
||||
but with:
|
||||
|
||||
---
|
||||
$response
|
||||
"
|
||||
---
|
||||
|
||||
" | sed 's/TEST_NEWLINE/\n/g')"
|
||||
}
|
||||
|
||||
testReplResponse () {
|
||||
@ -190,7 +200,7 @@ testReplResponseNoRegex '
|
||||
let x = { y = { a = 1; }; inherit x; }; in x
|
||||
' \
|
||||
'{
|
||||
x = { ... };
|
||||
x = «repeated»;
|
||||
y = { ... };
|
||||
}
|
||||
'
|
||||
@ -242,7 +252,7 @@ testReplResponseNoRegex '
|
||||
' \
|
||||
'{
|
||||
x = «repeated»;
|
||||
y = { a = 1 };
|
||||
y = { a = 1; };
|
||||
}
|
||||
'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user