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
@@ -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,9 @@
let
a = builtins.trace "before inner break" (
let meow' = 3; in builtins.break { msg = "hello"; }
);
b = builtins.trace "before outer break" (
let meow = 2; in builtins.break a
);
in
b
@@ -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
```