aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGoldstein <root@goldstein.rs>2024-07-15 22:31:38 +0300
committerQyriad <qyriad@qyriad.me>2024-07-17 21:48:13 +0000
commit3a36c8bb9004a259bb29e8b86d3217002b9a53ea (patch)
treeefb020586bdc4ad8fcee8beab185d870344bf9c6 /tests
parent1eb5d22132a57487e0cb84a65ecd35814624c0e5 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/repl.sh24
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh
index 3765fb492..cd56b4d92 100644
--- a/tests/functional/repl.sh
+++ b/tests/functional/repl.sh
@@ -62,21 +62,31 @@ stripColors () {
testReplResponseGeneral () {
local grepMode="$1"; shift
local commands="$1"; shift
- local expectedResponse="$1"; shift
- local 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.
+ 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
does not respond with:
+---
$expectedResponse
+---
but with:
+---
$response
-"
+---
+
+" | sed 's/TEST_NEWLINE/\n/g')"
}
testReplResponse () {
@@ -179,7 +189,7 @@ testReplResponseNoRegex '
let x = { y = { a = 1; }; inherit x; }; in x
' \
'{
- x = { ... };
+ x = «repeated»;
y = { ... };
}
'
@@ -231,6 +241,6 @@ testReplResponseNoRegex '
' \
'{
x = «repeated»;
- y = { a = 1 };
+ y = { a = 1; };
}
'