From b814c83e21dd2a90d0a6a9a086c487db14a79b1e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 27 Apr 2016 17:13:36 +1000 Subject: [PATCH] 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. --- .gitignore | 1 - build-aux/.gitignore | 8 ++++++ build-aux/wine-crlf.sh | 16 +++++++++++ configure.ac | 4 +-- test/json-parse.in | 27 ------------------- test/json-parse.sh.in | 31 ++++++++++++++++++++++ test/{json-schema.in => json-schema.py.in} | 22 ++++++++++++--- 7 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 build-aux/.gitignore create mode 100755 build-aux/wine-crlf.sh delete mode 100755 test/json-parse.in create mode 100755 test/json-parse.sh.in rename test/{json-schema.in => json-schema.py.in} (61%) diff --git a/.gitignore b/.gitignore index d3f21741..6bb74d77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /aclocal.m4 /autom4te.cache/ -/build-aux/ /compile /config.* /configure diff --git a/build-aux/.gitignore b/build-aux/.gitignore new file mode 100644 index 00000000..a10c25f5 --- /dev/null +++ b/build-aux/.gitignore @@ -0,0 +1,8 @@ +/compile +/config.guess +/config.sub +/depcomp +/install-sh +/ltmain.sh +/missing +/test-driver diff --git a/build-aux/wine-crlf.sh b/build-aux/wine-crlf.sh new file mode 100755 index 00000000..1871d838 --- /dev/null +++ b/build-aux/wine-crlf.sh @@ -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 diff --git a/configure.ac b/configure.ac index de6e39b2..6012bce0 100644 --- a/configure.ac +++ b/configure.ac @@ -132,7 +132,7 @@ AC_CONFIG_FILES([ Makefile ]) -AC_CONFIG_FILES([test/json-parse], [chmod a+x test/json-parse]) -AC_CONFIG_FILES([test/json-schema], [chmod a+x test/json-schema]) +AC_CONFIG_FILES([test/json-parse.sh], [chmod a+x test/json-parse.sh]) +AC_CONFIG_FILES([test/json-schema.py], [chmod a+x test/json-schema.py]) AC_OUTPUT diff --git a/test/json-parse.in b/test/json-parse.in deleted file mode 100755 index f0525499..00000000 --- a/test/json-parse.in +++ /dev/null @@ -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 diff --git a/test/json-parse.sh.in b/test/json-parse.sh.in new file mode 100755 index 00000000..f9a9792f --- /dev/null +++ b/test/json-parse.sh.in @@ -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" diff --git a/test/json-schema.in b/test/json-schema.py.in similarity index 61% rename from test/json-schema.in rename to test/json-schema.py.in index 6e8ffd86..bdcbeb42 100644 --- a/test/json-schema.in +++ b/test/json-schema.py.in @@ -1,18 +1,28 @@ #!/usr/bin/env python3 +import sys import glob import os.path import subprocess 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@" 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") -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")) EXPECTED = { @@ -22,17 +32,23 @@ EXPECTED = { print("1..%s" % len(glob.glob(os.path.join(SCHEMA_DIR, "*.json")))) +code=0 for schema in SCHEMAS: (name, _) = os.path.splitext(os.path.basename(schema)) test_glob = name + "_*.json" 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() res = subprocess.call(command, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) if res != EXPECTED[success]: + print('got res', res) print('not ok -', os.path.basename(test), '#', ' '.join(command)) + code=1 else: print('ok -', os.path.basename(test)) + +sys.exit(code)