Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of SMAP for Kotlin 1.5 #1164

Merged
merged 3 commits into from Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -163,6 +163,47 @@ public void should_filter_when_in_same_file() {
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";
Expand Down
Expand Up @@ -92,7 +92,11 @@ private static int getFirstGeneratedLineNumber(final String sourceFileName,
}
// 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(
Expand Down
7 changes: 6 additions & 1 deletion org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -41,6 +41,12 @@ <h3>New Features</h3>
(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
Expand All @@ -51,7 +57,6 @@ <h3>Non-functional Changes</h3>
(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>
Expand Down