2006-03-01 12:15:33 +00:00
|
|
|
source common.sh
|
|
|
|
|
2015-09-04 20:23:08 +00:00
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
source lang/framework.sh
|
|
|
|
|
|
|
|
# specialize function a bit
|
|
|
|
function diffAndAccept() {
|
|
|
|
local -r testName="$1"
|
|
|
|
local -r got="lang/$testName.$2"
|
|
|
|
local -r expected="lang/$testName.$3"
|
|
|
|
diffAndAcceptInner "$testName" "$got" "$expected"
|
|
|
|
}
|
|
|
|
|
2006-09-24 17:48:41 +00:00
|
|
|
export TEST_VAR=foo # for eval-okay-getenv.nix
|
2020-08-24 16:54:16 +00:00
|
|
|
export NIX_REMOTE=dummy://
|
2022-12-09 17:12:28 +00:00
|
|
|
export NIX_STORE_DIR=/nix/store
|
2006-09-24 17:48:41 +00:00
|
|
|
|
2021-12-09 15:26:46 +00:00
|
|
|
nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>&1 | grepQuiet Hello
|
2023-04-01 20:05:06 +00:00
|
|
|
nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>/dev/null | grepQuiet 123
|
2022-05-02 13:12:50 +00:00
|
|
|
nix-instantiate --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1
|
2021-12-09 15:26:46 +00:00
|
|
|
nix-instantiate --trace-verbose --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grepQuiet Hello
|
|
|
|
nix-instantiate --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grepQuietInverse Hello
|
|
|
|
nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1 | grepQuietInverse Hello
|
|
|
|
expectStderr 1 nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' | grepQuiet Hello
|
2014-02-26 18:12:31 +00:00
|
|
|
|
2023-04-01 20:05:06 +00:00
|
|
|
nix-instantiate --eval -E 'let x = builtins.trace { x = x; } true; in x' \
|
|
|
|
2>&1 | grepQuiet -E 'trace: { x = «potential infinite recursion»; }'
|
|
|
|
|
|
|
|
nix-instantiate --eval -E 'let x = { repeating = x; tracing = builtins.trace x true; }; in x.tracing'\
|
|
|
|
2>&1 | grepQuiet -F 'trace: { repeating = «repeated»; tracing = «potential infinite recursion»; }'
|
|
|
|
|
2014-02-26 18:08:44 +00:00
|
|
|
set +x
|
|
|
|
|
2015-09-04 20:23:08 +00:00
|
|
|
badDiff=0
|
|
|
|
badExitCode=0
|
2004-10-27 12:41:53 +00:00
|
|
|
|
|
|
|
for i in lang/parse-fail-*.nix; do
|
|
|
|
echo "parsing $i (should fail)";
|
2015-09-04 20:23:08 +00:00
|
|
|
i=$(basename "$i" .nix)
|
|
|
|
if expectStderr 1 nix-instantiate --parse - < "lang/$i.nix" > "lang/$i.err"
|
|
|
|
then
|
|
|
|
diffAndAccept "$i" err err.exp
|
|
|
|
else
|
2022-05-02 12:22:00 +00:00
|
|
|
echo "FAIL: $i shouldn't parse"
|
2015-09-04 20:23:08 +00:00
|
|
|
badExitCode=1
|
2022-05-02 12:22:00 +00:00
|
|
|
fi
|
2004-10-27 12:41:53 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for i in lang/parse-okay-*.nix; do
|
|
|
|
echo "parsing $i (should succeed)";
|
2015-09-04 20:23:08 +00:00
|
|
|
i=$(basename "$i" .nix)
|
|
|
|
if
|
|
|
|
expect 0 nix-instantiate --parse - < "lang/$i.nix" \
|
2023-07-13 12:03:42 +00:00
|
|
|
1> "lang/$i.out" \
|
|
|
|
2> "lang/$i.err"
|
2015-09-04 20:23:08 +00:00
|
|
|
then
|
2023-07-13 12:03:42 +00:00
|
|
|
sed "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err"
|
2015-09-04 20:23:08 +00:00
|
|
|
diffAndAccept "$i" out exp
|
|
|
|
diffAndAccept "$i" err err.exp
|
|
|
|
else
|
2022-05-02 12:22:00 +00:00
|
|
|
echo "FAIL: $i should parse"
|
2015-09-04 20:23:08 +00:00
|
|
|
badExitCode=1
|
2022-05-02 12:22:00 +00:00
|
|
|
fi
|
2004-10-27 12:41:53 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for i in lang/eval-fail-*.nix; do
|
|
|
|
echo "evaluating $i (should fail)";
|
2015-09-04 20:23:08 +00:00
|
|
|
i=$(basename "$i" .nix)
|
|
|
|
if
|
2024-03-04 03:42:21 +00:00
|
|
|
expectStderr 1 nix-instantiate --eval --strict --show-trace "lang/$i.nix" \
|
2015-09-04 20:23:08 +00:00
|
|
|
| sed "s!$(pwd)!/pwd!g" > "lang/$i.err"
|
|
|
|
then
|
|
|
|
diffAndAccept "$i" err err.exp
|
|
|
|
else
|
2022-05-02 12:22:00 +00:00
|
|
|
echo "FAIL: $i shouldn't evaluate"
|
2015-09-04 20:23:08 +00:00
|
|
|
badExitCode=1
|
2022-05-02 12:22:00 +00:00
|
|
|
fi
|
2004-10-27 12:41:53 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for i in lang/eval-okay-*.nix; do
|
|
|
|
echo "evaluating $i (should succeed)";
|
2015-09-04 20:23:08 +00:00
|
|
|
i=$(basename "$i" .nix)
|
2006-08-22 09:34:38 +00:00
|
|
|
|
2015-09-04 20:23:08 +00:00
|
|
|
if test -e "lang/$i.exp.xml"; then
|
|
|
|
if expect 0 nix-instantiate --eval --xml --no-location --strict \
|
|
|
|
"lang/$i.nix" > "lang/$i.out.xml"
|
|
|
|
then
|
|
|
|
diffAndAccept "$i" out.xml exp.xml
|
|
|
|
else
|
2022-05-02 12:22:00 +00:00
|
|
|
echo "FAIL: $i should evaluate"
|
2015-09-04 20:23:08 +00:00
|
|
|
badExitCode=1
|
|
|
|
fi
|
|
|
|
elif test ! -e "lang/$i.exp-disabled"; then
|
|
|
|
declare -a flags=()
|
|
|
|
if test -e "lang/$i.flags"; then
|
|
|
|
read -r -a flags < "lang/$i.flags"
|
2006-08-22 09:34:38 +00:00
|
|
|
fi
|
2014-02-26 18:08:44 +00:00
|
|
|
|
2015-09-04 20:23:08 +00:00
|
|
|
if
|
|
|
|
expect 0 env \
|
|
|
|
NIX_PATH=lang/dir3:lang/dir4 \
|
|
|
|
HOME=/fake-home \
|
|
|
|
nix-instantiate "${flags[@]}" --eval --strict "lang/$i.nix" \
|
|
|
|
1> "lang/$i.out" \
|
|
|
|
2> "lang/$i.err"
|
|
|
|
then
|
|
|
|
sed -i "s!$(pwd)!/pwd!g" "lang/$i.out" "lang/$i.err"
|
|
|
|
diffAndAccept "$i" out exp
|
|
|
|
diffAndAccept "$i" err err.exp
|
|
|
|
else
|
2022-05-02 12:22:00 +00:00
|
|
|
echo "FAIL: $i should evaluate"
|
2015-09-04 20:23:08 +00:00
|
|
|
badExitCode=1
|
2006-08-17 11:28:29 +00:00
|
|
|
fi
|
|
|
|
fi
|
2004-10-27 12:41:53 +00:00
|
|
|
done
|
|
|
|
|
2015-09-04 20:23:08 +00:00
|
|
|
if test -n "${_NIX_TEST_ACCEPT-}"; then
|
|
|
|
if (( "$badDiff" )); then
|
|
|
|
echo 'Output did mot match, but accepted output as the persisted expected output.'
|
|
|
|
echo 'That means the next time the tests are run, they should pass.'
|
|
|
|
else
|
|
|
|
echo 'NOTE: Environment variable _NIX_TEST_ACCEPT is defined,'
|
|
|
|
echo 'indicating the unexpected output should be accepted as the expected output going forward,'
|
|
|
|
echo 'but no tests had unexpected output so there was no expected output to update.'
|
|
|
|
fi
|
|
|
|
if (( "$badExitCode" )); then
|
|
|
|
exit "$badExitCode"
|
|
|
|
else
|
|
|
|
skipTest "regenerating golden masters"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if (( "$badDiff" )); then
|
|
|
|
echo ''
|
|
|
|
echo 'You can rerun this test with:'
|
|
|
|
echo ''
|
2023-10-05 16:12:18 +00:00
|
|
|
echo ' _NIX_TEST_ACCEPT=1 make tests/functional/lang.sh.test'
|
2015-09-04 20:23:08 +00:00
|
|
|
echo ''
|
|
|
|
echo 'to regenerate the files containing the expected output,'
|
|
|
|
echo 'and then view the git diff to decide whether a change is'
|
|
|
|
echo 'good/intentional or bad/unintentional.'
|
|
|
|
echo 'If the diff contains arbitrary or impure information,'
|
|
|
|
echo 'please improve the normalization that the test applies to the output.'
|
|
|
|
fi
|
|
|
|
exit $(( "$badExitCode" + "$badDiff" ))
|
|
|
|
fi
|