|
19 | 19 | */ |
20 | 20 | package org.sonarsource.kotlin.plugin |
21 | 21 |
|
| 22 | +import io.mockk.every |
| 23 | +import io.mockk.spyk |
22 | 24 | import org.assertj.core.api.Assertions |
23 | | -import org.junit.Ignore |
24 | 25 | import org.junit.jupiter.api.Test |
25 | 26 | import org.sonar.api.batch.rule.CheckFactory |
26 | 27 | import org.sonar.api.batch.sensor.highlighting.TypeOfText |
27 | 28 | import org.sonar.api.batch.sensor.issue.internal.DefaultNoSonarFilter |
28 | 29 | import org.sonar.api.config.internal.MapSettings |
29 | 30 | import org.sonar.api.measures.CoreMetrics |
| 31 | +import org.sonar.api.utils.log.LoggerLevel |
30 | 32 | import org.sonarsource.kotlin.testing.AbstractSensorTest |
31 | 33 | import org.sonarsource.kotlin.testing.assertTextRange |
| 34 | +import java.io.IOException |
32 | 35 | import kotlin.time.ExperimentalTime |
33 | 36 |
|
34 | 37 | @ExperimentalTime |
@@ -157,6 +160,26 @@ internal class KotlinSensorTest : AbstractSensorTest() { |
157 | 160 | Assertions.assertThat(textPointer.lineOffset()).isEqualTo(14) |
158 | 161 | Assertions.assertThat(logTester.logs()) |
159 | 162 | .contains(String.format("Unable to parse file: %s. Parse error at position 1:14", inputFile.uri())) |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + fun test_fail_reading() { |
| 167 | + val inputFile = spyk(createInputFile("file1.kt", "class A { fun f() = TODO() }")) |
| 168 | + context.fileSystem().add(inputFile) |
| 169 | + every { inputFile.contents() } throws IOException("Can't read") |
| 170 | + every { inputFile.toString() } returns "file1.kt" |
| 171 | + |
| 172 | + val checkFactory = checkFactory("S1764") |
| 173 | + sensor(checkFactory).execute(context) |
| 174 | + val analysisErrors = context.allAnalysisErrors() |
| 175 | + Assertions.assertThat(analysisErrors).hasSize(1) |
| 176 | + val analysisError = analysisErrors.iterator().next() |
| 177 | + Assertions.assertThat(analysisError.inputFile()).isEqualTo(inputFile) |
| 178 | + Assertions.assertThat(analysisError.message()).isEqualTo("Unable to parse file: file1.kt") |
| 179 | + val textPointer = analysisError.location() |
| 180 | + Assertions.assertThat(textPointer).isNull() |
| 181 | + |
| 182 | + Assertions.assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Cannot read 'file1.kt': Can't read") |
160 | 183 | } |
161 | 184 |
|
162 | 185 | @Test |
|
0 commit comments