add cram based unit tests
[project/libubox.git] / tests / cram / test_json_script.t
1 set test bin path:
2
3 $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH"
4 $ export TEST_INPUTS="$TESTDIR/inputs"
5 $ alias js="valgrind --quiet --leak-check=full test-json-script"
6
7 check that json-script is producing expected results:
8
9 $ js
10 Usage: test-json-script [VARNAME=value] <filename_json_script>
11 [254]
12
13 $ echo '}' > test.json; js test.json
14 load JSON data from test.json failed.
15
16 $ js nada.json 2>&1 | grep load.*failed
17 load JSON data from nada.json failed.
18
19 $ echo '[ [ ] [ ] ]' > test.json; js test.json
20 load JSON data from test.json failed.
21
22 check example json-script:
23
24 $ js $TEST_INPUTS/json-script.json
25 exec /%/
26 exec_if_or
27
28 $ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
29 exec meh /%/
30 exec_if_or meep
31
32 check has expression:
33
34 $ echo '
35 > [
36 > [ "if",
37 > [ "has", "VAR" ],
38 > [ "echo", "bar" ],
39 > [ "echo", "baz" ]
40 > ]
41 > ]' > test.json
42
43 $ js VAR=foo test.json
44 echo bar
45
46 $ js VAR=bar test.json
47 echo bar
48
49 $ js test.json
50 echo baz
51
52 check eq expression:
53
54 $ echo '
55 > [
56 > [ "if",
57 > [ "eq", "VAR", "bar" ],
58 > [ "echo", "foo" ],
59 > [ "echo", "baz" ]
60 > ]
61 > ]' > test.json
62
63 $ js VAR=bar test.json
64 echo foo
65
66 $ js VAR=xxx test.json
67 echo baz
68
69 $ js test.json
70 echo baz
71
72 check regex single expression:
73
74 $ echo '
75 > [
76 > [ "if",
77 > [ "regex", "VAR", ".ell." ],
78 > [ "echo", "bar" ],
79 > [ "echo", "baz" ]
80 > ]
81 > ]' > test.json
82
83 $ js VAR=hello test.json
84 echo bar
85
86 $ js VAR=.ell. test.json
87 echo bar
88
89 $ js test.json
90 echo baz
91
92 $ js VAR= test.json
93 echo baz
94
95 $ js VAR=hell test.json
96 echo baz