Skip to content

Commit 5813ab1

Browse files
committed
Merge branch 'fixup-tests' into 'master' (open-source-parsers#1102)
2 parents 8b20b7a + a0b8c3e commit 5813ab1

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ Then,
2727
#LIB_TYPE=static
2828
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
2929
ninja -v -C build-${LIB_TYPE}
30-
cd build-${LIB_TYPE}
31-
meson test --no-rebuild --print-errorlogs
30+
31+
ninja -C build-static/ test
32+
33+
# Or
34+
#cd build-${LIB_TYPE}
35+
#meson test --no-rebuild --print-errorlogs
36+
3237
sudo ninja install
3338

3439
## Building and testing with other build systems

meson.build

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,17 @@ test(
103103
'-B',
104104
join_paths(meson.current_source_dir(), 'test/runjsontests.py'),
105105
jsontestrunner,
106-
join_paths(meson.current_source_dir(), 'test/data')]
106+
join_paths(meson.current_source_dir(), 'test/data')],
107+
)
108+
test(
109+
'jsonchecker_jsontestrunner',
110+
python,
111+
is_parallel : false,
112+
args : [
113+
'-B',
114+
join_paths(meson.current_source_dir(), 'test/runjsontests.py'),
115+
'--with-json-checker',
116+
jsontestrunner,
117+
join_paths(meson.current_source_dir(), 'test/data')],
118+
workdir : join_paths(meson.current_source_dir(), 'test/data'),
107119
)

test/runjsontests.py

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,52 +62,37 @@ def safeReadFile(path):
6262
except IOError as e:
6363
return '<File "%s" is missing: %s>' % (path,e)
6464

65+
class FailError(Exception):
66+
def __init__(self, msg):
67+
super(Exception, self).__init__(msg)
68+
6569
def runAllTests(jsontest_executable_path, input_dir = None,
6670
use_valgrind=False, with_json_checker=False,
6771
writerClass='StyledWriter'):
6872
if not input_dir:
6973
input_dir = os.path.join(os.getcwd(), 'data')
7074
tests = glob(os.path.join(input_dir, '*.json'))
7175
if with_json_checker:
72-
all_test_jsonchecker = glob(os.path.join(input_dir, '../jsonchecker', '*.json'))
73-
# These tests fail with strict json support, but pass with jsoncpp extra lieniency
74-
"""
75-
Failure details:
76-
* Test ../jsonchecker/fail25.json
77-
Parsing should have failed:
78-
[" tab character in string "]
79-
80-
* Test ../jsonchecker/fail13.json
81-
Parsing should have failed:
82-
{"Numbers cannot have leading zeroes": 013}
83-
84-
* Test ../jsonchecker/fail18.json
85-
Parsing should have failed:
86-
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
87-
88-
* Test ../jsonchecker/fail8.json
89-
Parsing should have failed:
90-
["Extra close"]]
91-
92-
* Test ../jsonchecker/fail7.json
93-
Parsing should have failed:
94-
["Comma after the close"],
95-
96-
* Test ../jsonchecker/fail10.json
97-
Parsing should have failed:
98-
{"Extra value after close": true} "misplaced quoted value"
99-
100-
* Test ../jsonchecker/fail27.json
101-
Parsing should have failed:
102-
["line
103-
break"]
104-
"""
105-
known_differences_withjsonchecker = [ "fail25.json", "fail13.json", "fail18.json", "fail8.json",
106-
"fail7.json", "fail10.json", "fail27.json" ]
107-
test_jsonchecker = [ test for test in all_test_jsonchecker if os.path.basename(test) not in known_differences_withjsonchecker ]
76+
all_tests = glob(os.path.join(input_dir, '../jsonchecker', '*.json'))
77+
# These tests fail with strict json support, but pass with JsonCPP's
78+
# extra leniency features. When adding a new exclusion to this list,
79+
# remember to add the test's number and reasoning here:
80+
known = ["fail{}.json".format(n) for n in [
81+
4, 9, # fail because we allow trailing commas
82+
7, # fails because we allow commas after close
83+
8, # fails because we allow extra close
84+
10, # fails because we allow extra values after close
85+
13, # fails because we allow leading zeroes in numbers
86+
18, # fails because we allow deeply nested values
87+
25, # fails because we allow tab characters in strings
88+
27, # fails because we allow string line breaks
89+
]]
90+
test_jsonchecker = [ test for test in all_tests
91+
if os.path.basename(test) not in known]
10892

10993
else:
11094
test_jsonchecker = []
95+
11196
failed_tests = []
11297
valgrind_path = use_valgrind and VALGRIND_CMD or ''
11398
for input_path in tests + test_jsonchecker:
@@ -161,10 +146,9 @@ def runAllTests(jsontest_executable_path, input_dir = None,
161146
print()
162147
print('Test results: %d passed, %d failed.' % (len(tests)-len(failed_tests),
163148
len(failed_tests)))
164-
return 1
149+
raise FailError(repr(failed_tests))
165150
else:
166151
print('All %d tests passed.' % len(tests))
167-
return 0
168152

169153
def main():
170154
from optparse import OptionParser
@@ -187,24 +171,21 @@ def main():
187171
input_path = os.path.normpath(os.path.abspath(args[1]))
188172
else:
189173
input_path = None
190-
status = runAllTests(jsontest_executable_path, input_path,
174+
runAllTests(jsontest_executable_path, input_path,
191175
use_valgrind=options.valgrind,
192176
with_json_checker=options.with_json_checker,
193177
writerClass='StyledWriter')
194-
if status:
195-
sys.exit(status)
196-
status = runAllTests(jsontest_executable_path, input_path,
178+
runAllTests(jsontest_executable_path, input_path,
197179
use_valgrind=options.valgrind,
198180
with_json_checker=options.with_json_checker,
199181
writerClass='StyledStreamWriter')
200-
if status:
201-
sys.exit(status)
202-
status = runAllTests(jsontest_executable_path, input_path,
182+
runAllTests(jsontest_executable_path, input_path,
203183
use_valgrind=options.valgrind,
204184
with_json_checker=options.with_json_checker,
205185
writerClass='BuiltStyledStreamWriter')
206-
if status:
207-
sys.exit(status)
208186

209187
if __name__ == '__main__':
210-
main()
188+
try:
189+
main()
190+
except FailError:
191+
sys.exit(1)

0 commit comments

Comments
 (0)