Skip to content

Commit

Permalink
Merge pull request #22 from nbaztec/fix-20
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
nbaztec authored Oct 30, 2020
2 parents 229954a + 1407564 commit e6b25bc
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "com.github.nbaztec"
version = "1.2.3"
version = "1.2.4"

buildscript {
repositories {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/SourceReportParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ object SourceReportParser {
val lineHits = arrayOfNulls<Int>(lines.size)

cov.forEach { (line, hits) ->
if (line < lineHits.size) {
if (line < lines.size) {
lineHits[line] = hits
} else {
logger.debug("skipping invalid line $line, (total ${lines.size})")
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/test/kotlin/SourceReportParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.io.File

internal class SourceReportParserTest {
private val testReport = File("src/test/resources/testreports/jacocoTestReport.xml")
private val testReportMissingLines = File("src/test/resources/testreports/jacocoTestReportMissingLines.xml")
private val testKotlinStyleSourceDir = File("src/test/resources/testrepo/src/main/kotlin")
private val testKotlinStyleSourceDirAdditional = File("src/test/resources/testrepo/src/anotherMain/kotlin")
private val testJavaStyleSourceDir = File("src/test/resources/testrepo/javaStyleSrc/main/kotlin")
Expand Down Expand Up @@ -146,4 +147,37 @@ internal class SourceReportParserTest {
)
assertEquals(expected, actual)
}

@Test
fun `SourceReportParser ignores lines in report that are missing in source`() {
val project = mockk<Project> {
every { projectDir } returns File("src/test/resources/testrepo")
every { extensions.getByType(CoverallsJacocoPluginExtension::class.java) } returns mockk {
every { reportPath } returns testReportMissingLines.path
every { reportSourceSets } returns listOf(
testKotlinStyleSourceDir,
testKotlinStyleSourceDirAdditional
)
}
}

val actual = SourceReportParser.parse(project)
val expected = listOf(
SourceReport(
"src/main/kotlin/Main.kt",
"36083cd4c2ac736f9210fd3ed23504b5",
listOf(null, null, null, null, 1, 1, 1, 1, null, 1, 1, 0, 0, 1, 1, null, 1, 1, 1)),
SourceReport(
"src/main/kotlin/internal/Util.kt",
"805ee340f4d661be591b4eb42f6164d2",
listOf(null, null, null, null, 1, 1, 1, null, null)
),
SourceReport(
"src/anotherMain/kotlin/Lib.kt",
"8b5c1c773cf81996efc19a08f0ac3648",
listOf(null, null, null, null, 1, 1, 1, null, null, null, null, null, null)
)
)
assertEquals(expected, actual)
}
}
66 changes: 66 additions & 0 deletions src/test/resources/testreports/jacocoTestReportMissingLines.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN"
"report.dtd">
<report name="coveralls-jacoco-gradle-plugin">
<sessioninfo id="HAMACL00142-96fbcb3b" start="1596118223365" dump="1596118225180"/>
<package name="foo/bar/baz">
<sourcefile name="Main.kt">
<line nr="5" mi="0" ci="1" mb="0" cb="0"/>
<line nr="6" mi="3" ci="1" mb="0" cb="0"/>
<line nr="7" mi="3" ci="1" mb="0" cb="0"/>
<line nr="8" mi="3" ci="1" mb="0" cb="0"/>
<line nr="10" mi="3" ci="1" mb="0" cb="0"/>
<line nr="11" mi="3" ci="1" mb="0" cb="0"/>
<line nr="12" mi="3" ci="0" mb="0" cb="0"/>
<line nr="13" mi="3" ci="0" mb="0" cb="0"/>
<line nr="14" mi="3" ci="1" mb="0" cb="0"/>
<line nr="15" mi="3" ci="1" mb="0" cb="0"/>
<line nr="17" mi="0" ci="1" mb="0" cb="0"/>
<line nr="18" mi="3" ci="1" mb="0" cb="0"/>
<line nr="19" mi="3" ci="1" mb="0" cb="0"/>
<line nr="39" mi="3" ci="1" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="55" covered="236"/>
<counter type="LINE" missed="15" covered="23"/>
<counter type="COMPLEXITY" missed="13" covered="5"/>
<counter type="METHOD" missed="13" covered="5"/>
<counter type="CLASS" missed="1" covered="5"/>
</sourcefile>
<counter type="INSTRUCTION" missed="1035" covered="506"/>
<counter type="BRANCH" missed="34" covered="20"/>
<counter type="LINE" missed="127" covered="60"/>
<counter type="COMPLEXITY" missed="74" covered="17"/>
<counter type="METHOD" missed="56" covered="8"/>
<counter type="CLASS" missed="14" covered="7"/>
</package>
<package name="foo/bar/baz/internal">
<sourcefile name="Util.kt">
<line nr="5" mi="0" ci="1" mb="0" cb="0"/>
<line nr="6" mi="3" ci="1" mb="0" cb="0"/>
<line nr="7" mi="3" ci="1" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="524" covered="0"/>
<counter type="BRANCH" missed="20" covered="0"/>
<counter type="LINE" missed="49" covered="0"/>
<counter type="COMPLEXITY" missed="20" covered="0"/>
<counter type="METHOD" missed="10" covered="0"/>
<counter type="CLASS" missed="4" covered="0"/>
</sourcefile>
</package>
<package name="foo/bar/baz/lib">
<sourcefile name="Lib.kt">
<line nr="5" mi="0" ci="1" mb="0" cb="0"/>
<line nr="6" mi="3" ci="1" mb="0" cb="0"/>
<line nr="7" mi="3" ci="1" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="524" covered="0"/>
<counter type="BRANCH" missed="20" covered="0"/>
<counter type="LINE" missed="49" covered="0"/>
<counter type="COMPLEXITY" missed="20" covered="0"/>
<counter type="METHOD" missed="10" covered="0"/>
<counter type="CLASS" missed="4" covered="0"/>
</sourcefile>
</package>
<counter type="INSTRUCTION" missed="1035" covered="506"/>
<counter type="BRANCH" missed="34" covered="20"/>
<counter type="LINE" missed="127" covered="60"/>
<counter type="COMPLEXITY" missed="74" covered="17"/>
<counter type="METHOD" missed="56" covered="8"/>
<counter type="CLASS" missed="14" covered="7"/>
</report>

0 comments on commit e6b25bc

Please sign in to comment.