gap> #############################################################################
gap> ##
gap> ##
gap> ##  This file tests the combination of Where and DownEnv/UpEnv, and also the
gap> ##  initial backtrace (for which Where is executed in a slightly different
gap> ##  execution context compared to the later Where invocations from the break
gap> ##  prompt)
gap> ##
gap> ##  We test with three slightly different ways to trigger an error, as they
gap> ##  exhibit slight differences in how they interact with the error handling
gap> ##  code.
gap> ##
gap> ##  We also test what happens when UpEnv/DownEnv are asked to go beyond the
gap> ##  first/last execution context.
gap> ##
gap> 
gap> #############################################################################
gap> ##
gap> ##  trigger error using Error()
gap> ##
gap> test:= function( n )
>   if n > 2 then
>     Error( "!\n" );
>   fi;
>   test( n+1 );
> end;;
gap> test( 1 );
Error, !
Stack trace:
*[1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *stdin*:28
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk> n; Where();
3
*[1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:1
brk> DownEnv(); n; Where();
2
 [1] Error( "!\n" );
   @ *stdin*:24
*[2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:2
brk> DownEnv(); n; Where();
1
 [1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
*[3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:3
brk> DownEnv(); n; Where();
1
 [1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
*[3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:4
brk> UpEnv(); n; Where();
2
 [1] Error( "!\n" );
   @ *stdin*:24
*[2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:5
brk> UpEnv(); n; Where();
3
*[1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:6
brk> UpEnv(); n; Where();
3
*[1] Error( "!\n" );
   @ *stdin*:24
 [2] test( n + 1 );
   @ *stdin*:26
 [3] test( n + 1 );
   @ *stdin*:26
<function "test">( <arguments> )
 called from read-eval loop at *errin*:7
brk> quit;
gap> 
gap> #############################################################################
gap> ##
gap> ##  trigger error in the kernel
gap> ##
gap> test:= function( n )
>   if n > 2 then
>     return 1/0;
>   fi;
>   test( n+1 );
> end;;
gap> test( 1 );
Error, Rational operations: <divisor> must not be zero
Stack trace:
*[1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *stdin*:39
type 'quit;' to quit to outer loop
brk> n; Where();
3
*[1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:1
brk> DownEnv(); n; Where();
2
 [1] 1 / 0
   @ *stdin*:35
*[2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:2
brk> DownEnv(); n; Where();
1
 [1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
*[3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:3
brk> DownEnv(); n; Where();
1
 [1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
*[3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:4
brk> UpEnv(); n; Where();
2
 [1] 1 / 0
   @ *stdin*:35
*[2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:5
brk> UpEnv(); n; Where();
3
*[1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:6
brk> UpEnv(); n; Where();
3
*[1] 1 / 0
   @ *stdin*:35
 [2] test( n + 1 );
   @ *stdin*:37
 [3] test( n + 1 );
   @ *stdin*:37
<function "test">( <arguments> )
 called from read-eval loop at *errin*:7
brk> quit;
gap> 
gap> 
gap> #############################################################################
gap> ##
gap> ## trigger method not found error
gap> ##
gap> test:= function( n )
>   if n > 2 then
>     return IsAbelian(1);
>   fi;
>   test( n+1 );
> end;;
gap> test( 1 );
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `IsCommutative' on 1 arguments
Stack trace:
*[1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *stdin*:51
type 'quit;' to quit to outer loop
brk> n; Where();
3
*[1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:1
brk> DownEnv(); n; Where();
3
*[1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:2
brk> DownEnv(); n; Where();
2
 [1] IsAbelian( 1 )
   @ *stdin*:47
*[2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:3
brk> DownEnv(); n; Where();
1
 [1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
*[3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:4
brk> UpEnv(); n; Where();
2
 [1] IsAbelian( 1 )
   @ *stdin*:47
*[2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:5
brk> UpEnv(); n; Where();
3
*[1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:6
brk> UpEnv(); n; Where();
3
*[1] IsAbelian( 1 )
   @ *stdin*:47
 [2] test( n + 1 );
   @ *stdin*:49
 [3] test( n + 1 );
   @ *stdin*:49
<function "test">( <arguments> )
 called from read-eval loop at *errin*:7
brk> quit;
gap> QUIT;
