Skip to content

Commit cec3848

Browse files
Exit 1 for testharness if any tests fail
This change makes TokenizerTester, TreeTester, and EncodingTester 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 e6b0314 commit cec3848

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
public class EncodingTester {
3838

39+
protected static int SNIFFING_LIMIT = 16384;
40+
41+
private static int exitStatus = 0;
42+
3943
private final InputStream aggregateStream;
4044

4145
private final StringBuilder builder = new StringBuilder();
@@ -63,6 +67,7 @@ private boolean runTest() throws IOException, SAXException {
6367
Charset charset = reader.getCharset();
6468
stream.close();
6569
if (skipLabel()) {
70+
exitStatus = 1;
6671
System.err.println("Premature end of test data.");
6772
return false;
6873
}
@@ -73,6 +78,7 @@ private boolean runTest() throws IOException, SAXException {
7378
case '\n':
7479
break loop;
7580
case -1:
81+
exitStatus = 1;
7682
System.err.println("Premature end of test data.");
7783
return false;
7884
default:
@@ -85,6 +91,7 @@ private boolean runTest() throws IOException, SAXException {
8591
System.err.println("Success.");
8692
// System.err.println(stream);
8793
} else {
94+
exitStatus = 1;
8895
System.err.println("Failure. Expected: " + expected + " got "
8996
+ sniffed + ".");
9097
System.err.println(stream);
@@ -118,6 +125,7 @@ public static void main(String[] args) throws IOException, SAXException {
118125
args[i]));
119126
tester.runTests();
120127
}
128+
System.exit(exitStatus);
121129
}
122130

123131
}

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)