-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add filter for instructions inlined by Kotlin compiler #764
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1d932e7
(WIP) add validation test
Godin 09bb132
(WIP) add unit test
Godin 169eb95
(WIP) filters should have access to SourceDebugExtension attribute
Godin 04523d4
(WIP) add filter
Godin 3a3db75
(WIP) simplify validation test
Godin e13adca
(WIP) simplify code, add javadocs
Godin 9c21e54
(WIP) add unit tests
Godin 98dfd30
(WIP) remove unused variable
Godin 2290659
Merge branch 'master' into filter_kotlin_inline
Godin dae6687
(WIP) reorder imports
Godin 3a445bd
(WIP) assert: last line in coverage is less or equal to lines in source
Godin ab5c324
(WIP) ignored instructions should affect computation of lines
Godin 4292efb
(WIP) do not reparse SourceDebugExtension attribute
Godin 653a6ef
Merge branch 'master' into filter_kotlin_inline
Godin 8f8cea6
Merge branch 'master' into filter_kotlin_inline
Godin 37da973
Merge branch 'master' into filter_kotlin_inline
Godin ebe8437
(WIP) get rid of warning in Eclipse
Godin d333f2c
(WIP) move assertion into separate test
Godin 24ed5cd
(WIP) simplify regexp
Godin f083c88
(WIP) rename readLine into expectLine
Godin 680dd1b
(WIP) add comment about StringReader and IOException
Godin cda6733
(WIP) Replace AssertionError by IllegalStateException
Godin 179bddc
(WIP) improve wording
Godin db22afd
(WIP) reuse method isKotlinClass
Godin 32c3761
(WIP) avoid infinite loop
Godin 24d2f9c
(WIP) update changelog
Godin f6967ee
Add missing final.
marchof aac9ce4
(WIP) update test to prevent accidental merge
Godin 7e7724f
(WIP) add unit test
Godin 788abf0
(WIP) use only main "Kotlin" strata instead of optional "KotlinDebug"
Godin 2e7f6aa
(WIP) add case into validation test
Godin 524958b
(WIP) clarify entry in changelog
Godin 289eaa4
(WIP) add comments into unit test
Godin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...e.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinInlineTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.test.validation.kotlin; | ||
|
||
import org.jacoco.core.test.validation.ValidationTestBase; | ||
import org.jacoco.core.test.validation.kotlin.targets.KotlinInlineTarget; | ||
|
||
/** | ||
* Test of inline functions. |
||
*/ | ||
public class KotlinInlineTest extends ValidationTestBase { | ||
|
||
public KotlinInlineTest() { | ||
super(KotlinInlineTarget.class); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...alidation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinInlineTarget.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.test.validation.kotlin.targets | ||
|
||
import org.jacoco.core.test.validation.targets.Stubs.nop | ||
import org.jacoco.core.test.validation.targets.Stubs.t | ||
|
||
/** | ||
* Test target for `inline` functions. | ||
*/ | ||
object KotlinInlineTarget { | ||
|
||
inline fun inlined() { | ||
nop() // assertNotCovered() | ||
} | ||
|
||
@JvmStatic | ||
fun main(args: Array |
||
|
||
inlined() // assertFullyCovered() | ||
|
||
/* Following inlined method for some reasons doesn't appear in SMAP: */ | ||
assert(t()) // assertPartlyCovered(2, 2) | ||
|
||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
...jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinInlineFilterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.internal.analysis.filter; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jacoco.core.internal.instr.InstrSupport; | ||
import org.junit.Test; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
/** | ||
* Unit tests for {@link KotlinInlineFilter}. | ||
*/ | ||
public class KotlinInlineFilterTest extends FilterTestBase { | ||
|
||
private final KotlinInlineFilter filter = new KotlinInlineFilter(); | ||
|
||
private final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, | ||
"callsite", "()V", null, null); | ||
|
||
@Test | ||
public void should_filter() { | ||
context.sourceFileName = "callsite.kt"; | ||
context.sourceDebugExtension = "" // | ||
+ "SMAP\n" // | ||
+ "callsite.kt\n" // OutputFileName=callsite.kt | ||
+ "Kotlin\n" // DefaultStratumId=Kotlin | ||
+ "*S Kotlin\n" // StratumID=Kotlin | ||
+ "*F\n" // FileSection | ||
+ "+ 1 callsite.kt\n" // FileID=1,FileName=callsite.kt | ||
+ "CallsiteKt\n" // | ||
+ "+ 2 a.kt\n" // FileID=2,FileName=a.kt | ||
+ "AKt\n" // | ||
+ "+ 3 b.kt\n" // FileID=3,FileName=b.kt | ||
+ "BKt\n" // | ||
+ "*L\n" // LineSection | ||
+ "1#1,8:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=8,OutputStartLine=1 | ||
+ "2#2,2:9\n" // InputStartLine=2,LineFileID=2,RepeatCount=2,OutputStartLine=9 | ||
+ "2#3,2:11\n" // InputStartLine=2,LineFileID=3,RepeatCount=2,OutputStartLine=11 | ||
+ "*E\n"; // EndSection | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
m.visitLineNumber(2, new Label()); | ||
m.visitInsn(Opcodes.NOP); | ||
|
||
m.visitLineNumber(9, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); | ||
shouldIgnorePrevious(m); | ||
m.visitLineNumber(10, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitInsn(Opcodes.NOP); | ||
shouldIgnorePrevious(m); | ||
|
||
m.visitLineNumber(3, new Label()); | ||
m.visitInsn(Opcodes.NOP); | ||
|
||
m.visitLineNumber(11, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); | ||
shouldIgnorePrevious(m); | ||
m.visitLineNumber(12, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitInsn(Opcodes.NOP); | ||
shouldIgnorePrevious(m); | ||
|
||
m.visitLineNumber(4, new Label()); | ||
m.visitInsn(Opcodes.RETURN); | ||
|
||
filter.filter(m, context, output); | ||
|
||
assertIgnored(expectedRanges.toArray(new Range[0])); | ||
|
||
// should not reparse: | ||
context.sourceDebugExtension = ""; | ||
filter.filter(m, context, output); | ||
} | ||
|
||
@Test | ||
public void should_filter_when_in_same_file() { | ||
context.sourceFileName = "callsite.kt"; | ||
context.sourceDebugExtension = "" // | ||
+ "SMAP\n" // | ||
+ "callsite.kt\n" // OutputFileName=callsite.kt | ||
+ "Kotlin\n" // DefaultStratumId=Kotlin | ||
+ "*S Kotlin\n" // StratumID=Kotlin | ||
+ "*F\n" // FileSection | ||
+ "+ 1 callsite.kt\n" // FileID=1,FileName=callsite.kt | ||
+ "CallsiteKt\n" // | ||
+ "*L\n" // LineSection | ||
+ "1#1,33:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=33,OutputStartLine=1 | ||
+ "22#1,2:34\n" // InputStartLine=22,LineFileID=1,RepeatCount=2,OutputStartLine=34 | ||
+ "*E\n"; // EndSection | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
m.visitLineNumber(28, new Label()); | ||
m.visitInsn(Opcodes.NOP); | ||
|
||
m.visitLineNumber(34, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); | ||
shouldIgnorePrevious(m); | ||
m.visitLineNumber(35, new Label()); | ||
shouldIgnorePrevious(m); | ||
m.visitInsn(Opcodes.NOP); | ||
shouldIgnorePrevious(m); | ||
|
||
m.visitLineNumber(30, 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"; | ||
|
||
m.visitLineNumber(1, new Label()); | ||
m.visitInsn(Opcodes.RETURN); | ||
|
||
filter.filter(m, context, output); | ||
|
||
assertIgnored(); | ||
} | ||
|
||
@Test | ||
public void should_not_filter_when_no_SourceDebugExtension_attribute() { | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
m.visitLineNumber(1, new Label()); | ||
m.visitInsn(Opcodes.RETURN); | ||
|
||
filter.filter(m, context, output); | ||
|
||
assertIgnored(); | ||
} | ||
|
||
@Test | ||
public void should_throw_exception_when_SMAP_incomplete() { | ||
context.sourceDebugExtension = "" // | ||
+ "SMAP\n"; | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
try { | ||
filter.filter(m, context, output); | ||
fail("exception expected"); | ||
} catch (final IllegalStateException e) { | ||
assertEquals("Unexpected SMAP line: null", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void should_throw_exception_when_unexpected_FileInfo() { | ||
context.sourceFileName = "callsite.kt"; | ||
context.sourceDebugExtension = "" // | ||
+ "SMAP\n" // | ||
+ "callsite.kt\n" // | ||
+ "Kotlin\n" // | ||
+ "*S Kotlin\n" // | ||
+ "*F\n" // | ||
+ "xxx"; | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
try { | ||
filter.filter(m, context, output); | ||
fail("exception expected"); | ||
} catch (final IllegalStateException e) { | ||
assertEquals("Unexpected SMAP line: xxx", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void should_throw_exception_when_unexpected_LineInfo() { | ||
context.sourceFileName = "callsite.kt"; | ||
context.sourceDebugExtension = "" // | ||
+ "SMAP\n" // | ||
+ "callsite.kt\n" // | ||
+ "Kotlin\n" // | ||
+ "*S Kotlin\n" // | ||
+ "*F\n" // | ||
+ "*L\n" // | ||
+ "xxx"; | ||
context.classAnnotations | ||
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); | ||
|
||
try { | ||
filter.filter(m, context, output); | ||
fail("exception expected"); | ||
} catch (final IllegalStateException e) { | ||
assertEquals("Unexpected SMAP line: xxx", e.getMessage()); | ||
} | ||
} | ||
|
||
private final List |
||
|
||
private void shouldIgnorePrevious(final MethodNode m) { | ||
expectedRanges.add( | ||
new Range(m.instructions.getLast(), m.instructions.getLast())); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.