diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cram/test_basic.t | 97 | ||||
-rw-r--r-- | tests/custom/02_runtime/07_raw_template_mode_switching | 45 | ||||
-rw-r--r-- | tests/custom/03_stdlib/29_require | 26 | ||||
-rw-r--r-- | tests/custom/03_stdlib/35_include | 32 | ||||
-rwxr-xr-x | tests/custom/run_tests.sh | 5 |
5 files changed, 159 insertions, 46 deletions
diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t index d2a3605..b85167f 100644 --- a/tests/cram/test_basic.t +++ b/tests/cram/test_basic.t @@ -10,52 +10,95 @@ setup common environment: check that ucode provides exepected help: $ ucode | sed 's/ucode-san/ucode/' - Usage - - # ucode [-t] [-l] [-r] [-S] [-R] [-x function [-x ...]] [-e '[prefix=]{"var": ...}'] [-E [prefix=]env.json] {-i <file> | -s "ucode script..."} - -h, --help\tPrint this help (esc) - -i file\tExecute the given ucode script file (esc) - -s "ucode script..."\tExecute the given string as ucode script (esc) - -t Enable VM execution tracing - -l Do not strip leading block whitespace - -r Do not trim trailing block newlines - -S Enable strict mode - -R Enable raw code mode - -e Set global variables from given JSON object - -E Set global variables from given JSON file - -x Disable given function - -m Preload given module - -o Write precompiled byte code to given file - -O Write precompiled byte code to given file and strip debug information + Usage: + ucode -h + ucode -e "expression" + ucode input.uc [input2.uc ...] + ucode -c [-s] [-o output.uc] input.uc [input2.uc ...] + + -h + Help display this help. + + -e "expression" + Execute the given expression as ucode program. + + -t + Enable VM execution tracing. + + -S + Enable strict mode. + + -R + Process source file(s) as raw script code (default). + + -T[flag,flag,...] + Process the source file(s) as templates, not as raw script code. + Supported flags: no-lstrip (don't strip leading whitespace before + block tags), no-rtrim (don't strip trailing newline after block tags). + + -D [name=]value + Define global variable. If `name` is omitted, a JSON dictionary is + expected with each property becoming a global variable set to the + corresponding value. If `name` is specified, it is defined as global + variable set to `value` parsed as JSON (or the literal `value` string + if JSON parsing fails). + + -F [name=]path + Like `-D` but reading the value from the file in `path`. The given + file must contain a single, well-formed JSON dictionary. + + -U name + Undefine the given global variable name. + + -l [name=]library + Preload the given `library`, optionally aliased to `name`. + + -L pattern + Append given `pattern` to default library search paths. If the pattern + contains no `*`, it is added twice, once with `/*.so` and once with + `/*.uc` appended to it. + + -c[flag,flag,...] + Compile the given source file(s) to bytecode instead of executing them. + Supported flags: no-interp (omit interpreter line), interp=... (over- + ride interpreter line with ...) + + -o path + Output file path when compiling. If omitted, the compiled byte code + is written to `./uc.out`. Only meaningful in conjunction with `-c`. + + -s + Omit (strip) debug information when compiling files. + Only meaningful in conjunction with `-c`. + check that ucode prints greetings: - $ ucode -s "{% print('hello world') %}" + $ ucode -e "print('hello world')" hello world (no-eol) check that ucode provides proper error messages: - $ ucode -m foo - One of -i or -s is required + $ ucode -l foo + Require either -e expression or source file [1] - $ ucode -m foo -s ' ' + $ ucode -l foo -e ' ' Runtime error: No module named 'foo' could be found [254] - $ touch moo; ucode -m foo -i moo + $ touch moo; ucode -l foo moo Runtime error: No module named 'foo' could be found [254] check that ucode can load fs module: - $ ucode -m fs - One of -i or -s is required + $ ucode -l fs + Require either -e expression or source file [1] - $ ucode -m fs -s ' ' - (no-eol) + $ ucode -l fs -e ' ' - $ touch moo; ucode -m fs -i moo + $ touch moo; ucode -l fs moo diff --git a/tests/custom/02_runtime/07_raw_template_mode_switching b/tests/custom/02_runtime/07_raw_template_mode_switching new file mode 100644 index 0000000..5ae53e8 --- /dev/null +++ b/tests/custom/02_runtime/07_raw_template_mode_switching @@ -0,0 +1,45 @@ +Testing that require(), render() and include() properly toggle between +raw- and template parse mode. + + +1. Testing recursive invocation. + +-- Testcase -- +require("files.requiretest"); +print(render("files/render-test.uc")); +include("files/include-test.uc"); +-- End -- + +-- Args -- +-R +-- End -- + +-- File requiretest.uc -- +print("This is a raw mode file loaded by require()\n"); +print(render("require-render-test.uc")); +include("require-include-test.uc"); +-- End -- + +-- File require-include-test.uc -- +print("This is a raw mode file included by a required file\n"); +-- End -- + +-- File require-render-test.uc -- +This is a {{ "template mode" }} file rendered by a required file +-- End -- + +-- File render-test.uc -- +This is a {{ "template mode" }} file loaded by render() from a raw mode file +-- End -- + +-- File include-test.uc -- +print("This is a raw mode file loaded by include() from a raw mode file\n"); +-- End -- + +-- Expect stdout -- +This is a raw mode file loaded by require() +This is a template mode file rendered by a required file +This is a raw mode file included by a required file +This is a template mode file loaded by render() from a raw mode file +This is a raw mode file loaded by include() from a raw mode file +-- End -- diff --git a/tests/custom/03_stdlib/29_require b/tests/custom/03_stdlib/29_require index 681f3f7..4fb4216 100644 --- a/tests/custom/03_stdlib/29_require +++ b/tests/custom/03_stdlib/29_require @@ -42,15 +42,13 @@ Returns the value returned by the invoked module code (typically an object). -- End -- -- File require/test/module.uc -- -{% - print("This is require.test.module running!\n\n"); +print("This is require.test.module running!\n\n"); - return { - greeting: function(name) { - printf("Hello, %s!\n", name); - } - }; -%} +return { + greeting: function(name) { + printf("Hello, %s!\n", name); + } +}; -- End -- -- Expect stdout -- @@ -139,19 +137,17 @@ A compilation error in the module triggers an exception. -- End -- -- File require/test/broken.uc -- -{% - // Unclosed object to force syntax error - return { -%} +// Unclosed object to force syntax error +return { -- End -- -- Expect stderr -- Unable to compile module '.../require/test/broken.uc': Syntax error: Expecting label -In line 3, byte 11: +In line 2, byte 10: - ` return {` - Near here --^ + `return {` + ^-- Near here diff --git a/tests/custom/03_stdlib/35_include b/tests/custom/03_stdlib/35_include index 6d808f2..1d428f1 100644 --- a/tests/custom/03_stdlib/35_include +++ b/tests/custom/03_stdlib/35_include @@ -171,3 +171,35 @@ In line 12, byte 8: -- End -- + + +Ensure that included files inherit the parse mode of their calling file. + +-- Testcase -- +{% include("files/inctest.uc"); %} +-- End -- + +-- File inctest.uc -- +print("Test\n"); +-- End -- + +-- Expect stdout -- +print("Test\n"); +-- End -- + + +-- Testcase -- +include("files/inctest.uc"); +-- End -- + +-- Args -- +-R +-- End -- + +-- File inctest.uc -- +print("Test\n"); +-- End -- + +-- Expect stdout -- +Test +-- End -- diff --git a/tests/custom/run_tests.sh b/tests/custom/run_tests.sh index 2f13c3b..c2839df 100755 --- a/tests/custom/run_tests.sh +++ b/tests/custom/run_tests.sh @@ -93,10 +93,7 @@ run_testcase() { IFS=$' \t\n' - $ucode_bin $args -e '{ - "REQUIRE_SEARCH_PATH": [ "'"$ucode_lib"'/*.so" ], - "TESTFILES_PATH": "'"$dir"'/files" - }' -i - <"$in" >"$dir/res.out" 2>"$dir/res.err" + $ucode_bin -T -L "$ucode_lib/*.so" -D TESTFILES_PATH="$dir/files" $args - <"$in" >"$dir/res.out" 2>"$dir/res.err" ) printf "%d\n" $? > "$dir/res.code" |