Commit 9ce5838a4f8812462d2f664ee7b68d32c01ebe1b

Jannik Zschiesche 2015-07-14T10:51:35

Catch JSON parse error to provide a unified error reporting in the test runner

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;
 	}
 };