libcruft-util/test/json-schema.py.in
Danny Robson b814c83e21 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.
2016-04-27 17:13:36 +10:00

55 lines
1.4 KiB
Python

#!/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@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")
SCHEMAS = glob.iglob(os.path.join(SCHEMA_DIR, "*.schema"))
EXPECTED = {
"pass": 0,
"fail": 1
}
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 = [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)