|
4 | 4 | import edu.hm.hafner.analysis.Severity; |
5 | 5 | import edu.hm.hafner.analysis.assertions.SoftAssertions; |
6 | 6 | import edu.hm.hafner.analysis.registry.AbstractParserTest; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | +import org.junit.jupiter.params.ParameterizedTest; |
| 9 | +import org.junit.jupiter.params.provider.ValueSource; |
7 | 10 |
|
8 | 11 | /** |
9 | 12 | * Tests the class {@link CMakeParser}. |
@@ -68,6 +71,135 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti |
68 | 71 | .hasFileName("unlikely.cmake"); |
69 | 72 | } |
70 | 73 |
|
| 74 | + @ParameterizedTest |
| 75 | + @ValueSource( |
| 76 | + strings = { |
| 77 | + "-- Build files have been written to: C:/workspace/build", |
| 78 | + "22>-- Build files have been written to: C:/workspace/build", |
| 79 | + "[timestamp] C/C++: -- Build files have been written to: C:/workspace/build", |
| 80 | + "make[1]: Entering directory 'C:/workspace/build'", |
| 81 | + "make[1]: Leaving directory 'C:/workspace/build'", |
| 82 | + "-- Build files have an unrelated message", |
| 83 | + "Entering directory without a valid path" |
| 84 | + }) |
| 85 | + void shouldIgnoreBuildDirectoryMessages(final String directoryMessage) { |
| 86 | + var report = parseStringContent(directoryMessage + """ |
| 87 | +
|
| 88 | + CMake Warning at subproject/CMakeLists.txt:14 (message): |
| 89 | + Configure warning |
| 90 | + """); |
| 91 | + |
| 92 | + try (var softly = new SoftAssertions()) { |
| 93 | + softly.assertThat(report).hasSize(1).doesNotHaveErrors(); |
| 94 | + softly.assertThat(report.get(0)) |
| 95 | + .hasFileName("subproject/CMakeLists.txt") |
| 96 | + .hasPath("-") |
| 97 | + .hasLineStart(14) |
| 98 | + .hasMessage("Configure warning"); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + void shouldPreserveAbsoluteSourcePaths() { |
| 104 | + var report = parseStringContent(""" |
| 105 | + -- Build files have been written to: C:/workspace/build |
| 106 | + CMake Warning at C:/workspace/source/cmake/options.cmake:7 (message): |
| 107 | + Warning with an absolute source path |
| 108 | + """); |
| 109 | + |
| 110 | + try (var softly = new SoftAssertions()) { |
| 111 | + softly.assertThat(report).hasSize(1).doesNotHaveErrors(); |
| 112 | + softly.assertThat(report.get(0)) |
| 113 | + .hasFileName("C:/workspace/source/cmake/options.cmake") |
| 114 | + .hasLineStart(7) |
| 115 | + .hasMessage("Warning with an absolute source path"); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + void shouldNotCarryDirectoriesBetweenProjects() { |
| 121 | + var report = parseStringContent(""" |
| 122 | + make: Entering directory 'C:/workspace/build' |
| 123 | + -- Build files have been written to: C:/workspace/build/external |
| 124 | + CMake Warning at external/CMakeLists.txt:3 (message): |
| 125 | + External warning |
| 126 | + make: Leaving directory 'C:/workspace/build' |
| 127 | + -- Build files have been written to: C:/workspace/build/root |
| 128 | + CMake Warning at CMakeLists.txt:9 (message): |
| 129 | + Root warning |
| 130 | + """); |
| 131 | + |
| 132 | + try (var softly = new SoftAssertions()) { |
| 133 | + softly.assertThat(report).hasSize(2).doesNotHaveErrors(); |
| 134 | + softly.assertThat(report.get(0)) |
| 135 | + .hasFileName("external/CMakeLists.txt") |
| 136 | + .hasMessage("External warning"); |
| 137 | + softly.assertThat(report.get(1)).hasFileName("CMakeLists.txt").hasMessage("Root warning"); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + void shouldReadPrefixedMultilineMessages() { |
| 143 | + var report = parseStringContent(""" |
| 144 | + [step] CMake Warning at CMakeLists.txt:9 (message): |
| 145 | + [step] First line |
| 146 | + [step] |
| 147 | + [step] A wrapped explanation, continued |
| 148 | + [step] on another line. |
| 149 | + [step] |
| 150 | + [step] CMake Warning at nested/CMakeLists.txt:4 (message): |
| 151 | + [step] Next warning |
| 152 | + """); |
| 153 | + |
| 154 | + try (var softly = new SoftAssertions()) { |
| 155 | + softly.assertThat(report).hasSize(2).doesNotHaveErrors(); |
| 156 | + softly.assertThat(report.get(0)).hasFileName("CMakeLists.txt").hasMessage(""" |
| 157 | + First line |
| 158 | +
|
| 159 | + A wrapped explanation, continued |
| 160 | + on another line."""); |
| 161 | + softly.assertThat(report.get(1)) |
| 162 | + .hasFileName("nested/CMakeLists.txt") |
| 163 | + .hasMessage("Next warning"); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + void shouldExcludeCallStackFromMessage() { |
| 169 | + var report = parseStringContent(""" |
| 170 | + CMake Warning at CMakeLists.txt:14 (message): |
| 171 | + Warning raised by the nested project |
| 172 | + Call Stack (most recent call first): |
| 173 | + external-project/CMakeLists.txt:4 (include) |
| 174 | + CMakeLists.txt:38 (ExternalProject_Add) |
| 175 | + CMake Warning at after.cmake:3 (message): |
| 176 | + Warning after the call stack |
| 177 | + """); |
| 178 | + |
| 179 | + try (var softly = new SoftAssertions()) { |
| 180 | + softly.assertThat(report).hasSize(2).doesNotHaveErrors(); |
| 181 | + softly.assertThat(report.get(0)) |
| 182 | + .hasFileName("CMakeLists.txt") |
| 183 | + .hasMessage("Warning raised by the nested project"); |
| 184 | + softly.assertThat(report.get(1)).hasFileName("after.cmake").hasMessage("Warning after the call stack"); |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + void shouldNotConsumeWarningAfterEmptyMessage() { |
| 190 | + var report = parseStringContent(""" |
| 191 | + CMake Warning at empty.cmake:3 (message): |
| 192 | + CMake Warning at after.cmake:4 (message): |
| 193 | + Next warning |
| 194 | + """); |
| 195 | + |
| 196 | + try (var softly = new SoftAssertions()) { |
| 197 | + softly.assertThat(report).hasSize(2).doesNotHaveErrors(); |
| 198 | + softly.assertThat(report.get(0)).hasFileName("empty.cmake").hasMessage(""); |
| 199 | + softly.assertThat(report.get(1)).hasFileName("after.cmake").hasMessage("Next warning"); |
| 200 | + } |
| 201 | + } |
| 202 | + |
71 | 203 | @Override |
72 | 204 | protected CMakeParser createParser() { |
73 | 205 | return new CMakeParser(); |
|
0 commit comments