Skip to content

Commit

Permalink
Adding ON ERROR GOTO test
Browse files Browse the repository at this point in the history
- checks correct function of `ON ERROR GOTO label` in conjuction with `ON ERROR GOTO _LASTHANDLER`
  • Loading branch information
RhoSigma-QB64 committed Aug 19, 2024
1 parent ffce952 commit 48099fe
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/compile_tests/on_error/errtest.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
$CONSOLE:ONLY

'interfacing internal variables
DECLARE LIBRARY "errtest"
FUNCTION GetErrorHistory$
FUNCTION GetErrorGotoLine&
END DECLARE

'testing handler behavior
Status
ON ERROR GOTO mainHandler
Status
ERROR 5
NormalTest
ERROR 5
RecursiveTest 3
ERROR 5
ON ERROR GOTO _LASTHANDLER
Status

'return to test script
SYSTEM

'-----------------------------------------------------------------------
mainHandler:
PRINT " CALLED: main handler"
RESUME NEXT
'-----
nSubHandler:
PRINT " CALLED: normal sub handler"
RESUME NEXT
'-----
rSubHandler:
PRINT " CALLED: recursive sub handler"
RESUME NEXT

'-----------------------------------------------------------------------
SUB NormalTest
ON ERROR GOTO nSubHandler
Status
ERROR 5
ON ERROR GOTO _LASTHANDLER
Status
END SUB
'-----
SUB RecursiveTest (n%)
ON ERROR GOTO rSubHandler
Status
ERROR 5
IF n% > 1 THEN RecursiveTest n% - 1
ON ERROR GOTO _LASTHANDLER
Status
END SUB

'-----------------------------------------------------------------------
SUB Status
PRINT: PRINT "HISTORY: "; "<"; GetErrorHistory$; ">"
SELECT CASE GetErrorGotoLine&
CASE 0: PRINT " ACTIVE: unhandled"
CASE 1: PRINT " ACTIVE: main handler"
CASE 2: PRINT " ACTIVE: normal sub handler"
CASE 3: PRINT " ACTIVE: recursive sub handler"
END SELECT
END SUB

12 changes: 12 additions & 0 deletions tests/compile_tests/on_error/errtest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unsigned char cont[256];

unsigned char *GetErrorHistory() {
memset(cont, 0, 256);
memcpy (cont, error_handler_history -> chr, error_handler_history -> len);
return cont;
}

uint32_t GetErrorGotoLine() {
return error_goto_line;
}

40 changes: 40 additions & 0 deletions tests/compile_tests/on_error/errtest.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

HISTORY: <>
ACTIVE: unhandled

HISTORY: < 0|>
ACTIVE: main handler
CALLED: main handler

HISTORY: < 1| 0|>
ACTIVE: normal sub handler
CALLED: normal sub handler

HISTORY: < 0|>
ACTIVE: main handler
CALLED: main handler

HISTORY: < 1| 0|>
ACTIVE: recursive sub handler
CALLED: recursive sub handler

HISTORY: < 3| 1| 0|>
ACTIVE: recursive sub handler
CALLED: recursive sub handler

HISTORY: < 3| 3| 1| 0|>
ACTIVE: recursive sub handler
CALLED: recursive sub handler

HISTORY: < 3| 1| 0|>
ACTIVE: recursive sub handler

HISTORY: < 1| 0|>
ACTIVE: recursive sub handler

HISTORY: < 0|>
ACTIVE: main handler
CALLED: main handler

HISTORY: <>
ACTIVE: unhandled

0 comments on commit 48099fe

Please sign in to comment.