tests/functional/repl.sh: actually 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.

Change-Id: Ie6561f9f2e18b83d976f162269d20136e2595141
This commit is contained in:
Max “Goldstein” Siling 2024-07-15 22:31:38 +03:00 committed by Qyriad
parent 1eb5d22132
commit 3a36c8bb90

View file

@ -62,21 +62,31 @@ stripColors () {
testReplResponseGeneral () { testReplResponseGeneral () {
local grepMode="$1"; shift local grepMode="$1"; shift
local commands="$1"; shift local commands="$1"; shift
local expectedResponse="$1"; shift # Expected response can contain newlines.
local 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.
local 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.
local 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 () {
@ -179,7 +189,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 = { ... };
} }
' '
@ -231,6 +241,6 @@ testReplResponseNoRegex '
' \ ' \
'{ '{
x = «repeated»; x = «repeated»;
y = { a = 1 }; y = { a = 1; };
} }
' '