From 7edad5cefa0f065aa83dffd2d7830aeaf9f38662 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 29 Jan 2022 23:31:16 +0100 Subject: tests: add functional tests for builtin functions Signed-off-by: Jo-Philipp Wich --- tests/custom/03_stdlib/39_trace | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/custom/03_stdlib/39_trace (limited to 'tests/custom/03_stdlib/39_trace') diff --git a/tests/custom/03_stdlib/39_trace b/tests/custom/03_stdlib/39_trace new file mode 100644 index 0000000..2b2295a --- /dev/null +++ b/tests/custom/03_stdlib/39_trace @@ -0,0 +1,79 @@ +The `trace()` function sets the execution trace level of the VM. + +Throws an exception if trace level argument is not a valid integer. + +Returns the previously used execution trace level. + +-- Testcase -- +{% + printf("Code before enabling tracing.\n"); + + trace(1); + + printf("Code after enabling tracing.\n"); + + trace(0); + + printf("Code after disabling tracing.\n"); +%} +-- End -- + +-- Expect stdout -- +Code before enabling tracing. +Code after enabling tracing. +Code after disabling tracing. +-- End -- + +-- Expect stderr -- + [-2] 1 + [-1] "function trace(...) { [native code] }" + [+1] 0 + [stdin]:4 trace(1); +0000001c POP + [-1] 0 +0000001d LVAR {0x0} ; "printf" + [+1] "function printf(...) { [native code] }" + [stdin]:6 printf("Code after enabling tracing.\n"); +00000022 LOAD {0x3} ; "Code after enabling tracing.\n" + [+2] "Code after enabling tracing.\n" + [stdin]:6 printf("Code after enabling tracing.\n"); +00000027 CALL {0x1} + [*] CALLFRAME[1] + |- stackframe 1/3 + |- ctx null + [-2] "Code after enabling tracing.\n" + [-1] "function printf(...) { [native code] }" + [+1] 29 + [stdin]:6 printf("Code after enabling tracing.\n"); +0000002c POP + [-1] 29 +0000002d LVAR {0x2} ; "trace" + [+1] "function trace(...) { [native code] }" + [stdin]:8 trace(0); +00000032 LOAD8 {0} + [+2] 0 + [stdin]:8 trace(0); +00000034 CALL {0x1} + [*] CALLFRAME[1] + |- stackframe 1/3 + |- ctx null +-- End -- + + +Passing an invalid trace value throws an exception. + +-- Testcase -- +{% + trace("inval"); +%} +-- End -- + +-- Expect stderr -- +Type error: Invalid level specified +In line 2, byte 15: + + ` trace("inval");` + Near here -------^ + + +-- End -- -- cgit v1.2.3