tests(f2/repl): migrate stacktrace tests

Change-Id: Ic6795f22d68aea113fa2037cbd0a731ac5e698f8
This commit is contained in:
rootile
2026-06-11 16:30:56 +02:00
parent da9f0c494e
commit 64b434b87b
10 changed files with 575 additions and 360 deletions
@@ -1,108 +0,0 @@
@args --debugger
trace: before outer break
info: breakpoint reached
Here we are in the outer break and the let of "meow". st should show meow there
as it is in scope.
nix-repl> :st
0: error: breakpoint reached
$TEST_DATA/stack_vars.nix:6:22
5| b = builtins.trace "before outer break" (
6| let meow = 2; in builtins.break a
| ^
7| );
Env level 0
static: meow
Env level 1
static: a b
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> meow
2
If we :st past the frame in the backtrace with the meow in it, the meow should not be there.
nix-repl> :st 3
3: while calling a function
$TEST_DATA/stack_vars.nix:5:7
4| );
5| b = builtins.trace "before outer break" (
| ^
6| let meow = 2; in builtins.break a
Env level 0
static: a b
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> :c
trace: before inner break
info: breakpoint reached
nix-repl> :st
0: error: breakpoint reached
$TEST_DATA/stack_vars.nix:3:23
2| a = builtins.trace "before inner break" (
3| let meow' = 3; in builtins.break { msg = "hello"; }
| ^
4| );
Env level 0
static: meow'
Env level 1
static: a b
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> meow'
3
nix-repl> :st 3
3: while calling a function
$TEST_DATA/stack_vars.nix:2:7
1| let
2| a = builtins.trace "before inner break" (
| ^
3| let meow' = 3; in builtins.break { msg = "hello"; }
Env level 0
static: a b
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> :quit
error:
… while evaluating the file '$TEST_DATA/stack_vars.nix':
… while evaluating b
at $TEST_DATA/stack_vars.nix:9:3:
8| in
9| b
| ^
10|
… while calling the 'trace' builtin
at $TEST_DATA/stack_vars.nix:5:7:
4| );
5| b = builtins.trace "before outer break" (
| ^
6| let meow = 2; in builtins.break a
(stack trace truncated; use '--show-trace' to show the full trace)
error: breakpoint reached
@@ -1,73 +0,0 @@
@args --debugger
nix-repl> throw "(forever?????????)"
error: (forever?????????)
argument-less :st works fine
nix-repl> :st
0: error: (forever?????????)
«string»:1:1
1| throw "(forever?????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
a non-numeric strings produces an error
nix-repl> :st chat
error: argument 'chat' is not a valid integer
nix-repl> :st bedroom community
error: argument 'bedroom community' is not a valid integer
...even when they start with a digit
nix-repl> :st 6up
error: argument '6up' is not a valid integer
...or when they're floats
nix-repl> :st 4.50
error: argument '4.50' is not a valid integer
an integer outside the range produces an error
nix-repl> :st 23571113171923
error: argument '23571113171923' is not a valid integer
argument-less :st is still at the same index after errors
nix-repl> :st 1
1: while calling a function
«string»:1:1
1| throw "(forever?????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> :st foo
error: argument 'foo' is not a valid integer
nix-repl> :st
1: while calling a function
«string»:1:1
1| throw "(forever?????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
quit
nix-repl> :quit
error: (forever?????????)
@@ -1,110 +0,0 @@
@args --debugger
nix-repl> let f = _: throw "x_x"; x = f 5; in x
error: x_x
frames from 0 up to 4 work fine
nix-repl> :st 0
0: error: x_x
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
nix-repl> :st 4
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
absolute frames out of bounds print an error
nix-repl> :st 5
error: stack index must be between 0 and 4 (inclusive), but was 5
argument-less :st is still at the same after absolute oob
nix-repl> :st
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
positive relative frames oob clamp to upper bound and print a warning
nix-repl> :st +5
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
warning: stopped at stack frame 4, cannot go any higher
negative relative frames oob clamp to lower bound and print a warning
nix-repl> :st -5
0: error: x_x
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
warning: stopped at stack frame 0, cannot go any deeper
quit
nix-repl> :quit
error: x_x
@@ -1,64 +0,0 @@
@args --debugger
nix-repl> let f = _: throw "x_x"; x = f 5; in x
error: x_x
absolute indices still work:
nix-repl> :st 1
1: while calling a function
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
index with + goes up the stack relative to current (1 in this case):
nix-repl> :st +3
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
index with - goes down and is also relative to current (4):
nix-repl> :st -1
3: while calling a function
«string»:1:29
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
quit
nix-repl> :quit
error: x_x
@@ -176,9 +176,4 @@ TEST_F(ReplSessionTest, tidy)
runReplTestPath(#name); \
}
REPL_TEST(stack_vars);
REPL_TEST(stacktrace_invalid_arg);
REPL_TEST(stacktrace_oob);
REPL_TEST(stacktrace_relative);
}; // namespace nix
@@ -0,0 +1,127 @@
---
args: ['--debugger']
---
```nix
throw "(forever????????)"
```
```output
error: (forever????????)
```
argument-less :st works fine
```nix
:st
```
```output
0: error: (forever????????)
«string»:1:1
1| throw "(forever????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
```
a non-numeric string produces an error
```nix
:st chat
:st bedroom community
```
```output
error: argument 'chat' is not a valid integer
error: argument 'bedroom community' is not a valid integer
```
even when they start with a digit
```nix
:st 6up
```
```output
error: argument '6up' is not a valid integer
```
or when they're floats
```nix
:st 4.50
```
```output
error: argument '4.50' is not a valid integer
```
an integer outside of the range produces an error
```nix
:st 23571113171923
```
```output
error: argument '23571113171923' is not a valid integer
```
argument-less `:st` is still at the same index after errors
```nix
:st 1
:st foo
:st
```
```output
1: while calling a function
«string»:1:1
1| throw "(forever????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
error: argument 'foo' is not a valid integer
1: while calling a function
«string»:1:1
1| throw "(forever????????)"
| ^
Env level 0
static:
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
```
quit
```nix
:quit
```
```output
error: (forever????????)
```
@@ -0,0 +1,165 @@
---
args: ['--debugger']
---
```nix
let f = _: throw "x_x"; x = f 5; in x
```
```output
error: x_x
Added 3 variables.
```
frames from 0 up to 4 work fine
```nix
:st 0
:st 4
```
```output
0: error: x_x
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 3 variables.
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
```
absolute frames out of bounds print an error
```nix
:st 5
```
```output
error: stack index must be between 0 and 4 (inclusive), but was 5
```
argument-less `:st` is still the same afer absolute oob
```nix
:st
```
```output
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
```
positive relative frames oob clamp to upper bound and prints a warning
```nix
:st +5
```
```output
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
warning: stopped at stack frame 4, cannot go any higher
```
negative relative frames oob clamp to lower bound and print a warning
```nix
:st -5
```
```output
0: error: x_x
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 3 variables.
warning: stopped at stack frame 0, cannot go any deeper
```
quit
```nix
:quit
```
```output
error: x_x
```
@@ -0,0 +1,105 @@
---
args: ['--debugger']
---
```nix
let f = _: throw "x_x"; x = f 5; in x
```
```output
error: x_x
Added 3 variables.
```
absolute indices still work:
```nix
:st 1
```
```output
1: while calling a function
«string»:1:12
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: _
Env level 1
static: f x
Env level 2
static:
Env level 3
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 3 variables.
```
index with + goes up the stack relative to current (1 in this case):
```nix
:st +3
```
```output
4: while evaluating a 'let' expression
«string»:1:1
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
```
index with - goes down and is also relative to current(4):
```nix
:st -1
```
```output
3: while calling a function
«string»:1:29
1| let f = _: throw "x_x"; x = f 5; in x
| ^
Env level 0
static: f x
Env level 1
static:
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
```
quit
```nix
:quit
```
```output
error: x_x
```
@@ -0,0 +1,178 @@
---
args: ['--debugger', '-f', '{PWD}/stack_vars.nix']
should_fail: True
files: ['stack_vars.nix']
---
```output
Lix VERSION
Type :? for help.
trace: before outer break
info: breakpoint reached
Added 3 variables.
```
Here we are in the outer break and the let of "meow". `:st` should show meow there
```nix
:st
```
```output
0: error: breakpoint reached
/pwd/stack_vars.nix:6:22
5| b = builtins.trace "before outer break" (
6| let meow = 2; in builtins.break a
| ^
7| );
Env level 0
static: meow
Env level 1
static: a b
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 3 variables.
```
```nix
meow
```
```output
2
```
If we `:st` past the frame in the backtrace with the `meow` in it, the `meow` should not be there
```nix
:st 3
:c
```
```output
3: while calling a function
/pwd/stack_vars.nix:5:7
4| );
5| b = builtins.trace "before outer break" (
| ^
6| let meow = 2; in builtins.break a
Env level 0
static: a b
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
trace: before inner break
info: breakpoint reached
Added 3 variables.
```
```nix
:st
```
```output
0: error: breakpoint reached
/pwd/stack_vars.nix:3:23
2| a = builtins.trace "before inner break" (
3| let meow' = 3; in builtins.break { msg = "hello"; }
| ^
4| );
Env level 0
static: meow'
Env level 1
static: a b
Env level 2
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 3 variables.
```
```nix
meow'
:st 3
```
```output
3
3: while calling a function
/pwd/stack_vars.nix:2:7
1| let
2| a = builtins.trace "before inner break" (
| ^
3| let meow' = 3; in builtins.break { msg = "hello"; }
Env level 0
static: a b
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Added 2 variables.
```
```nix
:quit
```
```output
error:
… while evaluating the file '/pwd/stack_vars.nix':
… while evaluating b
at /pwd/stack_vars.nix:9:3:
8| in
9| b
| ^
10|
… while calling the 'trace' builtin
at /pwd/stack_vars.nix:5:7:
4| );
5| b = builtins.trace "before outer break" (
| ^
6| let meow = 2; in builtins.break a
… while calling the 'break' builtin
at /pwd/stack_vars.nix:6:22:
5| b = builtins.trace "before outer break" (
6| let meow = 2; in builtins.break a
| ^
7| );
… while calling the 'trace' builtin
at /pwd/stack_vars.nix:2:7:
1| let
2| a = builtins.trace "before inner break" (
| ^
3| let meow' = 3; in builtins.break { msg = "hello"; }
… while calling the 'break' builtin
at /pwd/stack_vars.nix:3:23:
2| a = builtins.trace "before inner break" (
3| let meow' = 3; in builtins.break { msg = "hello"; }
| ^
4| );
error: breakpoint reached
```