Merge branch 'fixup-tests' into 'master' (#1102)

This commit is contained in:
Christopher Dunn 2020-04-24 13:06:44 -05:00
commit 5813ab1bc1
3 changed files with 49 additions and 51 deletions

View File

@ -27,8 +27,13 @@ Then,
#LIB_TYPE=static #LIB_TYPE=static
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE} meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
ninja -v -C build-${LIB_TYPE} ninja -v -C build-${LIB_TYPE}
cd build-${LIB_TYPE}
meson test --no-rebuild --print-errorlogs ninja -C build-static/ test
# Or
#cd build-${LIB_TYPE}
#meson test --no-rebuild --print-errorlogs
sudo ninja install sudo ninja install
## Building and testing with other build systems ## Building and testing with other build systems

View File

@ -103,5 +103,17 @@ test(
'-B', '-B',
join_paths(meson.current_source_dir(), 'test/runjsontests.py'), join_paths(meson.current_source_dir(), 'test/runjsontests.py'),
jsontestrunner, jsontestrunner,
join_paths(meson.current_source_dir(), 'test/data')] join_paths(meson.current_source_dir(), 'test/data')],
)
test(
'jsonchecker_jsontestrunner',
python,
is_parallel : false,
args : [
'-B',
join_paths(meson.current_source_dir(), 'test/runjsontests.py'),
'--with-json-checker',
jsontestrunner,
join_paths(meson.current_source_dir(), 'test/data')],
workdir : join_paths(meson.current_source_dir(), 'test/data'),
) )

View File

@ -62,6 +62,10 @@ def safeReadFile(path):
except IOError as e: except IOError as e:
return '<File "%s" is missing: %s>' % (path,e) return '<File "%s" is missing: %s>' % (path,e)
class FailError(Exception):
def __init__(self, msg):
super(Exception, self).__init__(msg)
def runAllTests(jsontest_executable_path, input_dir = None, def runAllTests(jsontest_executable_path, input_dir = None,
use_valgrind=False, with_json_checker=False, use_valgrind=False, with_json_checker=False,
writerClass='StyledWriter'): writerClass='StyledWriter'):
@ -69,45 +73,26 @@ def runAllTests(jsontest_executable_path, input_dir = None,
input_dir = os.path.join(os.getcwd(), 'data') input_dir = os.path.join(os.getcwd(), 'data')
tests = glob(os.path.join(input_dir, '*.json')) tests = glob(os.path.join(input_dir, '*.json'))
if with_json_checker: if with_json_checker:
all_test_jsonchecker = glob(os.path.join(input_dir, '../jsonchecker', '*.json')) all_tests = glob(os.path.join(input_dir, '../jsonchecker', '*.json'))
# These tests fail with strict json support, but pass with jsoncpp extra lieniency # These tests fail with strict json support, but pass with JsonCPP's
""" # extra leniency features. When adding a new exclusion to this list,
Failure details: # remember to add the test's number and reasoning here:
* Test ../jsonchecker/fail25.json known = ["fail{}.json".format(n) for n in [
Parsing should have failed: 4, 9, # fail because we allow trailing commas
[" tab character in string "] 7, # fails because we allow commas after close
8, # fails because we allow extra close
* Test ../jsonchecker/fail13.json 10, # fails because we allow extra values after close
Parsing should have failed: 13, # fails because we allow leading zeroes in numbers
{"Numbers cannot have leading zeroes": 013} 18, # fails because we allow deeply nested values
25, # fails because we allow tab characters in strings
* Test ../jsonchecker/fail18.json 27, # fails because we allow string line breaks
Parsing should have failed: ]]
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] test_jsonchecker = [ test for test in all_tests
if os.path.basename(test) not in known]
* Test ../jsonchecker/fail8.json
Parsing should have failed:
["Extra close"]]
* Test ../jsonchecker/fail7.json
Parsing should have failed:
["Comma after the close"],
* Test ../jsonchecker/fail10.json
Parsing should have failed:
{"Extra value after close": true} "misplaced quoted value"
* Test ../jsonchecker/fail27.json
Parsing should have failed:
["line
break"]
"""
known_differences_withjsonchecker = [ "fail25.json", "fail13.json", "fail18.json", "fail8.json",
"fail7.json", "fail10.json", "fail27.json" ]
test_jsonchecker = [ test for test in all_test_jsonchecker if os.path.basename(test) not in known_differences_withjsonchecker ]
else: else:
test_jsonchecker = [] test_jsonchecker = []
failed_tests = [] failed_tests = []
valgrind_path = use_valgrind and VALGRIND_CMD or '' valgrind_path = use_valgrind and VALGRIND_CMD or ''
for input_path in tests + test_jsonchecker: for input_path in tests + test_jsonchecker:
@ -161,10 +146,9 @@ def runAllTests(jsontest_executable_path, input_dir = None,
print() print()
print('Test results: %d passed, %d failed.' % (len(tests)-len(failed_tests), print('Test results: %d passed, %d failed.' % (len(tests)-len(failed_tests),
len(failed_tests))) len(failed_tests)))
return 1 raise FailError(repr(failed_tests))
else: else:
print('All %d tests passed.' % len(tests)) print('All %d tests passed.' % len(tests))
return 0
def main(): def main():
from optparse import OptionParser from optparse import OptionParser
@ -187,24 +171,21 @@ def main():
input_path = os.path.normpath(os.path.abspath(args[1])) input_path = os.path.normpath(os.path.abspath(args[1]))
else: else:
input_path = None input_path = None
status = runAllTests(jsontest_executable_path, input_path, runAllTests(jsontest_executable_path, input_path,
use_valgrind=options.valgrind, use_valgrind=options.valgrind,
with_json_checker=options.with_json_checker, with_json_checker=options.with_json_checker,
writerClass='StyledWriter') writerClass='StyledWriter')
if status: runAllTests(jsontest_executable_path, input_path,
sys.exit(status)
status = runAllTests(jsontest_executable_path, input_path,
use_valgrind=options.valgrind, use_valgrind=options.valgrind,
with_json_checker=options.with_json_checker, with_json_checker=options.with_json_checker,
writerClass='StyledStreamWriter') writerClass='StyledStreamWriter')
if status: runAllTests(jsontest_executable_path, input_path,
sys.exit(status)
status = runAllTests(jsontest_executable_path, input_path,
use_valgrind=options.valgrind, use_valgrind=options.valgrind,
with_json_checker=options.with_json_checker, with_json_checker=options.with_json_checker,
writerClass='BuiltStyledStreamWriter') writerClass='BuiltStyledStreamWriter')
if status:
sys.exit(status)
if __name__ == '__main__': if __name__ == '__main__':
main() try:
main()
except FailError:
sys.exit(1)