libubox/tests/cram/test_json_script.t
Petr Štetiar b0a5cd8a28 add cram based unit tests
For improved QA etc. For the start with initial test cases for avl,
base64, jshn and list components. Moved runqueue and blobmsg from
examples to tests.  Converted just a few first test cases from
json-script example into the new cram based unit test, more to come.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-11-24 13:26:58 +01:00

96 lines
1.6 KiB
Perl

set test bin path:
$ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH"
$ export TEST_INPUTS="$TESTDIR/inputs"
$ alias js="valgrind --quiet --leak-check=full test-json-script"
check that json-script is producing expected results:
$ js
Usage: test-json-script [VARNAME=value] <filename_json_script>
[254]
$ echo '}' > test.json; js test.json
load JSON data from test.json failed.
$ js nada.json 2>&1 | grep load.*failed
load JSON data from nada.json failed.
$ echo '[ [ ] [ ] ]' > test.json; js test.json
load JSON data from test.json failed.
check example json-script:
$ js $TEST_INPUTS/json-script.json
exec /%/
exec_if_or
$ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
exec meh /%/
exec_if_or meep
check has expression:
$ echo '
> [
> [ "if",
> [ "has", "VAR" ],
> [ "echo", "bar" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=foo test.json
echo bar
$ js VAR=bar test.json
echo bar
$ js test.json
echo baz
check eq expression:
$ echo '
> [
> [ "if",
> [ "eq", "VAR", "bar" ],
> [ "echo", "foo" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=bar test.json
echo foo
$ js VAR=xxx test.json
echo baz
$ js test.json
echo baz
check regex single expression:
$ echo '
> [
> [ "if",
> [ "regex", "VAR", ".ell." ],
> [ "echo", "bar" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=hello test.json
echo bar
$ js VAR=.ell. test.json
echo bar
$ js test.json
echo baz
$ js VAR= test.json
echo baz
$ js VAR=hell test.json
echo baz