2019-11-19 14:31:44 +01:00
|
|
|
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"
|
2019-12-08 13:12:47 +01:00
|
|
|
$ alias js-san="test-json-script-san"
|
2019-11-19 14:31:44 +01:00
|
|
|
|
|
|
|
check that json-script is producing expected results:
|
|
|
|
|
|
|
|
$ js
|
|
|
|
Usage: test-json-script [VARNAME=value] <filename_json_script>
|
|
|
|
[254]
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san
|
|
|
|
Usage: test-json-script-san [VARNAME=value] <filename_json_script>
|
|
|
|
[254]
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ echo '}' > test.json; js test.json
|
|
|
|
load JSON data from test.json failed.
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ echo '}' > test.json; js-san test.json
|
|
|
|
load JSON data from test.json failed.
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js nada.json 2>&1 | grep load.*failed
|
|
|
|
load JSON data from nada.json failed.
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san nada.json 2>&1 | grep load.*failed
|
|
|
|
load JSON data from nada.json failed.
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ echo '[ [ ] [ ] ]' > test.json; js test.json
|
|
|
|
load JSON data from test.json failed.
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ echo '[ [ ] [ ] ]' > test.json; js-san test.json
|
|
|
|
load JSON data from test.json failed.
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
check example json-script:
|
|
|
|
|
|
|
|
$ js $TEST_INPUTS/json-script.json
|
|
|
|
exec /%/
|
|
|
|
exec_if_or
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san $TEST_INPUTS/json-script.json
|
|
|
|
exec /%/
|
|
|
|
exec_if_or
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
|
|
|
|
exec meh /%/
|
|
|
|
exec_if_or meep
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
|
|
|
|
exec meh /%/
|
|
|
|
exec_if_or meep
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
check has expression:
|
|
|
|
|
|
|
|
$ echo '
|
|
|
|
> [
|
|
|
|
> [ "if",
|
|
|
|
> [ "has", "VAR" ],
|
|
|
|
> [ "echo", "bar" ],
|
|
|
|
> [ "echo", "baz" ]
|
|
|
|
> ]
|
|
|
|
> ]' > test.json
|
|
|
|
|
|
|
|
$ js VAR=foo test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=foo test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js VAR=bar test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=bar test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
check eq expression:
|
|
|
|
|
|
|
|
$ echo '
|
|
|
|
> [
|
|
|
|
> [ "if",
|
|
|
|
> [ "eq", "VAR", "bar" ],
|
|
|
|
> [ "echo", "foo" ],
|
|
|
|
> [ "echo", "baz" ]
|
|
|
|
> ]
|
|
|
|
> ]' > test.json
|
|
|
|
|
|
|
|
$ js VAR=bar test.json
|
|
|
|
echo foo
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=bar test.json
|
|
|
|
echo foo
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js VAR=xxx test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=xxx test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
check regex single expression:
|
|
|
|
|
|
|
|
$ echo '
|
|
|
|
> [
|
|
|
|
> [ "if",
|
|
|
|
> [ "regex", "VAR", ".ell." ],
|
|
|
|
> [ "echo", "bar" ],
|
|
|
|
> [ "echo", "baz" ]
|
|
|
|
> ]
|
|
|
|
> ]' > test.json
|
|
|
|
|
|
|
|
$ js VAR=hello test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=hello test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js VAR=.ell. test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR=.ell. test.json
|
|
|
|
echo bar
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js VAR= test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-12-08 13:12:47 +01:00
|
|
|
$ js-san VAR= test.json
|
|
|
|
echo baz
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
$ js VAR=hell test.json
|
|
|
|
echo baz
|
2019-12-08 13:12:47 +01:00
|
|
|
|
|
|
|
$ js-san VAR=hell test.json
|
|
|
|
echo baz
|