Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2019-11-24 01:51:20 +0300
committerPetr Štetiar <ynezz@true.cz>2019-11-24 15:26:58 +0300
commit07413cce72e19520af55dfcbc765484f5ab41dd9 (patch)
treeb85adbced7fdb3957792ca73a5c76e2b56ee153d /tests
parent26586dae43a83d286762c73b49b98aa8dfc852c3 (diff)
tests: jshn: add more test cases
In order to cover all command line options. Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'tests')
-rw-r--r--tests/cram/test_jshn.t164
1 files changed, 164 insertions, 0 deletions
diff --git a/tests/cram/test_jshn.t b/tests/cram/test_jshn.t
index 937c7e1..1881a3d 100644
--- a/tests/cram/test_jshn.t
+++ b/tests/cram/test_jshn.t
@@ -23,3 +23,167 @@ test good json:
json_add_object 'baz';
json_add_string 'next' 'meep';
json_close_object;
+
+test json from file:
+
+ $ echo '[]' > test.json; jshn -R test.json
+ Failed to parse message data
+ [1]
+
+ $ jshn -R nada.json
+ Error opening nada.json
+ [3]
+
+ $ echo '{"foo": "bar", "baz": {"next": "meep"}}' > test.json; jshn -R test.json
+ json_init;
+ json_add_string 'foo' 'bar';
+ json_add_object 'baz';
+ json_add_string 'next' 'meep';
+ json_close_object;
+
+test json formatting without prepared environment:
+
+ $ jshn -p procd -w
+ { }
+
+ $ jshn -i -p procd -w
+ {
+ \t (esc)
+ }
+
+ $ jshn -i -n -p procd -w
+ {
+ \t (esc)
+ } (no-eol)
+
+ $ jshn -p procd -o test.json; cat test.json
+ { }
+
+ $ jshn -i -p procd -o test.json; cat test.json
+ {
+ \t (esc)
+ }
+
+ $ jshn -i -n -p procd -o test.json; cat test.json
+ {
+ \t (esc)
+ } (no-eol)
+
+ $ chmod oug= test.json
+ $ jshn -i -n -p procd -o test.json
+ Error opening test.json
+ [3]
+ $ rm -f test.json
+
+test json formatting with prepared environment:
+
+ $ export procdJSON_CUR=J_V
+ $ export procdJ_A3_1=/sbin/urngd
+ $ export procdJ_T1_instance1=J_T2
+ $ export procdJ_T2_command=J_A3
+ $ export procdJ_V_data=J_T5
+ $ export procdJ_V_instances=J_T1
+ $ export procdJ_V_name=urngd
+ $ export procdJ_V_script=/etc/init.d/urngd
+ $ export procdJ_V_triggers=J_A4
+ $ export procdK_J_A3=1
+ $ export procdK_J_A4=
+ $ export procdK_J_T1=instance1
+ $ export procdK_J_T2=command
+ $ export procdK_J_T5=
+ $ export procdK_J_V="name script instances triggers data"
+ $ export procdT_J_A3_1=string
+ $ export procdT_J_T1_instance1=object
+ $ export procdT_J_T2_command=array
+ $ export procdT_J_V_data=object
+ $ export procdT_J_V_instances=object
+ $ export procdT_J_V_name=string
+ $ export procdT_J_V_script=string
+ $ export procdT_J_V_triggers=array
+
+ $ jshn -p procd -w
+ { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
+
+ $ jshn -i -p procd -w
+ {
+ \t"name": "urngd", (esc)
+ \t"script": "/etc/init.d/urngd", (esc)
+ \t"instances": { (esc)
+ \t\t"instance1": { (esc)
+ \t\t\t"command": [ (esc)
+ \t\t\t\t"/sbin/urngd" (esc)
+ \t\t\t] (esc)
+ \t\t} (esc)
+ \t}, (esc)
+ \t"triggers": [ (esc)
+ \t\t (esc)
+ \t], (esc)
+ \t"data": { (esc)
+ \t\t (esc)
+ \t} (esc)
+ }
+
+ $ jshn -n -i -p procd -w
+ {
+ \t"name": "urngd", (esc)
+ \t"script": "/etc/init.d/urngd", (esc)
+ \t"instances": { (esc)
+ \t\t"instance1": { (esc)
+ \t\t\t"command": [ (esc)
+ \t\t\t\t"/sbin/urngd" (esc)
+ \t\t\t] (esc)
+ \t\t} (esc)
+ \t}, (esc)
+ \t"triggers": [ (esc)
+ \t\t (esc)
+ \t], (esc)
+ \t"data": { (esc)
+ \t\t (esc)
+ \t} (esc)
+ } (no-eol)
+
+ $ jshn -p procd -o test.json; cat test.json
+ { "name": "urngd", "script": "\/etc\/init.d\/urngd", "instances": { "instance1": { "command": [ "\/sbin\/urngd" ] } }, "triggers": [ ], "data": { } }
+
+ $ jshn -i -p procd -o test.json; cat test.json
+ {
+ \t"name": "urngd", (esc)
+ \t"script": "/etc/init.d/urngd", (esc)
+ \t"instances": { (esc)
+ \t\t"instance1": { (esc)
+ \t\t\t"command": [ (esc)
+ \t\t\t\t"/sbin/urngd" (esc)
+ \t\t\t] (esc)
+ \t\t} (esc)
+ \t}, (esc)
+ \t"triggers": [ (esc)
+ \t\t (esc)
+ \t], (esc)
+ \t"data": { (esc)
+ \t\t (esc)
+ \t} (esc)
+ }
+
+ $ jshn -n -i -p procd -o test.json; cat test.json
+ {
+ \t"name": "urngd", (esc)
+ \t"script": "/etc/init.d/urngd", (esc)
+ \t"instances": { (esc)
+ \t\t"instance1": { (esc)
+ \t\t\t"command": [ (esc)
+ \t\t\t\t"/sbin/urngd" (esc)
+ \t\t\t] (esc)
+ \t\t} (esc)
+ \t}, (esc)
+ \t"triggers": [ (esc)
+ \t\t (esc)
+ \t], (esc)
+ \t"data": { (esc)
+ \t\t (esc)
+ \t} (esc)
+ } (no-eol)
+
+ $ chmod oug= test.json
+ $ jshn -n -i -p procd -o test.json
+ Error opening test.json
+ [3]