diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-03-14 08:47:58 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-03-14 15:31:34 +0100 |
commit | 46188077ef727c21513008f4e0c42e8cb211e90e (patch) | |
tree | 47933baeb43ff6ff3a95810c25fc189a6062e7be /tests/cram | |
parent | 23929951ad4b0ed2bcea793f6bf72d9e4236d3c7 (diff) |
main: rework CLI frontend
- Change command line flags to be align better with those of other
interpreters and with the gcc compiler, e.g. `-D` and `-U` to
define and undefine globals, `-e` to execute script expression etc.
- Pass only excess CLI arguments as `ARGV` to scripts, e.g.
`ucode -e 'print("Hello world")' -- -x -y` would pass only
`[ "-x", "-y" ]` as ARGV contents
- Default to raw mode and introduce flag to enable template mode
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/cram')
-rw-r--r-- | tests/cram/test_basic.t | 97 |
1 files changed, 70 insertions, 27 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 |