libubox
C utility functions for OpenWrt.
test_json_script.t
Go to the documentation of this file.
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  $ alias js-san="test-json-script-san"
7 
8 check that json-script is producing expected results:
9 
10  $ js
11  Usage: test-json-script [VARNAME=value] <filename_json_script>
12  [254]
13 
14  $ js-san
15  Usage: test-json-script-san [VARNAME=value] <filename_json_script>
16  [254]
17 
18  $ echo '}' > test.json; js test.json
19  load JSON data from test.json failed.
20 
21  $ echo '}' > test.json; js-san test.json
22  load JSON data from test.json failed.
23 
24  $ js nada.json 2>&1 | grep load.*failed
25  load JSON data from nada.json failed.
26 
27  $ js-san nada.json 2>&1 | grep load.*failed
28  load JSON data from nada.json failed.
29 
30  $ echo '[ [ ] [ ] ]' > test.json; js test.json
31  load JSON data from test.json failed.
32 
33  $ echo '[ [ ] [ ] ]' > test.json; js-san test.json
34  load JSON data from test.json failed.
35 
36 check example json-script:
37 
38  $ js $TEST_INPUTS/json-script.json
39  exec /%/
40  exec_if_or
41 
42  $ js-san $TEST_INPUTS/json-script.json
43  exec /%/
44  exec_if_or
45 
46  $ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
47  exec meh /%/
48  exec_if_or meep
49 
50  $ js-san EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
51  exec meh /%/
52  exec_if_or meep
53 
54 check has expression:
55 
56  $ echo '
57  > [
58  > [ "if",
59  > [ "has", "VAR" ],
60  > [ "echo", "bar" ],
61  > [ "echo", "baz" ]
62  > ]
63  > ]' > test.json
64 
65  $ js VAR=foo test.json
66  echo bar
67 
68  $ js-san VAR=foo test.json
69  echo bar
70 
71  $ js VAR=bar test.json
72  echo bar
73 
74  $ js-san VAR=bar test.json
75  echo bar
76 
77  $ js test.json
78  echo baz
79 
80  $ js-san test.json
81  echo baz
82 
83 check eq expression:
84 
85  $ echo '
86  > [
87  > [ "if",
88  > [ "eq", "VAR", "bar" ],
89  > [ "echo", "foo" ],
90  > [ "echo", "baz" ]
91  > ]
92  > ]' > test.json
93 
94  $ js VAR=bar test.json
95  echo foo
96 
97  $ js-san VAR=bar test.json
98  echo foo
99 
100  $ js VAR=xxx test.json
101  echo baz
102 
103  $ js-san VAR=xxx test.json
104  echo baz
105 
106  $ js test.json
107  echo baz
108 
109  $ js-san test.json
110  echo baz
111 
112 check regex single expression:
113 
114  $ echo '
115  > [
116  > [ "if",
117  > [ "regex", "VAR", ".ell." ],
118  > [ "echo", "bar" ],
119  > [ "echo", "baz" ]
120  > ]
121  > ]' > test.json
122 
123  $ js VAR=hello test.json
124  echo bar
125 
126  $ js-san VAR=hello test.json
127  echo bar
128 
129  $ js VAR=.ell. test.json
130  echo bar
131 
132  $ js-san VAR=.ell. test.json
133  echo bar
134 
135  $ js test.json
136  echo baz
137 
138  $ js-san test.json
139  echo baz
140 
141  $ js VAR= test.json
142  echo baz
143 
144  $ js-san VAR= test.json
145  echo baz
146 
147  $ js VAR=hell test.json
148  echo baz
149 
150  $ js-san VAR=hell test.json
151  echo baz