aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_util_json.sh
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-03-05 20:48:20 +0000
committerMatthew Wild <mwild1@gmail.com>2016-03-05 20:48:20 +0000
commit39dceba25851f3c9db32082f6217fbb2b7d6fc39 (patch)
treee708589be73c3c8c13e8dc3614684d4d3f66ef43 /tests/test_util_json.sh
parentdf618247d3fb899b69668dfcc084a154e04c34c6 (diff)
downloadprosody-39dceba25851f3c9db32082f6217fbb2b7d6fc39.tar.gz
prosody-39dceba25851f3c9db32082f6217fbb2b7d6fc39.zip
tests: Add extra tests for util.json
Diffstat (limited to 'tests/test_util_json.sh')
-rwxr-xr-xtests/test_util_json.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_util_json.sh b/tests/test_util_json.sh
new file mode 100755
index 00000000..bbbd132b
--- /dev/null
+++ b/tests/test_util_json.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+export LUA_PATH="../?.lua;;"
+export LUA_CPATH="../?.so;;"
+
+#set -x
+
+if ! which "$RUNWITH"; then
+ echo "Unable to find interpreter $RUNWITH";
+ exit 1;
+fi
+
+if ! $RUNWITH -e 'assert(require"util.json")' 2>/dev/null; then
+ echo "Unable to find util.json";
+ exit 1;
+fi
+
+FAIL=0
+
+for f in json/pass*.json; do
+ if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))~=nil)' <"$f" 2>/dev/null; then
+ echo "Failed to decode valid JSON: $f";
+ FAIL=1
+ fi
+done
+
+for f in json/fail*.json; do
+ if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))==nil)' <"$f" 2>/dev/null; then
+ echo "Invalid JSON decoded without error: $f";
+ FAIL=1
+ fi
+done
+
+if [ "$FAIL" == "1" ]; then
+ echo "JSON tests failed"
+ exit 1;
+fi
+
+exit 0;