Skip to content

Commit cc6b52b

Browse files
authored
sonar-kotlin-surefire should not depend on sonar-kotlin-api
1 parent d3dcd68 commit cc6b52b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

sonar-kotlin-surefire/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ dependencies {
99
implementation(libs.sonar.xml.parsing)
1010
implementation(libs.sonar.regex.parsing)
1111
implementation(libs.sonar.performance.measure)
12-
implementation(libs.kotlin.compiler.embeddable)
1312
implementation(libs.staxmate)
1413
implementation(libs.gson)
1514
implementation(libs.sonar.analyzer.commons.recognizers)
1615

17-
implementation(project(":sonar-kotlin-api"))
18-
1916
testRuntimeOnly(testLibs.junit.engine)
2017
testImplementation(libs.slf4j.api)
2118
testImplementation(testLibs.junit.api)
@@ -26,6 +23,4 @@ dependencies {
2623
testImplementation(testLibs.sonar.analyzer.test.commons)
2724
testImplementation(testLibs.sonar.plugin.api.impl)
2825
testImplementation(testLibs.sonar.plugin.api.test.fixtures)
29-
30-
testImplementation(project(":sonar-kotlin-test-api"))
3126
}

sonar-kotlin-surefire/src/main/java/org/sonarsource/kotlin/surefire/KotlinSurefireParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.sonar.api.batch.sensor.SensorContext;
3535
import org.sonar.api.measures.CoreMetrics;
3636
import org.sonar.api.measures.Metric;
37-
import org.sonarsource.kotlin.api.frontend.ParseException;
3837
import org.sonarsource.kotlin.surefire.data.UnitTestClassReport;
3938
import org.sonarsource.kotlin.surefire.data.UnitTestIndex;
4039

@@ -96,7 +95,7 @@ private static void parseFiles(List<File> reports, UnitTestIndex index) {
9695
try {
9796
parser.parse(report);
9897
} catch (XMLStreamException e) {
99-
throw new ParseException("Fail to parse the Surefire report: " + report, null, e);
98+
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
10099
}
101100
}
102101
}

sonar-kotlin-surefire/src/test/java/org/sonarsource/kotlin/surefire/KotlinSurefireParserTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.Optional;
2626
import java.util.stream.Collectors;
2727
import java.util.stream.Stream;
28+
29+
import com.ctc.wstx.exc.WstxEOFException;
2830
import kotlin.jvm.JvmField;
2931
import org.junit.jupiter.api.BeforeEach;
3032
import org.junit.jupiter.api.Test;
@@ -39,6 +41,7 @@
3941
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
4042

4143
import static org.assertj.core.api.Assertions.assertThat;
44+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4245
import static org.mockito.ArgumentMatchers.anyString;
4346
import static org.mockito.Mockito.doAnswer;
4447
import static org.mockito.Mockito.mock;
@@ -187,6 +190,21 @@ void shouldNotCountNegativeTests() {
187190
assertThat(context.measure(":java.Foo", CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(659);
188191
}
189192

193+
@Test
194+
void shouldThrowWhenUnparsable() {
195+
SensorContextTester context = mockContext();
196+
197+
var reportPath = "src/test/resources/org/sonarsource/kotlin/surefire/api/SurefireParserTest/unparsable/TEST-FooTest.xml"
198+
.replace('/', File.separatorChar);
199+
var dirs = getDirs("unparsable");
200+
assertThatThrownBy(() -> parser.collect(context, dirs, true))
201+
.isInstanceOf(IllegalStateException.class)
202+
.hasMessage("Fail to parse the Surefire report: " + reportPath)
203+
.hasRootCauseInstanceOf(WstxEOFException.class)
204+
.hasRootCauseMessage("Unexpected EOF in prolog" + System.lineSeparator() +
205+
" at [row,col {unknown-source}]: [1,0]");
206+
}
207+
190208
private List<File> getDirs(String... directoryNames) {
191209
return Stream.of(directoryNames)
192210
.map(directoryName -> new File("src/test/resources/org/sonarsource/kotlin/surefire/api/SurefireParserTest/" + directoryName))

sonar-kotlin-surefire/src/test/resources/org/sonarsource/kotlin/surefire/api/SurefireParserTest/unparsable/TEST-FooTest.xml

Whitespace-only changes.

0 commit comments

Comments
 (0)