tests/test_util_json.sh
author Kim Alvefur <zash@zash.se>
Sun, 25 Nov 2018 13:16:17 +0100
changeset 9647 bb8486491b48
parent 7240 472736b583fb
permissions -rwxr-xr-x
mod_proxy65: Check what port is used at the time of the query Could have changed between startup and time of request
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7240
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     1
#!/bin/bash
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
export LUA_PATH="../?.lua;;"
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
export LUA_CPATH="../?.so;;"
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
#set -x
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
if ! which "$RUNWITH"; then
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
	echo "Unable to find interpreter $RUNWITH";
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
	exit 1;
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
fi
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
if ! $RUNWITH -e 'assert(require"util.json")' 2>/dev/null; then
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
	echo "Unable to find util.json";
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
	exit 1;
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
fi
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    17
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
FAIL=0
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
for f in json/pass*.json; do
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
	if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))~=nil)' <"$f" 2>/dev/null; then
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
		echo "Failed to decode valid JSON: $f";
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
		FAIL=1
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
	fi
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
done
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
for f in json/fail*.json; do
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
	if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))==nil)' <"$f" 2>/dev/null; then
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    29
		echo "Invalid JSON decoded without error: $f";
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    30
		FAIL=1
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
	fi
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
done
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    33
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    34
if [ "$FAIL" == "1" ]; then
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    35
	echo "JSON tests failed"
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    36
	exit 1;
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    37
fi
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    38
472736b583fb tests: Add extra tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
exit 0;