Skip to content

Commit

Permalink
Remove the class name from the coverageinformation.xml file. The cove…
Browse files Browse the repository at this point in the history
…rage-reporter accumulates the results for each file.

Signed-off-by: nikomall34 <[email protected]>
  • Loading branch information
nikomall34 committed Feb 6, 2024
1 parent 8195a32 commit c84bad4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.pitest.coverage.ReportCoverage
import org.pitest.mutationtest.ClassMutationResults
import org.pitest.mutationtest.MutationResultListener
import org.pitest.mutationtest.report.html.MutationHtmlReportListener
import org.pitest.mutationtest.report.html.MutationTestSummaryData
import org.pitest.mutationtest.report.html.MutationTotals
import org.pitest.mutationtest.report.html.PackageSummaryMap
import org.pitest.util.ResultOutputStrategy
Expand All @@ -16,7 +17,7 @@ import java.io.IOException
import java.io.Writer

internal enum class Tag {
FileName, PackageName, MutatedClass, LineCoverage, LineCoveragePercentage, MutationCoverage,
FileName, PackageName, LineCoverage, LineCoveragePercentage, MutationCoverage,
MutationCoveragePercentage, TestStrengthPercentage, TestStrength, NumberOfClasses
}

Expand All @@ -29,6 +30,7 @@ class CoverageResultListener(
private var out: Writer? = null
private var totals: MutationTotals = MutationTotals()
private var packageSummaryData: PackageSummaryMap = PackageSummaryMap()
private var fileSummaryData = HashMap<String, MutationTestSummaryData>()

init {
this.out = outputStrategy?.createWriterForFile("coverageInformation.xml")
Expand Down Expand Up @@ -79,21 +81,17 @@ class CoverageResultListener(
if (htmlListener is MutationHtmlReportListener) {
val testMetaData = (htmlListener as MutationHtmlReportListener).createSummaryData(coverage, results)
val classTotals = testMetaData.totals

totals.add(classTotals)
packageSummaryData.update(results.packageName, testMetaData)

write("<testMetaData>")
write(makeNode(results.fileName, Tag.FileName))
write(makeNode(results.packageName, Tag.PackageName))
write(makeNode(results.mutatedClass.toString(), Tag.MutatedClass))
writeMetaDataNode(classTotals)
write("</testMetaData>\n")
fileSummaryData[results.fileName]?.add(testMetaData) ?: run {
fileSummaryData[results.fileName] = testMetaData
}
}
}

override fun runEnd() {
try {
writeFileSummaries()
writePackageSummaries()
writeTotals()
out!!.close()
Expand All @@ -102,6 +100,16 @@ class CoverageResultListener(
}
}

private fun writeFileSummaries() {
for(fileSummary in fileSummaryData.values) {
write("<testMetaData>")
write(makeNode(fileSummary.fileName, Tag.FileName))
write(makeNode(fileSummary.packageName, Tag.PackageName))
writeMetaDataNode(fileSummary.totals)
write("</testMetaData>\n")
}
}

private fun writeTotals() {
write("<totalMetaData>")
writeMetaDataNode(totals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ class XMLParser {

val fileName = getTextContent(element, "FileName")
val packageName = getTextContent(element, "PackageName")
val mutatedClass = getTextContent(element, "MutatedClass")
val coverageReport = CoverageReport(
fileName,
packageName,
mutatedClass,
getLineCoveragePercentage(element),
getLineCoverageTextRatio(element),
getMutationCoveragePercentage(element),
Expand All @@ -110,7 +108,6 @@ class XMLParser {
val coverageReport = CoverageReport(
"package",
packageName,
"package",
getLineCoveragePercentage(element),
getLineCoverageTextRatio(element),
getMutationCoveragePercentage(element),
Expand All @@ -131,7 +128,6 @@ class XMLParser {
val element = mutationsNodeList.item(i) as? Element ?: continue

val coverageReport = CoverageReport(
"totals",
"totals",
"totals",
getLineCoveragePercentage(element),
Expand Down Expand Up @@ -241,8 +237,10 @@ class XMLParser {
packageReports.add(packageReport)
}
fun addCoverageReportTotals(coverageReport: CoverageReport) {
if (coverageReports.isNotEmpty()) {
coverageReport.numberOfClasses = coverageReports.size
if (packageReports.isNotEmpty()) {
for(packageReport in packageReports) {
coverageReport.numberOfClasses += packageReport.numberOfClasses
}
}
totalResult = coverageReport
}
Expand All @@ -267,7 +265,6 @@ class XMLParser {
data class CoverageReport(
val fileName: String,
val packageName: String,
val mutatedClass: String,
var lineCoveragePercentage: Int,
val lineCoverageTextRatio: String,
var mutationCoveragePercentage: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import javax.swing.table.DefaultTableModel

class LatestPiTestReport(
coverageReport: XMLParser.CoverageReport = XMLParser.CoverageReport(
"Test",
"Test",
"Test",
lineCoveragePercentage = 0,
Expand Down Expand Up @@ -61,7 +60,7 @@ class LatestPiTestReport(

val table = JBTable(model)

table.setRowHeight(lineCoverageBar.height + 2)
table.rowHeight = lineCoverageBar.height + 2
table.tableHeader.reorderingAllowed = false
table.tableHeader.resizingAllowed = false
table.tableHeader.font = UIUtil.getLabelFont()
Expand Down Expand Up @@ -103,12 +102,18 @@ class LatestPiTestReport(
row: Int,
column: Int
): Component {
if (value is CustomProgressBar) {
return value
} else if (value is JBLabel) {
return value
} else {
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
return when (value) {
is CustomProgressBar -> {
value
}

is JBLabel -> {
value
}

else -> {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class PiTestClassReport(
private val coverageReport: XMLParser.CoverageReport = XMLParser.CoverageReport(
fileName = "Test",
packageName = "Test",
mutatedClass = "Test",
lineCoveragePercentage = 0,
lineCoverageTextRatio = "",
mutationCoveragePercentage = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class MutationResultServiceTest : LightJavaCodeInsightFixtureTestCase5() {
XMLParser.CoverageReport(
fileName = "Presenter.java",
packageName = "de.esolutions.pitest.showcase",
mutatedClass = "de.esolutions.pitest.showcase.Presenter",
lineCoveragePercentage = 100,
lineCoverageTextRatio = "19/19",
mutationCoveragePercentage = 23,
Expand All @@ -138,7 +137,6 @@ class MutationResultServiceTest : LightJavaCodeInsightFixtureTestCase5() {
XMLParser.CoverageReport(
fileName = "totals",
packageName = "totals",
mutatedClass = "totals",
lineCoveragePercentage = 100,
lineCoverageTextRatio = "19/19",
mutationCoveragePercentage = 23,
Expand Down Expand Up @@ -190,15 +188,6 @@ class MutationResultServiceTest : LightJavaCodeInsightFixtureTestCase5() {
val actual = mutationResult.mutationResults.map { "${it.mutatedMethod}:${it.lineNumber}:${it.status}" }
Assertions.assertEquals(expected, actual)
Assertions.assertEquals(4, mutationResult.coverageReports.size)
Assertions.assertEquals(
listOf(
"de.pfoerd.example.pitest.coffeemachine.Palindrome",
"de.pfoerd.example.pitest.coffeemachine.service.CoffeeService",
"de.pfoerd.example.pitest.coffeemachine.service.CoffeeService2",
"de.pfoerd.example.pitest.coffeemachine.MyEmptyClass"
),
mutationResult.coverageReports.map { it.mutatedClass }
)
Assertions.assertNotNull(mutationResult.totalResult)
Assertions.assertEquals(4, mutationResult.totalResult!!.numberOfClasses)
}
Expand Down

0 comments on commit c84bad4

Please sign in to comment.