Skip to content

Commit c4571cf

Browse files
sideshowbarkerhsivonen
authored andcommitted
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 11dbb0d commit c4571cf

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();
@@ -64,6 +66,7 @@ private boolean runTest() throws IOException, SAXException {
6466
Charset charset = reader.getCharset();
6567
stream.close();
6668
if (skipLabel()) {
69+
exitStatus = 1;
6770
System.err.println("Premature end of test data.");
6871
return false;
6972
}
@@ -74,6 +77,7 @@ private boolean runTest() throws IOException, SAXException {
7477
case '\n':
7578
break loop;
7679
case -1:
80+
exitStatus = 1;
7781
System.err.println("Premature end of test data.");
7882
return false;
7983
default:
@@ -86,6 +90,7 @@ private boolean runTest() throws IOException, SAXException {
8690
System.err.println("Success.");
8791
// System.err.println(stream);
8892
} else {
93+
exitStatus = 1;
8994
System.err.println("Failure. Expected: " + expected + " got "
9095
+ sniffed + ".");
9196
System.err.println(stream);
@@ -119,6 +124,7 @@ public static void main(String[] args) throws IOException, SAXException {
119124
args[i]));
120125
tester.runTests();
121126
}
127+
System.exit(exitStatus);
122128
}
123129

124130
}

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

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

5656
public class TokenizerTester {
5757

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

6062
private static JSONString PCDATA = new JSONString("Data state");
@@ -192,6 +194,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
192194
if (jsonDeepEquals(actualTokens, expectedTokens)) {
193195
writer.write("Success\n");
194196
} else {
197+
exitStatus = 1;
195198
writer.write("Failure\n");
196199
writer.write(description);
197200
writer.write("\nInput:\n");
@@ -203,6 +206,7 @@ private void runTestInner(String inputString, JSONArray expectedTokens,
203206
writer.write("\n");
204207
}
205208
} catch (Throwable t) {
209+
exitStatus = 1;
206210
writer.write("Failure\n");
207211
writer.write(description);
208212
writer.write("\nInput:\n");
@@ -230,6 +234,7 @@ public static void main(String[] args) throws TokenStreamException,
230234
TokenizerTester tester = new TokenizerTester(bais);
231235
tester.runTests();
232236
}
237+
System.exit(exitStatus);
233238
}
234239

235240
}

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
*/
@@ -228,6 +230,7 @@ private boolean runTest() throws Throwable {
228230
System.err.println("Success.");
229231
// System.err.println(stream);
230232
} else {
233+
exitStatus = 1;
231234
System.err.print("Failure.\nData:\n" + stream + "\nExpected:\n"
232235
+ expected + "Got: \n" + actual);
233236
System.err.println("Expected errors:");
@@ -240,6 +243,7 @@ private boolean runTest() throws Throwable {
240243
}
241244
}
242245
} catch (Throwable t) {
246+
exitStatus = 1;
243247
System.err.println("Failure.\nData:\n" + stream);
244248
throw t;
245249
}
@@ -270,6 +274,7 @@ public static void main(String[] args) throws Throwable {
270274
TreeTester tester = new TreeTester(new FileInputStream(args[i]));
271275
tester.runTests();
272276
}
277+
System.exit(exitStatus);
273278
}
274279

275280
}

0 commit comments

Comments
 (0)