2019-04-12 18:31:33 +02:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
set +x
|
|
|
|
|
|
|
|
expect_trace() {
|
|
|
|
expr="$1"
|
|
|
|
expect="$2"
|
|
|
|
actual=$(
|
|
|
|
nix-instantiate \
|
|
|
|
--trace-function-calls \
|
|
|
|
--expr "$expr" 2>&1 \
|
|
|
|
| grep "function-trace" \
|
2021-12-09 16:26:46 +01:00
|
|
|
| sed -e 's/ [0-9]*$//' \
|
|
|
|
|| true
|
2022-12-07 12:58:58 +01:00
|
|
|
)
|
2019-04-12 18:31:33 +02:00
|
|
|
|
|
|
|
echo -n "Tracing expression '$expr'"
|
|
|
|
msg=$(diff -swB \
|
|
|
|
<(echo "$expect") \
|
|
|
|
<(echo "$actual")
|
2021-12-09 16:26:46 +01:00
|
|
|
) && result=0 || result=$?
|
2019-04-12 18:31:33 +02:00
|
|
|
if [ $result -eq 0 ]; then
|
|
|
|
echo " ok."
|
|
|
|
else
|
|
|
|
echo " failed. difference:"
|
|
|
|
echo "$msg"
|
|
|
|
return $result
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# failure inside a tryEval
|
|
|
|
expect_trace 'builtins.tryEval (throw "example")' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace entered «string»:1:19 at
|
|
|
|
function-trace exited «string»:1:19 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# Missing argument to a formal function
|
|
|
|
expect_trace '({ x }: x) { }' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# Too many arguments to a formal function
|
|
|
|
expect_trace '({ x }: x) { x = "x"; y = "y"; }' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# Not enough arguments to a lambda
|
|
|
|
expect_trace '(x: y: x + y) 1' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# Too many arguments to a lambda
|
|
|
|
expect_trace '(x: x) 1 2' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# Not a function
|
|
|
|
expect_trace '1 2' "
|
2022-12-13 00:48:04 +01:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 18:31:33 +02:00
|
|
|
"
|