2024-05-28 16:43:04 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-04-12 16:31:33 +00: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 15:26:46 +00:00
|
|
|
| sed -e 's/ [0-9]*$//' \
|
|
|
|
|| true
|
2022-12-07 11:58:58 +00:00
|
|
|
)
|
2019-04-12 16:31:33 +00:00
|
|
|
|
|
|
|
echo -n "Tracing expression '$expr'"
|
|
|
|
msg=$(diff -swB \
|
|
|
|
<(echo "$expect") \
|
|
|
|
<(echo "$actual")
|
2021-12-09 15:26:46 +00:00
|
|
|
) && result=0 || result=$?
|
2024-06-04 20:33:32 +00:00
|
|
|
if [ "$result" -eq 0 ]; then
|
2019-04-12 16:31:33 +00:00
|
|
|
echo " ok."
|
|
|
|
else
|
|
|
|
echo " failed. difference:"
|
|
|
|
echo "$msg"
|
2024-06-04 20:33:32 +00:00
|
|
|
return "$result"
|
2019-04-12 16:31:33 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# failure inside a tryEval
|
|
|
|
expect_trace 'builtins.tryEval (throw "example")' "
|
2022-12-12 23:48:04 +00: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 16:31:33 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
# Missing argument to a formal function
|
|
|
|
expect_trace '({ x }: x) { }' "
|
2022-12-12 23:48:04 +00:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 16:31:33 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
# Too many arguments to a formal function
|
|
|
|
expect_trace '({ x }: x) { x = "x"; y = "y"; }' "
|
2022-12-12 23:48:04 +00:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 16:31:33 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
# Not enough arguments to a lambda
|
|
|
|
expect_trace '(x: y: x + y) 1' "
|
2022-12-12 23:48:04 +00:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 16:31:33 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
# Too many arguments to a lambda
|
|
|
|
expect_trace '(x: x) 1 2' "
|
2022-12-12 23:48:04 +00:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 16:31:33 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
# Not a function
|
|
|
|
expect_trace '1 2' "
|
2022-12-12 23:48:04 +00:00
|
|
|
function-trace entered «string»:1:1 at
|
|
|
|
function-trace exited «string»:1:1 at
|
2019-04-12 16:31:33 +00:00
|
|
|
"
|