Skip to content

Commit 20885c9

Browse files
committed
Improve Test Directory
1 parent a52ec32 commit 20885c9

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Run `./mvnw test` to run all the tests in LiquidJava.
115115

116116
The `TestExamples.java` test runs the Java files and test directories under the `testSuite` directory in `liquidjava-example`.
117117

118+
Test inputs are discovered as follows:
119+
- Top-level Java files are treated as individual test inputs
120+
- Leaf directories are treated as a single test input
121+
118122
Test results are determined by inline diagnostic expectations using comments:
119123

120124
```java

liquidjava-verifier/src/test/java/liquidjava/api/tests/TestExamples.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ private static boolean matches(LJDiagnostic diagnostic, Pair<String, Integer> ex
8686
* Returns the test suite paths to verify
8787
*/
8888
private static Stream<Path> sourcePaths() throws IOException {
89-
return Files.find(Paths.get("../liquidjava-example/src/main/java/testSuite/"), Integer.MAX_VALUE,
90-
(filePath, fileAttr) -> {
91-
String name = filePath.getFileName().toString();
92-
return (fileAttr.isRegularFile() || fileAttr.isDirectory()) && isTestPath(name);
93-
});
89+
Path testSuite = Paths.get("../liquidjava-example/src/main/java/testSuite/");
90+
return Files.find(testSuite, Integer.MAX_VALUE,
91+
(path, attributes) -> attributes.isDirectory() ? isLeafDirectory(path) : attributes.isRegularFile()
92+
&& path.toString().endsWith(".java") && !isLeafDirectory(path.getParent()));
9493
}
9594

96-
private static boolean isTestPath(String path) {
97-
String lowerCasePath = path.toLowerCase();
98-
return lowerCasePath.contains("correct") || lowerCasePath.contains("error")
99-
|| lowerCasePath.contains("warning");
95+
private static boolean isLeafDirectory(Path path) {
96+
try (Stream<Path> children = Files.list(path)) {
97+
return children.noneMatch(Files::isDirectory);
98+
} catch (IOException e) {
99+
return false;
100+
}
100101
}
101102

102103
/**

0 commit comments

Comments
 (0)