test/json: run tests through a line wine/crlf wrapper

unit tests rely on AWKs record seperator being LF which presents issues
when running windows tests. rather than modify the tap-driver provided
by autotools (which would be extremely annoying to maintain) we run all
tests through wine-crlf.sh which will perform line ending transforms as
required.

it's a pretty braindead script, so don't do anything terrifically
extreme under it.
This commit is contained in:
Danny Robson 2016-04-27 17:13:36 +10:00
parent 456362adff
commit b814c83e21
7 changed files with 76 additions and 33 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
/aclocal.m4 /aclocal.m4
/autom4te.cache/ /autom4te.cache/
/build-aux/
/compile /compile
/config.* /config.*
/configure /configure

8
build-aux/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
/compile
/config.guess
/config.sub
/depcomp
/install-sh
/ltmain.sh
/missing
/test-driver

16
build-aux/wine-crlf.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
case "$1" in
*.exe)
OUTPUT="$(/usr/bin/env wine $@)"
STATUS=$?
echo "$OUTPUT" | sed 's/\r$//'
exit $STATUS
;;
*)
$@
exit $?
;;
esac

View File

@ -132,7 +132,7 @@ AC_CONFIG_FILES([
Makefile Makefile
]) ])
AC_CONFIG_FILES([test/json-parse], [chmod a+x test/json-parse]) AC_CONFIG_FILES([test/json-parse.sh], [chmod a+x test/json-parse.sh])
AC_CONFIG_FILES([test/json-schema], [chmod a+x test/json-schema]) AC_CONFIG_FILES([test/json-schema.py], [chmod a+x test/json-schema.py])
AC_OUTPUT AC_OUTPUT

View File

@ -1,27 +0,0 @@
#!/bin/sh
validate=@abs_top_builddir@/tools/json-validate
good=(@abs_top_srcdir@/test/json/good/*)
bad=(@abs_top_srcdir@/test/json/bad/*)
count=$((${#good[@]}+${#bad[@]}))
echo 1..$count
for i in ${good[@]};
do
$validate $i 2>/dev/null 1>&2
case $? in
0) echo "ok - $(basename $i .json)";;
*) echo "not ok - $(basename $i .json)";;
esac
done
for i in ${bad[@]};
do
$validate $i 1>&2 2>/dev/null
case $? in
0) echo "not ok - $(basename $i .json)";;
*) echo "ok - $(basename $i .json)";;
esac
done

31
test/json-parse.sh.in Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
validate=@abs_top_builddir@/tools/json-validate@EXEEXT@
count=0
code=0
for i in $(ls @abs_top_srcdir@/test/json/good/*);
do
@abs_top_srcdir@/build-aux/wine-crlf.sh $validate $i 2>/dev/null 1>&2
case $? in
0) echo "ok - good/$(basename $i .json)";;
*) echo "not ok - good/$(basename $i .json)"; code=1;;
esac
count=$((count+1))
done
for i in $(ls @abs_top_srcdir@/test/json/bad/*);
do
@abs_top_srcdir@/build-aux/wine-crlf.sh $validate $i 1>&2 2>/dev/null
case $? in
0) echo "not ok - bad/$(basename $i .json)"; code=1;;
*) echo "ok - bad/$(basename $i .json)";;
esac
count=$((count+1))
done
echo "1..$count"

View File

@ -1,18 +1,28 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
import glob import glob
import os.path import os.path
import subprocess import subprocess
import re import re
## fix paths for running under Wine
def systemise_path(path):
if "@EXEEXT@" == ".exe":
return "Z:%s" % os.path.abspath(path)
return path
SDIR = "@abs_top_srcdir@" SDIR = "@abs_top_srcdir@"
BDIR = "@abs_top_builddir@" BDIR = "@abs_top_builddir@"
TOOL = os.path.join(BDIR, "tools/json-schema") TOOL = os.path.join(BDIR, "tools", "json-schema@EXEEXT@")
RUNNER = os.path.join("@abs_top_srcdir@", "build-aux", "wine-crlf.sh") if "@EXEEXT@" == ".exe" else "/usr/bin/env"
TEST_EXTRACT = re.compile("(.*?)_(\d{4})_(pass|fail).json") TEST_EXTRACT = re.compile("(.*?)_(\d{4})_(pass|fail).json")
SCHEMA_DIR = os.path.join(SDIR, "test/json/schema") SCHEMA_DIR = os.path.join(SDIR, "test", "json", "schema")
SCHEMAS = glob.iglob(os.path.join(SCHEMA_DIR, "*.schema")) SCHEMAS = glob.iglob(os.path.join(SCHEMA_DIR, "*.schema"))
EXPECTED = { EXPECTED = {
@ -22,17 +32,23 @@ EXPECTED = {
print("1..%s" % len(glob.glob(os.path.join(SCHEMA_DIR, "*.json")))) print("1..%s" % len(glob.glob(os.path.join(SCHEMA_DIR, "*.json"))))
code=0
for schema in SCHEMAS: for schema in SCHEMAS:
(name, _) = os.path.splitext(os.path.basename(schema)) (name, _) = os.path.splitext(os.path.basename(schema))
test_glob = name + "_*.json" test_glob = name + "_*.json"
for test in glob.iglob(os.path.join(SCHEMA_DIR, test_glob)): for test in glob.iglob(os.path.join(SCHEMA_DIR, test_glob)):
command = [TOOL, schema, test] command = [RUNNER, TOOL, systemise_path(schema), systemise_path(test)]
(name, seq, success) = TEST_EXTRACT.match(test).groups() (name, seq, success) = TEST_EXTRACT.match(test).groups()
res = subprocess.call(command, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) res = subprocess.call(command, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
if res != EXPECTED[success]: if res != EXPECTED[success]:
print('got res', res)
print('not ok -', os.path.basename(test), '#', ' '.join(command)) print('not ok -', os.path.basename(test), '#', ' '.join(command))
code=1
else: else:
print('ok -', os.path.basename(test)) print('ok -', os.path.basename(test))
sys.exit(code)