Skip to content

Commit c01d841

Browse files
Exit 1 for test harness 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 54f317b commit c01d841

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

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

3737
public class EncodingTester {
3838

39+
private static int exitStatus = 0;
40+
3941
private final InputStream aggregateStream;
4042

4143
private final StringBuilder builder = new StringBuilder();
@@ -63,6 +65,7 @@ private boolean runTest() throws IOException, SAXException {
6365
Charset charset = reader.getCharset();
6466
stream.close();
6567
if (skipLabel()) {
68+
exitStatus = 1;
6669
System.err.println("Premature end of test data.");
6770
return false;
6871
}
@@ -73,6 +76,7 @@ private boolean runTest() throws IOException, SAXException {
7376
case '\n':
7477
break loop;
7578
case -1:
79+
exitStatus = 1;
7680
System.err.println("Premature end of test data.");
7781
return false;
7882
default:
@@ -85,6 +89,7 @@ private boolean runTest() throws IOException, SAXException {
8589
System.err.println("Success.");
8690
// System.err.println(stream);
8791
} else {
92+
exitStatus = 1;
8893
System.err.println("Failure. Expected: " + expected + " got "
8994
+ sniffed + ".");
9095
System.err.println(stream);
@@ -118,6 +123,7 @@ public static void main(String[] args) throws IOException, SAXException {
118123
args[i]));
119124
tester.runTests();
120125
}
126+
System.exit(exitStatus);
121127
}
122128

123129
}

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

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

5252
public class TokenizerTester {
5353

54+
private static int exitStatus = 0;
55+
5456
private static JSONString PLAINTEXT = new JSONString("PLAINTEXT state");
5557

5658
private static JSONString PCDATA = new JSONString("Data state");
@@ -182,6 +184,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
182184
if (jsonDeepEquals(actualTokens, expectedTokens)) {
183185
writer.write("Success\n");
184186
} else {
187+
exitStatus = 1;
185188
writer.write("Failure\n");
186189
writer.write(description);
187190
writer.write("\nInput:\n");
@@ -193,6 +196,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
193196
writer.write("\n");
194197
}
195198
} catch (Throwable t) {
199+
exitStatus = 1;
196200
writer.write("Failure\n");
197201
writer.write(description);
198202
writer.write("\nInput:\n");
@@ -216,6 +220,7 @@ public static void main(String[] args) throws TokenStreamException,
216220
args[i]));
217221
tester.runTests();
218222
}
223+
System.exit(exitStatus);
219224
}
220225

221226
}

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

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

4444
private boolean streaming = false;
4545

46+
private static int exitStatus = 0;
47+
4648
/**
4749
* @param aggregateStream
4850
*/
@@ -224,6 +226,7 @@ private boolean runTest() throws Throwable {
224226
System.err.println("Success.");
225227
// System.err.println(stream);
226228
} else {
229+
exitStatus = 1;
227230
System.err.print("Failure.\nData:\n" + stream + "\nExpected:\n"
228231
+ expected + "Got: \n" + actual);
229232
System.err.println("Expected errors:");
@@ -236,6 +239,7 @@ private boolean runTest() throws Throwable {
236239
}
237240
}
238241
} catch (Throwable t) {
242+
exitStatus = 1;
239243
System.err.println("Failure.\nData:\n" + stream);
240244
throw t;
241245
}
@@ -266,6 +270,7 @@ public static void main(String[] args) throws Throwable {
266270
TreeTester tester = new TreeTester(new FileInputStream(args[i]));
267271
tester.runTests();
268272
}
273+
System.exit(exitStatus);
269274
}
270275

271276
}

0 commit comments

Comments
 (0)