@@ -62,52 +62,37 @@ def safeReadFile(path):
62
62
except IOError as e :
63
63
return '<File "%s" is missing: %s>' % (path ,e )
64
64
65
+ class FailError (Exception ):
66
+ def __init__ (self , msg ):
67
+ super (Exception , self ).__init__ (msg )
68
+
65
69
def runAllTests (jsontest_executable_path , input_dir = None ,
66
70
use_valgrind = False , with_json_checker = False ,
67
71
writerClass = 'StyledWriter' ):
68
72
if not input_dir :
69
73
input_dir = os .path .join (os .getcwd (), 'data' )
70
74
tests = glob (os .path .join (input_dir , '*.json' ))
71
75
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 ]
108
92
109
93
else :
110
94
test_jsonchecker = []
95
+
111
96
failed_tests = []
112
97
valgrind_path = use_valgrind and VALGRIND_CMD or ''
113
98
for input_path in tests + test_jsonchecker :
@@ -161,10 +146,9 @@ def runAllTests(jsontest_executable_path, input_dir = None,
161
146
print ()
162
147
print ('Test results: %d passed, %d failed.' % (len (tests )- len (failed_tests ),
163
148
len (failed_tests )))
164
- return 1
149
+ raise FailError ( repr ( failed_tests ))
165
150
else :
166
151
print ('All %d tests passed.' % len (tests ))
167
- return 0
168
152
169
153
def main ():
170
154
from optparse import OptionParser
@@ -187,24 +171,21 @@ def main():
187
171
input_path = os .path .normpath (os .path .abspath (args [1 ]))
188
172
else :
189
173
input_path = None
190
- status = runAllTests (jsontest_executable_path , input_path ,
174
+ runAllTests (jsontest_executable_path , input_path ,
191
175
use_valgrind = options .valgrind ,
192
176
with_json_checker = options .with_json_checker ,
193
177
writerClass = 'StyledWriter' )
194
- if status :
195
- sys .exit (status )
196
- status = runAllTests (jsontest_executable_path , input_path ,
178
+ runAllTests (jsontest_executable_path , input_path ,
197
179
use_valgrind = options .valgrind ,
198
180
with_json_checker = options .with_json_checker ,
199
181
writerClass = 'StyledStreamWriter' )
200
- if status :
201
- sys .exit (status )
202
- status = runAllTests (jsontest_executable_path , input_path ,
182
+ runAllTests (jsontest_executable_path , input_path ,
203
183
use_valgrind = options .valgrind ,
204
184
with_json_checker = options .with_json_checker ,
205
185
writerClass = 'BuiltStyledStreamWriter' )
206
- if status :
207
- sys .exit (status )
208
186
209
187
if __name__ == '__main__' :
210
- main ()
188
+ try :
189
+ main ()
190
+ except FailError :
191
+ sys .exit (1 )
0 commit comments