1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

tests/functional/repl: Normalize final prompt

This commit is contained in:
Robert Hensing 2024-07-24 01:01:00 +02:00
parent ca2cc26e12
commit c4ae9bb45b
12 changed files with 13 additions and 24 deletions

View file

@ -262,14 +262,23 @@ badExitCode=0
nixVersion="$(nix eval --impure --raw --expr 'builtins.nixVersion' --extra-experimental-features nix-command)"
# TODO: write a repl interacter for testing. Papering over the differences between readline / editline and between platforms is a pain.
# I couldn't get readline and editline to agree on the newline before the prompt,
# so let's just force it to be one empty line. Ideally we get the two to agree
# or use a simpler interacter for testing.
# so let's just force it to be one empty line.
stripEmptyLinesBeforePrompt() {
# --null-data: treat input as NUL-terminated instead of newline-terminated
sed --null-data 's/\n\n*nix-repl>/\n\nnix-repl>/g'
}
# We don't get a final prompt on darwin, so we strip this as well.
stripFinalPrompt() {
# Strip the final prompt and/or any trailing spaces
sed --null-data \
-e 's/\(.*[^\n]\)\n\n*nix-repl>[ \n]*$/\1/' \
-e 's/[ \n]*$/\n/'
}
runRepl () {
# That is right, we are also filtering out the testdir _without underscores_.
@ -285,7 +294,9 @@ runRepl () {
_NIX_TEST_REPL_ECHO=1 \
nix repl 2>&1 \
| stripColors \
| tr -d '\0' \
| stripEmptyLinesBeforePrompt \
| stripFinalPrompt \
| sed \
-e "s@$testDir@/path/to/tests/functional@g" \
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \