tests/functional/lang: Add post processing and remove certain line numbers

This commit is contained in:
Robert Hensing 2024-07-16 17:36:30 +02:00
parent 74698d54c8
commit f9a1d6b018
3 changed files with 37 additions and 13 deletions

View file

@ -50,11 +50,22 @@ set +x
badDiff=0 badDiff=0
badExitCode=0 badExitCode=0
# Extra post-processing that's specific to each test case
postprocess() {
if [[ -e "lang/$1.postprocess" ]]; then
(
set -x;
"lang/$1.postprocess" "lang/$1"
)
fi
}
for i in lang/parse-fail-*.nix; do for i in lang/parse-fail-*.nix; do
echo "parsing $i (should fail)"; echo "parsing $i (should fail)";
i=$(basename "$i" .nix) i=$(basename "$i" .nix)
if expectStderr 1 nix-instantiate --parse - < "lang/$i.nix" > "lang/$i.err" if expectStderr 1 nix-instantiate --parse - < "lang/$i.nix" > "lang/$i.err"
then then
postprocess "$i"
diffAndAccept "$i" err err.exp diffAndAccept "$i" err err.exp
else else
echo "FAIL: $i shouldn't parse" echo "FAIL: $i shouldn't parse"
@ -71,6 +82,7 @@ for i in lang/parse-okay-*.nix; do
2> "lang/$i.err" 2> "lang/$i.err"
then then
sed "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err" sed "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err"
postprocess "$i"
diffAndAccept "$i" out exp diffAndAccept "$i" out exp
diffAndAccept "$i" err err.exp diffAndAccept "$i" err err.exp
else else
@ -94,6 +106,7 @@ for i in lang/eval-fail-*.nix; do
expectStderr 1 nix-instantiate $flags "lang/$i.nix" \ expectStderr 1 nix-instantiate $flags "lang/$i.nix" \
| sed "s!$(pwd)!/pwd!g" > "lang/$i.err" | sed "s!$(pwd)!/pwd!g" > "lang/$i.err"
then then
postprocess "$i"
diffAndAccept "$i" err err.exp diffAndAccept "$i" err err.exp
else else
echo "FAIL: $i shouldn't evaluate" echo "FAIL: $i shouldn't evaluate"
@ -109,6 +122,7 @@ for i in lang/eval-okay-*.nix; do
if expect 0 nix-instantiate --eval --xml --no-location --strict \ if expect 0 nix-instantiate --eval --xml --no-location --strict \
"lang/$i.nix" > "lang/$i.out.xml" "lang/$i.nix" > "lang/$i.out.xml"
then then
postprocess "$i"
diffAndAccept "$i" out.xml exp.xml diffAndAccept "$i" out.xml exp.xml
else else
echo "FAIL: $i should evaluate" echo "FAIL: $i should evaluate"
@ -129,6 +143,7 @@ for i in lang/eval-okay-*.nix; do
2> "lang/$i.err" 2> "lang/$i.err"
then then
sed -i "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err" sed -i "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err"
postprocess "$i"
diffAndAccept "$i" out exp diffAndAccept "$i" out exp
diffAndAccept "$i" err err.exp diffAndAccept "$i" err err.exp
else else

View file

@ -1,26 +1,26 @@
error: error:
… while evaluating the attribute 'outPath' … while evaluating the attribute 'outPath'
at <nix/derivation-internal.nix>:44:9: at <nix/derivation-internal.nix>:<number>:<number>:
43| value = commonAttrs // { <number>| value = commonAttrs // {
44| outPath = builtins.getAttr outputName strict; <number>| outPath = builtins.getAttr outputName strict;
| ^ | ^
45| drvPath = strict.drvPath; <number>| drvPath = strict.drvPath;
… while calling the 'getAttr' builtin … while calling the 'getAttr' builtin
at <nix/derivation-internal.nix>:44:19: at <nix/derivation-internal.nix>:<number>:<number>:
43| value = commonAttrs // { <number>| value = commonAttrs // {
44| outPath = builtins.getAttr outputName strict; <number>| outPath = builtins.getAttr outputName strict;
| ^ | ^
45| drvPath = strict.drvPath; <number>| drvPath = strict.drvPath;
… while calling the 'derivationStrict' builtin … while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:34:12: at <nix/derivation-internal.nix>:<number>:<number>:
33| <number>|
34| strict = derivationStrict drvAttrs; <number>| strict = derivationStrict drvAttrs;
| ^ | ^
35| <number>|
… while evaluating derivation '~jiggle~' … while evaluating derivation '~jiggle~'
whose name attribute is located at /pwd/lang/eval-fail-derivation-name.nix:2:3 whose name attribute is located at /pwd/lang/eval-fail-derivation-name.nix:<number>:<number>
error: invalid derivation name: name '~jiggle~' contains illegal character '~'. Please pass a different 'name'. error: invalid derivation name: name '~jiggle~' contains illegal character '~'. Please pass a different 'name'.

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
testcaseBasename=$1
# Line numbers change when derivation.nix docs are updated.
sed -i "$testcaseBasename.err" \
-e 's/[0-9 ][0-9 ][0-9 ][0-9 ][0-9 ][0-9 ][0-9 ][0-9]\([^0-9]\)/<number>\1/g' \
-e 's/[0-9][0-9]*/<number>/g' \
;