Skip to content

Commit 99d4827

Browse files
Make Html5libTest only check .dat and .test files
This change refines how Html5libTest handles filenames; it adds a mechanism to allow a required/expected file extension to be specified for each test type, and uses the mechanism to specify that ".test" is the required/expected extension for tokenizer tests, and that ".dat" is the required/expected extension for tree-construction test files and for encoding test files. Without this change, Html5libTest only deals correctly with the ".test" extension for tokenizer test files — but not with the ".dat" extension for tree-construction test files and encoding test files.
1 parent dac0141 commit 99d4827

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Html5libTest() throws URISyntaxException {
4242

4343
public void testEncoding() throws Exception {
4444
Files.walkFileTree(testDir.resolve("encoding"), //
45-
new TestVisitor(true, false, file -> //
45+
new TestVisitor(true, ".dat", file -> //
4646
new EncodingTester(Files.newInputStream(file)).runTests()));
4747
if (EncodingTester.exitStatus != 0) {
4848
assert false : "Encoding test failed";
@@ -51,7 +51,7 @@ public void testEncoding() throws Exception {
5151

5252
public void testTokenizer() throws Exception {
5353
Files.walkFileTree(testDir.resolve("tokenizer"),
54-
new TestVisitor(true, true, file -> //
54+
new TestVisitor(true, ".test", file -> //
5555
new TokenizerTester(Files.newInputStream(file)).runTests()));
5656
if (TokenizerTester.exitStatus != 0) {
5757
assert false : "Tokenizer test failed";
@@ -60,7 +60,7 @@ public void testTokenizer() throws Exception {
6060

6161
public void testTree() throws Exception {
6262
Files.walkFileTree(testDir.resolve("tree-construction"),
63-
new TestVisitor(true, false, file -> //
63+
new TestVisitor(true, ".dat", file -> //
6464
new TreeTester(Files.newInputStream(file)).runTests()));
6565
if (TreeTester.exitStatus != 0) {
6666
assert false : "Tree test failed";
@@ -86,14 +86,14 @@ private static class TestVisitor extends SimpleFileVisitor<Path> {
8686

8787
private final boolean skipScripted;
8888

89-
private final boolean requireTestExtension;
89+
private final String requiredTestExtension;
9090

9191
private final TestConsumer runner;
9292

93-
private TestVisitor(boolean skipScripted, boolean requireTestExtension,
93+
private TestVisitor(boolean skipScripted, String requiredTestExtension,
9494
TestConsumer runner) {
9595
this.skipScripted = skipScripted;
96-
this.requireTestExtension = requireTestExtension;
96+
this.requiredTestExtension = requiredTestExtension;
9797
this.runner = runner;
9898
}
9999

@@ -110,8 +110,7 @@ public FileVisitResult preVisitDirectory(Path dir,
110110
@Override
111111
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
112112
throws IOException {
113-
if (!requireTestExtension
114-
|| file.getFileName().toString().endsWith(".test")) {
113+
if (file.getFileName().toString().endsWith(requiredTestExtension)) {
115114
runner.accept(file);
116115
}
117116
return FileVisitResult.CONTINUE;

0 commit comments

Comments
 (0)