Skip to content

Commit d96878e

Browse files
Exit 1 for TokenizerTester/TreeTester if test fail
This change makes TokenizerTester and TreeTester exit with status code 1 if any test cases fail. Otherwise, without this change, we won’t catch the test failures when running tests under CI.
1 parent 62baf8a commit d96878e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

test-src/nu/validator/htmlparser/test/TokenizerTester.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
public class TokenizerTester {
5858

59+
private static int exitStatus = 0;
60+
5961
private static JSONString PLAINTEXT = new JSONString("PLAINTEXT state");
6062

6163
private static JSONString PCDATA = new JSONString("DATA state");
@@ -191,6 +193,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
191193
if (jsonDeepEquals(actualTokens, expectedTokens)) {
192194
writer.write("Success\n");
193195
} else {
196+
exitStatus = 1;
194197
writer.write("Failure\n");
195198
writer.write(description);
196199
writer.write("\nInput:\n");
@@ -202,6 +205,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
202205
writer.write("\n");
203206
}
204207
} catch (Throwable t) {
208+
exitStatus = 1;
205209
writer.write("Failure\n");
206210
writer.write(description);
207211
writer.write("\nInput:\n");
@@ -254,6 +258,7 @@ public static void main(String[] args) throws Throwable {
254258
tester.test(file.getPath().toString());
255259
}
256260
}
261+
System.exit(exitStatus);
257262
}
258263

259264
}

test-src/nu/validator/htmlparser/test/TreeTester.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class TreeTester {
4444

4545
private boolean streaming = false;
4646

47+
private static int exitStatus = 0;
48+
4749
/**
4850
* @param aggregateStream
4951
*/
@@ -229,6 +231,7 @@ private boolean runTest() throws Throwable {
229231
System.err.println("Success.");
230232
// System.err.println(stream);
231233
} else {
234+
exitStatus = 1;
232235
System.err.print("Failure.\nData:\n" + stream + "\nExpected:\n"
233236
+ expected + "Got: \n" + actual);
234237
System.err.println("Expected errors:");
@@ -241,6 +244,7 @@ private boolean runTest() throws Throwable {
241244
}
242245
}
243246
} catch (Throwable t) {
247+
exitStatus = 1;
244248
System.err.println("Failure.\nData:\n" + stream);
245249
throw t;
246250
}
@@ -292,6 +296,7 @@ public static void main(String[] args) throws Throwable {
292296
tester.runTests(file.getPath().toString());
293297
}
294298
}
299+
System.exit(exitStatus);
295300
}
296301

297302
}

0 commit comments

Comments
 (0)