Catch JSON parse error to provide a unified error reporting in the test runner
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/tests/helper/test-case.js b/tests/helper/test-case.js
index 92a9951..240599e 100644
--- a/tests/helper/test-case.js
+++ b/tests/helper/test-case.js
@@ -121,23 +121,25 @@ module.exports = {
var testCaseSource = fs.readFileSync(filePath, "utf8");
var testCaseParts = testCaseSource.split(/^----*\w*$/m);
- // No expected token stream found
- if (2 > testCaseParts.length) {
- return null;
- }
-
- var testCase = {
- testSource: testCaseParts[0].trim(),
- expectedTokenStream: JSON.parse(testCaseParts[1]),
- comment: null
- };
+ try {
+ var testCase = {
+ testSource: testCaseParts[0].trim(),
+ expectedTokenStream: JSON.parse(testCaseParts[1]),
+ comment: null
+ };
+
+ // if there are three parts, the third one is the comment
+ // explaining the test case
+ if (testCaseParts[2]) {
+ testCase.comment = testCaseParts[2].trim();
+ }
- // if there are three parts, the third one is the comment
- // explaining the test case
- if (testCaseParts[2]) {
- testCase.comment = testCaseParts[2].trim();
+ return testCase;
+ }
+ catch (e)
+ {
+ // the JSON can't be parsed (e.g. it could be empty)
+ return null;
}
-
- return testCase;
}
};