Skip to content

Commit d7c74ff

Browse files
authored
Fix: Source files not included in JaCoCo HTML report (#61)
fixes #60
1 parent dae2334 commit d7c74ff

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/RootCoveragePlugin.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ class RootCoveragePlugin : Plugin<Project> {
189189
return
190190
}
191191
}
192-
baseVariant.forEach {
193-
subProject.logger.warn("Name: $name, BaseName: ${it.baseName}")
192+
baseVariant.all {
194193
if(name.contentEquals(it.baseName, ignoreCase = true)) {
195194
val sourceFiles = it.getSourceFolders(SourceKind.JAVA).map { file -> file.dir }
196195
sourceDirectories.from(subProject.files(sourceFiles))

plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,22 @@ class IntegrationTest(
4545
assertThat(result.output).contains("BUILD SUCCESSFUL")
4646

4747
// Assert whether the combined coverage report is what we expected
48-
result.assertRootCoverageReport()
48+
result.assertRootCoverageReport(File(projectRoot, "build/reports/jacoco.csv"))
4949

5050
// Assert whether the per module coverage reports are what we expect
5151
result.assertAppCoverageReport()
5252
result.assertAndroidLibraryCoverageReport()
53+
54+
assertSourceFilesHaveBeenAddedToReport(File(projectRoot, "build/reports/jacoco"))
5355
}
5456

55-
private fun BuildResult.assertRootCoverageReport() {
57+
private fun BuildResult.assertRootCoverageReport(file: File) {
5658
assertEquals(task(":rootCoverageReport")!!.outcome, TaskOutcome.SUCCESS)
5759

5860
// Also check if the old task name is still exe
5961
assertEquals(task(":rootCodeCoverageReport")!!.outcome, TaskOutcome.SUCCESS)
6062

61-
val report = CoverageReport.from(File(projectRoot, "build/reports/jacoco.csv"))
63+
val report = CoverageReport.from(file)
6264

6365
report.assertCoverage("org.neotech.library.android", "LibraryAndroidJava")
6466
report.assertCoverage("org.neotech.library.android", "LibraryAndroidKotlin")
@@ -99,6 +101,18 @@ class IntegrationTest(
99101
)
100102
}
101103

104+
private fun assertSourceFilesHaveBeenAddedToReport(htmlReportRoot: File) {
105+
htmlReportRoot.walkTopDown()
106+
.filter {
107+
it.isFile && it.extension == "html"
108+
}
109+
.forEach { file ->
110+
file.forEachLine {
111+
assertThat(it).doesNotContainMatch("Source file &quot;.*&quot; was not found during generation of report\\.")
112+
}
113+
}
114+
}
115+
102116
companion object {
103117

104118
@Suppress("unused") // This method is used by the JVM (Parameterized JUnit Runner)

0 commit comments

Comments
 (0)