2015-03-18 16:08:18 +11:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-04-27 17:13:36 +10:00
|
|
|
import sys
|
2015-03-18 16:08:18 +11:00
|
|
|
import glob
|
|
|
|
import os.path
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
|
2016-04-27 17:13:36 +10:00
|
|
|
## fix paths for running under Wine
|
|
|
|
def systemise_path(path):
|
|
|
|
if "@EXEEXT@" == ".exe":
|
|
|
|
return "Z:%s" % os.path.abspath(path)
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
2015-03-18 16:08:18 +11:00
|
|
|
SDIR = "@abs_top_srcdir@"
|
|
|
|
BDIR = "@abs_top_builddir@"
|
|
|
|
|
2016-04-27 17:13:36 +10:00
|
|
|
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"
|
2015-03-18 16:08:18 +11:00
|
|
|
|
|
|
|
TEST_EXTRACT = re.compile("(.*?)_(\d{4})_(pass|fail).json")
|
|
|
|
|
2016-04-27 17:13:36 +10:00
|
|
|
SCHEMA_DIR = os.path.join(SDIR, "test", "json", "schema")
|
2015-03-18 16:08:18 +11:00
|
|
|
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"))))
|
2016-04-27 17:13:36 +10:00
|
|
|
code=0
|
2015-03-18 16:08:18 +11:00
|
|
|
|
|
|
|
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)):
|
2016-04-27 17:13:36 +10:00
|
|
|
command = [RUNNER, TOOL, systemise_path(schema), systemise_path(test)]
|
|
|
|
|
2015-03-18 16:08:18 +11:00
|
|
|
(name, seq, success) = TEST_EXTRACT.match(test).groups()
|
|
|
|
res = subprocess.call(command, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
|
|
|
|
|
|
|
|
if res != EXPECTED[success]:
|
2016-04-27 17:13:36 +10:00
|
|
|
print('got res', res)
|
2015-03-18 16:08:18 +11:00
|
|
|
print('not ok -', os.path.basename(test), '#', ' '.join(command))
|
2016-04-27 17:13:36 +10:00
|
|
|
code=1
|
2015-03-18 16:08:18 +11:00
|
|
|
else:
|
|
|
|
print('ok -', os.path.basename(test))
|
2016-04-27 17:13:36 +10:00
|
|
|
|
|
|
|
sys.exit(code)
|