|
1 | 1 | package liquidjava.api.tests; |
2 | 2 |
|
3 | 3 | import static liquidjava.utils.TestUtils.*; |
| 4 | + |
4 | 5 | import static org.junit.Assert.fail; |
5 | 6 |
|
6 | 7 | import java.io.IOException; |
|
10 | 11 | import java.util.List; |
11 | 12 | import java.util.Optional; |
12 | 13 | import java.util.stream.Stream; |
| 14 | + |
13 | 15 | import liquidjava.api.CommandLineLauncher; |
14 | 16 | import liquidjava.diagnostics.Diagnostics; |
15 | 17 |
|
16 | 18 | import liquidjava.diagnostics.errors.LJError; |
| 19 | +import liquidjava.utils.TestUtils.Pair; |
| 20 | + |
17 | 21 | import org.junit.Test; |
18 | 22 | import org.junit.jupiter.params.ParameterizedTest; |
19 | 23 | import org.junit.jupiter.params.provider.MethodSource; |
20 | 24 |
|
| 25 | +import liquidjava.diagnostics.ErrorPosition; |
| 26 | + |
21 | 27 | public class TestExamples { |
22 | 28 |
|
23 | 29 | Diagnostics diagnostics = Diagnostics.getInstance(); |
@@ -52,25 +58,26 @@ else if (shouldFail(pathName)) { |
52 | 58 | fail(); |
53 | 59 | } else { |
54 | 60 | // check if expected error was found |
55 | | - List<String> expected = isDirectory ? getExpectedErrorsFromDirectory(path) |
| 61 | + List<Pair> expected = isDirectory ? getExpectedErrorsFromDirectory(path) |
56 | 62 | : getExpectedErrorsFromFile(path); |
57 | 63 | if (diagnostics.getErrors().size() > expected.size()) { |
58 | 64 | System.out.println("Multiple errors found in: " + pathName + " --- expected exactly " |
59 | 65 | + expected.size() + " errors. \n" + diagnostics.getErrorOutput()); |
60 | 66 | fail(); |
61 | 67 | } |
62 | | - LJError error = diagnostics.getErrors().iterator().next(); |
63 | | - if (error.getPosition() == null) { |
64 | | - System.out.println("Error in: " + pathName + " --- error has no position information. \n" |
65 | | - + diagnostics.getErrorOutput()); |
66 | | - fail(); |
67 | | - } |
68 | 68 | if (!expected.isEmpty()) { |
69 | | - String foundError = error.getTitle(); |
70 | | - if (!expected.contains(foundError)) { |
71 | | - System.out.println("Error in: " + pathName + " --- expected errors: " + expected |
72 | | - + ", but found: " + foundError + ". \n" + diagnostics.getErrorOutput()); |
73 | | - fail(); |
| 69 | + for (LJError e : diagnostics.getErrors()) { |
| 70 | + String foundError = e.getTitle(); |
| 71 | + int errorPosition = e.getPosition().lineStart(); |
| 72 | + boolean match = expected.stream().anyMatch( |
| 73 | + pair -> pair.errorMessage().equals(foundError) && pair.lineNumber() == errorPosition); |
| 74 | + |
| 75 | + if (!match) { |
| 76 | + System.out.println("Error in: " + pathName + " --- expected errors: " + expected |
| 77 | + + ", but found: " + foundError + " at " + errorPosition + ". \n" |
| 78 | + + diagnostics.getErrorOutput()); |
| 79 | + fail(); |
| 80 | + } |
74 | 81 | } |
75 | 82 | } else { |
76 | 83 | System.out.println("No expected error messages found for: " + pathName); |
|
0 commit comments