From 48099fec845056bad684f9243f52021dfd42025d Mon Sep 17 00:00:00 2001 From: Roland Heyder Date: Mon, 19 Aug 2024 19:39:10 +0200 Subject: [PATCH] Adding ON ERROR GOTO test - checks correct function of `ON ERROR GOTO label` in conjuction with `ON ERROR GOTO _LASTHANDLER` --- tests/compile_tests/on_error/errtest.bas | 65 +++++++++++++++++++++ tests/compile_tests/on_error/errtest.h | 12 ++++ tests/compile_tests/on_error/errtest.output | 40 +++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/compile_tests/on_error/errtest.bas create mode 100644 tests/compile_tests/on_error/errtest.h create mode 100644 tests/compile_tests/on_error/errtest.output diff --git a/tests/compile_tests/on_error/errtest.bas b/tests/compile_tests/on_error/errtest.bas new file mode 100644 index 000000000..b617f23db --- /dev/null +++ b/tests/compile_tests/on_error/errtest.bas @@ -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 + diff --git a/tests/compile_tests/on_error/errtest.h b/tests/compile_tests/on_error/errtest.h new file mode 100644 index 000000000..666500dae --- /dev/null +++ b/tests/compile_tests/on_error/errtest.h @@ -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; +} + diff --git a/tests/compile_tests/on_error/errtest.output b/tests/compile_tests/on_error/errtest.output new file mode 100644 index 000000000..09fc11127 --- /dev/null +++ b/tests/compile_tests/on_error/errtest.output @@ -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