Skip to content

Commit 8af60de

Browse files
committed
Parse all existing files with new parser and report failures, successes, and rate
1 parent 7c97836 commit 8af60de

File tree

4 files changed

+135
-5
lines changed

4 files changed

+135
-5
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
<version>4.13.2</version>
105105
<scope>test</scope>
106106
</dependency>
107+
<dependency>
108+
<groupId>commons-io</groupId>
109+
<artifactId>commons-io</artifactId>
110+
<version>2.11.0</version>
111+
<scope>test</scope>
112+
</dependency>
107113
</dependencies>
108114
<build>
109115
<defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check spotbugs:check javadoc:javadoc</defaultGoal>

src/main/java/com/tupilabs/tap4j/Tap13Parser.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Rule TestSet() {
7777

7878
Rule Version() {
7979
return Sequence(
80-
String("TAP Version 13"),
80+
IgnoreCase("TAP Version 13"),
8181
EOL
8282
).label("Version");
8383
}
@@ -309,10 +309,6 @@ public ParsingResult<Object> parse(String input) throws IOException {
309309

310310
// --- main method for testing
311311

312-
private static void parse(Path file) {
313-
314-
}
315-
316312
public static void main(String[] args) throws IOException {
317313
String input = Files.readString(Path.of("/home/kinow/Development/java/workspace/tap4j/src/test/resources/org/tap4j/parser/issueFalseDupPlan/ihavetodoes.tap"));
318314
Tap13Parser parser = new Tap13Parser();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 tap4j team (see AUTHORS)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package com.tupilabs.tap4j;
25+
26+
import org.apache.commons.io.FileUtils;
27+
import org.junit.Test;
28+
import org.parboiled.common.Predicates;
29+
import org.parboiled.support.Filters;
30+
import org.parboiled.support.ParsingResult;
31+
import org.parboiled.support.ToStringFormatter;
32+
33+
import java.io.File;
34+
import java.io.IOException;
35+
import java.nio.file.Files;
36+
import java.nio.file.Path;
37+
import java.util.Collection;
38+
import java.util.List;
39+
40+
import static org.parboiled.errors.ErrorUtils.printParseErrors;
41+
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
42+
import static org.parboiled.trees.GraphUtils.printTree;
43+
44+
/**
45+
* Test created to verify compatibility of new PEG parser with all
46+
* existing files in the test area.
47+
*
48+
* <p>Some files may have to be skipped if some feature is dropped
49+
* in the new parser, or if the file is used for bogus testing.</p>
50+
*
51+
* @since 5.0.0
52+
*/
53+
public class AllFilesTest {
54+
55+
private static void parse(Path path, boolean verbose) throws IOException {
56+
final String tapStream = Files.readString(path);
57+
Tap13Parser parser = new Tap13Parser();
58+
ParsingResult<Object> parsingResult = parser.parse(tapStream);
59+
if (parsingResult.hasErrors()) {
60+
if (verbose) {
61+
System.err.println("\n--- ParseErrors ---\n");
62+
// System.err.println(StringUtils.join(parsingResult.parseErrors, "---\n"));
63+
System.err.println(printParseErrors(parsingResult));
64+
System.err.println("\n--- ParseTree ---\n");
65+
System.err.println(printNodeTree(parsingResult, Filters.SKIP_EMPTY_OPTS_AND_ZOMS, Predicates.alwaysTrue()));
66+
}
67+
throw new RuntimeException("Errors parsing TAP file");
68+
} else if (!parsingResult.matched) {
69+
throw new RuntimeException("No match!");
70+
}
71+
if (verbose) {
72+
System.out.println("\n--- ParseTree ---\n");
73+
String tree = printTree(
74+
parsingResult.parseTreeRoot,
75+
new ToStringFormatter<>(),
76+
Filters.SKIP_EMPTY_OPTS_AND_ZOMS,
77+
Predicates.alwaysTrue()
78+
);
79+
System.out.println(tree);
80+
}
81+
}
82+
83+
@Test
84+
public void testAll() {
85+
final String directory = AllFilesTest.class.getResource("/org/tap4j/").getFile();
86+
Collection<File> files = FileUtils.listFiles(new File(directory), new String[] {"tap", "t"}, true);
87+
int failed = 0;
88+
int total = files.size();
89+
for (File file: files) {
90+
try {
91+
parse(Path.of(file.getAbsolutePath()), false);
92+
System.out.printf("success [%s]%n", file.getAbsoluteFile());
93+
} catch (IOException|RuntimeException e) {
94+
System.err.printf("failed [%s]%n", file.getAbsoluteFile());
95+
failed++;
96+
}
97+
}
98+
System.out.printf("%.2f%% - failed [%d] success [%d] total [%d] %n", ((float) (total - failed) / total) * 100, failed, total - failed, total);
99+
}
100+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 tap4j team (see AUTHORS)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
/**
26+
* Tests.
27+
*/
28+
package com.tupilabs.tap4j;

0 commit comments

Comments
 (0)