|
39 | 39 | import org.sonar.plugins.javascript.bridge.BridgeServer.Issue; |
40 | 40 | import org.sonar.plugins.javascript.bridge.BridgeServer.Location; |
41 | 41 | import org.sonar.plugins.javascript.bridge.BridgeServer.Metrics; |
| 42 | +import org.sonar.plugins.javascript.bridge.BridgeServer.ParsingError; |
| 43 | +import org.sonar.plugins.javascript.bridge.BridgeServer.ParsingErrorCode; |
42 | 44 |
|
43 | 45 | class AnalysisProcessorTest { |
44 | 46 |
|
@@ -197,4 +199,45 @@ void should_not_fail_when_invalid_issue() { |
197 | 199 | processor.processResponse(context, mock(JsTsChecks.class), file, response); |
198 | 200 | assertThat(logTester.logs()).contains("Failed to save issue in " + file.uri() + " at line 2"); |
199 | 201 | } |
| 202 | + |
| 203 | + @Test |
| 204 | + void should_not_fail_when_invalid_parsing_error_pointer() { |
| 205 | + var fileLinesContextFactory = mock(FileLinesContextFactory.class); |
| 206 | + when(fileLinesContextFactory.createFor(any())).thenReturn(mock(FileLinesContext.class)); |
| 207 | + var processor = new AnalysisProcessor( |
| 208 | + mock(NoSonarFilter.class), |
| 209 | + fileLinesContextFactory, |
| 210 | + mock(CssRules.class) |
| 211 | + ); |
| 212 | + var context = new JsTsContext<SensorContextTester>(SensorContextTester.create(baseDir)); |
| 213 | + var file = TestInputFileBuilder.create("moduleKey", "file.js") |
| 214 | + .setContents("x") |
| 215 | + .setLanguage("js") |
| 216 | + .build(); |
| 217 | + |
| 218 | + var parsingError = new ParsingError( |
| 219 | + "Parse error message", |
| 220 | + 1, |
| 221 | + 2, |
| 222 | + ParsingErrorCode.PARSING, |
| 223 | + "js" |
| 224 | + ); |
| 225 | + var response = new AnalysisResponse( |
| 226 | + List.of(parsingError), |
| 227 | + List.of(), |
| 228 | + List.of(), |
| 229 | + List.of(), |
| 230 | + new Metrics(), |
| 231 | + List.of(), |
| 232 | + null |
| 233 | + ); |
| 234 | + |
| 235 | + processor.processResponse(context, mock(JsTsChecks.class), file, response); |
| 236 | + assertThat(context.getSensorContext().allAnalysisErrors()).hasSize(1); |
| 237 | + assertThat(logTester.logs()).contains( |
| 238 | + "Failed to create parsing error pointer in " + |
| 239 | + file.uri() + |
| 240 | + " at line 1, column 2. Falling back to file start." |
| 241 | + ); |
| 242 | + } |
200 | 243 | } |
0 commit comments