summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/39_trace
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-29 23:31:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:22:43 +0100
commit7edad5cefa0f065aa83dffd2d7830aeaf9f38662 (patch)
tree86b727f434302ffb28cb59278243517f9765e170 /tests/custom/03_stdlib/39_trace
parentd5003fde57eab19588da7bfdbaefe93d47435eb6 (diff)
tests: add functional tests for builtin functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/39_trace')
-rw-r--r--tests/custom/03_stdlib/39_trace79
1 files changed, 79 insertions, 0 deletions
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 --