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