diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-08-23 15:43:25 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-08-24 15:33:18 +0200 |
commit | 131d99c45e586e06d2fa3adba32e92c0370ad022 (patch) | |
tree | 0a089858e2f2fbf2c19440be8dda7e945667d83b /tests/custom/03_stdlib/35_include | |
parent | 8e8dae0eb0f90dea3cb4b244c79f7fa855219f92 (diff) |
lib: introduce three new functions call(), loadstring() and loadfile()
Introduce new functions dealing with on-the-fly compilation of code and
execution of functions with different global scope.
The `loadstring()` and `loadfile()` functions will compile the given
ucode source string or ucode file path respectively and return the entry
function of the resulting program.
An optional dictionary specifying parse options may be given as second
argument.
Both functions return `null` on invalid arguments and throw an exception
in case of compilation errors.
The `call()` function allows invoking a given function value with a
different `this` context and/or a different global environment.
Finally refactor the existing `uc_require_ucode()` implementation to
reuse the new `uc_loadfile()` and `uc_call()` implementations and adjust
as well as simplify affected testcases.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/35_include')
-rw-r--r-- | tests/custom/03_stdlib/35_include | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/tests/custom/03_stdlib/35_include b/tests/custom/03_stdlib/35_include index 1d428f1..83c34bb 100644 --- a/tests/custom/03_stdlib/35_include +++ b/tests/custom/03_stdlib/35_include @@ -132,18 +132,7 @@ A compilation error in the file triggers an exception. -- Testcase -- {% - try { - include("files/broken.uc"); - } - catch (e) { - // Catch and rethrow exception with modified message to - // ensure stable test output. - e.message = replace(e.message, - /(compile module '.+broken\.uc')/, - "compile module '.../broken.uc'"); - - die(e); - } + include("files/broken.uc"); %} -- End -- @@ -155,19 +144,18 @@ A compilation error in the file triggers an exception. -- End -- -- Expect stderr -- -Unable to compile module '.../broken.uc': -Syntax error: Expecting label -In line 3, byte 11: +Runtime error: Unable to compile source file './files/broken.uc': - ` return {` - Near here --^ + | Syntax error: Expecting label + | In line 3, byte 11: + | + | ` return {` + | Near here --^ +In line 2, byte 27: - -In line 12, byte 8: - - ` die(e);` - Near here ---^ + ` include("files/broken.uc");` + Near here -------------------^ -- End -- |