Comparison

tests/test_util_json.sh @ 7237:472736b583fb

tests: Add extra tests for util.json
author Matthew Wild <mwild1@gmail.com>
date Sat, 05 Mar 2016 20:48:20 +0000
comparison
equal deleted inserted replaced
7235:ee1f7e1e548c 7237:472736b583fb
1 #!/bin/bash
2
3 export LUA_PATH="../?.lua;;"
4 export LUA_CPATH="../?.so;;"
5
6 #set -x
7
8 if ! which "$RUNWITH"; then
9 echo "Unable to find interpreter $RUNWITH";
10 exit 1;
11 fi
12
13 if ! $RUNWITH -e 'assert(require"util.json")' 2>/dev/null; then
14 echo "Unable to find util.json";
15 exit 1;
16 fi
17
18 FAIL=0
19
20 for f in json/pass*.json; do
21 if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))~=nil)' <"$f" 2>/dev/null; then
22 echo "Failed to decode valid JSON: $f";
23 FAIL=1
24 fi
25 done
26
27 for f in json/fail*.json; do
28 if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))==nil)' <"$f" 2>/dev/null; then
29 echo "Invalid JSON decoded without error: $f";
30 FAIL=1
31 fi
32 done
33
34 if [ "$FAIL" == "1" ]; then
35 echo "JSON tests failed"
36 exit 1;
37 fi
38
39 exit 0;