|
16 | 16 |
|
17 | 17 | public class TestExamples { |
18 | 18 |
|
| 19 | + /** |
| 20 | + * Test the file at the given path by launching the verifier and checking for errors. The file/directory is expected |
| 21 | + * to be either correct or contain an error based on its name. |
| 22 | + * |
| 23 | + * @param filePath |
| 24 | + * path to the file to test |
| 25 | + */ |
19 | 26 | @ParameterizedTest |
20 | 27 | @MethodSource("fileNameSource") |
21 | 28 | public void testFile(final Path filePath) { |
22 | 29 | String fileName = filePath.getFileName().toString(); |
23 | | - System.out.println("Testing file: " + fileName); |
| 30 | + |
| 31 | + // 1. Run the verifier on the file or package |
| 32 | + ErrorEmitter errorEmitter = CommandLineLauncher.launchTest(filePath.toAbsolutePath().toString()); |
24 | 33 |
|
25 | | - // For Regular Files in the root directory check their name |
26 | | - if (Files.isRegularFile(filePath)) { |
27 | | - ErrorEmitter errorEmitter = CommandLineLauncher.launchTest(filePath.toAbsolutePath().toString()); |
28 | | - System.out.println( |
29 | | - errorEmitter.foundError() ? (errorEmitter.getFullMessage()) : ("Correct! Passed Verification.")); |
30 | | - |
31 | | - if (fileName.startsWith("Correct") && errorEmitter.foundError()) { |
32 | | - System.out.println("Error in directory: " + fileName + " --- should be correct but an error was found"); |
33 | | - fail(); |
34 | | - } |
35 | | - if (fileName.startsWith("Error") && !errorEmitter.foundError()) { |
36 | | - System.out.println("Error in directory: " + fileName + " --- should be an error but passed verification"); |
37 | | - fail(); |
38 | | - } |
39 | | - } else // For Directories and subdirectories check if they contain "error" or "correct" in their name |
40 | | - if (Files.isDirectory(filePath) && (fileName.contains("error") || fileName.contains("correct"))) { |
41 | | - ErrorEmitter errorEmitter = CommandLineLauncher.launchTest(filePath.toAbsolutePath().toString()); |
42 | | - System.out.println( |
43 | | - errorEmitter.foundError() ? (errorEmitter.getFullMessage()) : ("Correct! Passed Verification.")); |
44 | | - |
45 | | - if (fileName.contains("correct") && errorEmitter.foundError()) { |
46 | | - System.out.println("Error in directory: " + fileName + " --- should be correct but an error was found"); |
47 | | - fail(); |
48 | | - } |
49 | | - if (fileName.contains("error") && !errorEmitter.foundError()) { |
50 | | - System.out.println("Error in directory: " + fileName + " --- should be an error but passed verification"); |
51 | | - fail(); |
52 | | - } |
| 34 | + // 2. Check if the file is correct or contains an error |
| 35 | + if ((fileName.startsWith("Correct") && errorEmitter.foundError()) |
| 36 | + || (fileName.contains("correct") && errorEmitter.foundError())) { |
| 37 | + System.out.println("Error in directory: " + fileName + " --- should be correct but an error was found"); |
| 38 | + fail(); |
| 39 | + } |
| 40 | + // 3. Check if the file has an error but passed verification |
| 41 | + if ((fileName.startsWith("Error") && !errorEmitter.foundError()) |
| 42 | + || (fileName.contains("error") && !errorEmitter.foundError())) { |
| 43 | + System.out.println("Error in directory: " + fileName + " --- should be an error but passed verification"); |
| 44 | + fail(); |
53 | 45 | } |
54 | 46 | } |
55 | 47 |
|
| 48 | + /** |
| 49 | + * Returns a Stream of paths to test files in the testSuite directory. These include files with names starting with |
| 50 | + * "Correct" or "Error", and directories containing "correct" or "error". |
| 51 | + * |
| 52 | + * @return Stream of paths to test files |
| 53 | + * |
| 54 | + * @throws IOException |
| 55 | + * if an I/O error occurs or the path does not exist |
| 56 | + */ |
56 | 57 | private static Stream<Path> fileNameSource() throws IOException { |
57 | 58 | return Files.find(Paths.get("../liquidjava-example/src/main/java/testSuite/"), Integer.MAX_VALUE, |
58 | 59 | (filePath, fileAttr) -> { |
59 | | - // Get the parent directory path (root directory) |
60 | | - Path rootDir = Paths.get("../liquidjava-example/src/main/java/testSuite/"); |
61 | | - |
62 | | - // 1. Files only in the root directory |
63 | | - boolean isFileInRootDir = fileAttr.isRegularFile() && filePath.getParent().equals(rootDir); |
| 60 | + String name = filePath.getFileName().toString(); |
| 61 | + // 1. Files that start with "Correct" or "Error" |
| 62 | + boolean isFileStartingWithCorrectOrError = fileAttr.isRegularFile() |
| 63 | + && (name.startsWith("Correct") || name.startsWith("Error")); |
64 | 64 |
|
65 | | - // 2. Directories and subdirectories (recursive search for directories) |
66 | | - boolean isDirectory = fileAttr.isDirectory(); |
| 65 | + // 2. Folders (directories) that contain "correct" or "error" |
| 66 | + boolean isDirectoryWithCorrectOrError = fileAttr.isDirectory() |
| 67 | + && (name.contains("correct") || name.contains("error")); |
67 | 68 |
|
68 | 69 | // Return true if either condition matches |
69 | | - return isFileInRootDir || isDirectory; |
| 70 | + return isFileStartingWithCorrectOrError || isDirectoryWithCorrectOrError; |
70 | 71 | }); |
71 | 72 | } |
72 | 73 | } |
0 commit comments