aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2021-03-16 11:43:27 +0100
committerGitHub <noreply@github.com>2021-03-16 11:43:27 +0100
commitfaa8b7ad2ced6a3f2de8adcca8fd5a0626d64d91 (patch)
tree0b770143741366524ac610eea7e02f0d4b49efd0
parentd9296f7251f99a9b0b6e624d7eb6d35021279ce3 (diff)
downloadjacoco-faa8b7ad2ced6a3f2de8adcca8fd5a0626d64d91.tar.gz
Fix parsing of SMAP for Kotlin 1.5 (#1164)
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java41
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilter.java6
-rw-r--r--org.jacoco.doc/docroot/doc/changes.html7
3 files changed, 52 insertions, 2 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java
index 1824cfc3..beb49816 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java
@@ -163,6 +163,47 @@ public class KotlinInlineFilterTest extends FilterTestBase {
assertIgnored(expectedRanges.toArray(new Range[0]));
}
+ /**
+ * See <a href="https://youtrack.jetbrains.com/issue/KT-37704">KT-37704</a>
+ *
+ * <pre>
+ * inline fun f() {}
+ * fun g() = f()
+ * </pre>
+ */
+ @Test
+ public void should_filter_without_parsing_KotlinDebug_stratum() {
+ context.sourceFileName = "Example.kt";
+ context.sourceDebugExtension = "" //
+ + "SMAP\n" //
+ + "Example.kt\n" // OutputFileName=Example.kt
+ + "Kotlin\n" // DefaultStratumId=Kotlin
+ + "*S Kotlin\n" // StratumID=Kotlin
+ + "*F\n" // FileSection
+ + "+ 1 Example.kt\n" // FileID=1,FileName=Example.kt
+ + "ExampleKt\n" //
+ + "*L\n" // LineSection
+ + "1#1,3:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=3,OutputStartLine=1
+ + "1#1:4\n" // InputStartLine=1,LineFileID=1,OutputStartLine=4
+ + "*S KotlinDebug\n"; // StratumID=KotlinDebug
+ context.classAnnotations
+ .add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
+
+ m.visitLineNumber(2, new Label());
+ m.visitInsn(Opcodes.ICONST_0);
+ m.visitVarInsn(Opcodes.ISTORE, 0);
+ m.visitLineNumber(4, new Label());
+ shouldIgnorePrevious(m);
+ m.visitInsn(Opcodes.NOP);
+ shouldIgnorePrevious(m);
+ m.visitLineNumber(3, new Label());
+ m.visitInsn(Opcodes.RETURN);
+
+ filter.filter(m, context, output);
+
+ assertIgnored(expectedRanges.toArray(new Range[0]));
+ }
+
@Test
public void should_not_parse_SourceDebugExtension_attribute_when_no_kotlin_metadata_annotation() {
context.sourceDebugExtension = "SMAP";
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilter.java
index 1cc9d840..f3e7d6b9 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilter.java
@@ -92,7 +92,11 @@ public final class KotlinInlineFilter implements IFilter {
}
// LineSection
int min = Integer.MAX_VALUE;
- while (!"*E".equals(line = br.readLine())) {
+ while (true) {
+ line = br.readLine();
+ if (line.equals("*E") || line.equals("*S KotlinDebug")) {
+ break;
+ }
final Matcher m = LINE_INFO_PATTERN.matcher(line);
if (!m.matches()) {
throw new IllegalStateException(
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index 2eacdeb4..2ddf9d36 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -41,6 +41,12 @@
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1156">#1156</a>).</li>
</ul>
+<h3>Fixed bugs</h3>
+<ul>
+ <li>Fixed parsing of SMAP generated by Kotlin compiler version 1.5.0 and above
+ (GitHub <a href="https://github.com/jacoco/jacoco/issues/1164">#1164</a>).</li>
+</ul>
+
<h3>Non-functional Changes</h3>
<ul>
<li>JaCoCo now depends on ASM 9.1
@@ -51,7 +57,6 @@
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1121">#1121</a>).</li>
</ul>
-
<h2>Release 0.8.6 (2020/09/15)</h2>
<h3>New Features</h3>