• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/libubox/tests/cram/test_jshn.t

  1 set jshn for convenience:
  2 
  3   $ [ -n "$JSHN" ] && export PATH="$(dirname "$JSHN"):$PATH"
  4   $ alias jshn="valgrind --quiet --leak-check=full jshn"
  5 
  6 check usage:
  7 
  8   $ jshn
  9   Usage: jshn [-n] [-i] -r <message>|-R <file>|-o <file>|-p <prefix>|-w
 10   [2]
 11 
 12   $ jshn-san
 13   Usage: jshn-san [-n] [-i] -r <message>|-R <file>|-o <file>|-p <prefix>|-w
 14   [2]
 15 
 16 test bad json:
 17 
 18   $ jshn -r '[]'
 19   Failed to parse message data
 20   [1]
 21 
 22   $ jshn-san -r '[]'
 23   Failed to parse message data
 24   [1]
 25 
 26 test good json:
 27 
 28   $ jshn -r '{"foo": "bar", "baz": {"next": "meep"}}'
 29   json_init;
 30   json_add_string 'foo' 'bar';
 31   json_add_object 'baz';
 32   json_add_string 'next' 'meep';
 33   json_close_object;
 34 
 35   $ jshn-san -r '{"foo": "bar", "baz": {"next": "meep"}}'
 36   json_init;
 37   json_add_string 'foo' 'bar';
 38   json_add_object 'baz';
 39   json_add_string 'next' 'meep';
 40   json_close_object;
 41 
 42 test json from file:
 43 
 44   $ echo '[]' > test.json; jshn -R test.json
 45   Failed to parse message data
 46   [1]
 47 
 48   $ echo '[]' > test.json; jshn-san -R test.json
 49   Failed to parse message data
 50   [1]
 51 
 52   $ jshn -R nada.json
 53   Error opening nada.json
 54   [3]
 55 
 56   $ jshn-san -R nada.json
 57   Error opening nada.json
 58   [3]
 59 
 60   $ echo '{"foo": "bar", "baz": {"next": "meep"}}' > test.json; jshn -R test.json
 61   json_init;
 62   json_add_string 'foo' 'bar';
 63   json_add_object 'baz';
 64   json_add_string 'next' 'meep';
 65   json_close_object;
 66 
 67   $ echo '{"foo": "bar", "baz": {"next": "meep"}}' > test.json; jshn-san -R test.json
 68   json_init;
 69   json_add_string 'foo' 'bar';
 70   json_add_object 'baz';
 71   json_add_string 'next' 'meep';
 72   json_close_object;
 73 
 74 test json formatting without prepared environment:
 75 
 76   $ jshn -p procd -w
 77   { }
 78 
 79   $ jshn-san -p procd -w
 80   { }
 81 
 82   $ jshn -i -p procd -w
 83   {
 84   \t (esc)
 85   }
 86 
 87   $ jshn-san -i -p procd -w
 88   {
 89   \t (esc)
 90   }
 91 
 92   $ jshn -i -n -p procd -w
 93   {
 94   \t (esc)
 95   } (no-eol)
 96 
 97   $ jshn-san -i -n -p procd -w
 98   {
 99   \t (esc)
100   } (no-eol)
101 
102   $ jshn -p procd -o test.json; cat test.json
103   { }
104 
105   $ jshn-san -p procd -o test.json; cat test.json
106   { }
107 
108   $ jshn -i -p procd -o test.json; cat test.json
109   {
110   \t (esc)
111   }
112 
113   $ jshn-san -i -p procd -o test.json; cat test.json
114   {
115   \t (esc)
116   }
117 
118   $ jshn -i -n -p procd -o test.json; cat test.json
119   {
120   \t (esc)
121   } (no-eol)
122 
123   $ jshn-san -i -n -p procd -o test.json; cat test.json
124   {
125   \t (esc)
126   } (no-eol)
127 
128   $ chmod oug= test.json
129   $ jshn -i -n -p procd -o test.json
130   Error opening test.json
131   [3]
132   $ jshn-san -i -n -p procd -o test.json
133   Error opening test.json
134   [3]
135   $ rm -f test.json
136 
137 test json formatting with prepared environment:
138 
139   $ export procdJSON_CUR=J_V
140   $ export procdJ_A3_1=/sbin/urngd
141   $ export procdJ_T1_instance1=J_T2
142   $ export procdJ_T2_command=J_A3
143   $ export procdJ_V_data=J_T5
144   $ export procdJ_V_instances=J_T1
145   $ export procdJ_V_name=urngd
146   $ export procdJ_V_script=/etc/init.d/urngd
147   $ export procdJ_V_triggers=J_A4
148   $ export procdK_J_A3=1
149   $ export procdK_J_A4=
150   $ export procdK_J_T1=instance1
151   $ export procdK_J_T2=command
152   $ export procdK_J_T5=
153   $ export procdK_J_V="name script instances triggers data"
154   $ export procdT_J_A3_1=string
155   $ export procdT_J_T1_instance1=object
156   $ export procdT_J_T2_command=array
157   $ export procdT_J_V_data=object
158   $ export procdT_J_V_instances=object
159   $ export procdT_J_V_name=string
160   $ export procdT_J_V_script=string
161   $ export procdT_J_V_triggers=array
162 
163   $ jshn -p procd -w
164   { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
165 
166   $ jshn-san -p procd -w
167   { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
168 
169   $ jshn -i -p procd -w
170   {
171   \t"name": "urngd", (esc)
172   \t"script": "/etc/init.d/urngd", (esc)
173   \t"instances": { (esc)
174   \t\t"instance1": { (esc)
175   \t\t\t"command": [ (esc)
176   \t\t\t\t"/sbin/urngd" (esc)
177   \t\t\t] (esc)
178   \t\t} (esc)
179   \t}, (esc)
180   \t"triggers": [ (esc)
181   \t\t (esc)
182   \t], (esc)
183   \t"data": { (esc)
184   \t\t (esc)
185   \t} (esc)
186   }
187 
188   $ jshn-san -i -p procd -w
189   {
190   \t"name": "urngd", (esc)
191   \t"script": "/etc/init.d/urngd", (esc)
192   \t"instances": { (esc)
193   \t\t"instance1": { (esc)
194   \t\t\t"command": [ (esc)
195   \t\t\t\t"/sbin/urngd" (esc)
196   \t\t\t] (esc)
197   \t\t} (esc)
198   \t}, (esc)
199   \t"triggers": [ (esc)
200   \t\t (esc)
201   \t], (esc)
202   \t"data": { (esc)
203   \t\t (esc)
204   \t} (esc)
205   }
206 
207   $ jshn -n -i -p procd -w
208   {
209   \t"name": "urngd", (esc)
210   \t"script": "/etc/init.d/urngd", (esc)
211   \t"instances": { (esc)
212   \t\t"instance1": { (esc)
213   \t\t\t"command": [ (esc)
214   \t\t\t\t"/sbin/urngd" (esc)
215   \t\t\t] (esc)
216   \t\t} (esc)
217   \t}, (esc)
218   \t"triggers": [ (esc)
219   \t\t (esc)
220   \t], (esc)
221   \t"data": { (esc)
222   \t\t (esc)
223   \t} (esc)
224   } (no-eol)
225 
226   $ jshn-san -n -i -p procd -w
227   {
228   \t"name": "urngd", (esc)
229   \t"script": "/etc/init.d/urngd", (esc)
230   \t"instances": { (esc)
231   \t\t"instance1": { (esc)
232   \t\t\t"command": [ (esc)
233   \t\t\t\t"/sbin/urngd" (esc)
234   \t\t\t] (esc)
235   \t\t} (esc)
236   \t}, (esc)
237   \t"triggers": [ (esc)
238   \t\t (esc)
239   \t], (esc)
240   \t"data": { (esc)
241   \t\t (esc)
242   \t} (esc)
243   } (no-eol)
244 
245   $ jshn -p procd -o test.json; cat test.json
246   { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
247 
248   $ jshn-san -p procd -o test.json; cat test.json
249   { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
250 
251   $ jshn -i -p procd -o test.json; cat test.json
252   {
253   \t"name": "urngd", (esc)
254   \t"script": "/etc/init.d/urngd", (esc)
255   \t"instances": { (esc)
256   \t\t"instance1": { (esc)
257   \t\t\t"command": [ (esc)
258   \t\t\t\t"/sbin/urngd" (esc)
259   \t\t\t] (esc)
260   \t\t} (esc)
261   \t}, (esc)
262   \t"triggers": [ (esc)
263   \t\t (esc)
264   \t], (esc)
265   \t"data": { (esc)
266   \t\t (esc)
267   \t} (esc)
268   }
269 
270   $ jshn-san -i -p procd -o test.json; cat test.json
271   {
272   \t"name": "urngd", (esc)
273   \t"script": "/etc/init.d/urngd", (esc)
274   \t"instances": { (esc)
275   \t\t"instance1": { (esc)
276   \t\t\t"command": [ (esc)
277   \t\t\t\t"/sbin/urngd" (esc)
278   \t\t\t] (esc)
279   \t\t} (esc)
280   \t}, (esc)
281   \t"triggers": [ (esc)
282   \t\t (esc)
283   \t], (esc)
284   \t"data": { (esc)
285   \t\t (esc)
286   \t} (esc)
287   }
288 
289   $ jshn -n -i -p procd -o test.json; cat test.json
290   {
291   \t"name": "urngd", (esc)
292   \t"script": "/etc/init.d/urngd", (esc)
293   \t"instances": { (esc)
294   \t\t"instance1": { (esc)
295   \t\t\t"command": [ (esc)
296   \t\t\t\t"/sbin/urngd" (esc)
297   \t\t\t] (esc)
298   \t\t} (esc)
299   \t}, (esc)
300   \t"triggers": [ (esc)
301   \t\t (esc)
302   \t], (esc)
303   \t"data": { (esc)
304   \t\t (esc)
305   \t} (esc)
306   } (no-eol)
307 
308   $ jshn-san -n -i -p procd -o test.json; cat test.json
309   {
310   \t"name": "urngd", (esc)
311   \t"script": "/etc/init.d/urngd", (esc)
312   \t"instances": { (esc)
313   \t\t"instance1": { (esc)
314   \t\t\t"command": [ (esc)
315   \t\t\t\t"/sbin/urngd" (esc)
316   \t\t\t] (esc)
317   \t\t} (esc)
318   \t}, (esc)
319   \t"triggers": [ (esc)
320   \t\t (esc)
321   \t], (esc)
322   \t"data": { (esc)
323   \t\t (esc)
324   \t} (esc)
325   } (no-eol)
326 
327   $ chmod oug= test.json
328   $ jshn -n -i -p procd -o test.json
329   Error opening test.json
330   [3]
331   $ jshn-san -n -i -p procd -o test.json
332   Error opening test.json
333   [3]

This page was automatically generated by LXR 0.3.1.  •  OpenWrt