Skip to content

Commit

Permalink
Merge pull request #475 from codacy/fix-cobertura
Browse files Browse the repository at this point in the history
fix: [Cobertura] Merge results on the same line instead of replacing
  • Loading branch information
lolgab authored Oct 31, 2023
2 parents 5f6caf9 + 05a7290 commit 590a6cb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.codacy.parsers.util.MathUtils._
import com.codacy.parsers.util.TextUtils
import com.codacy.parsers.{CoverageParser, XmlReportParser}

import scala.collection.mutable
import scala.xml.{Elem, NodeSeq}

object CoberturaParser extends CoverageParser with XmlReportParser {
Expand Down Expand Up @@ -50,12 +51,18 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
}
val fileHit = if (classHit.nonEmpty) { classHit.sum / classHit.length } else 0

val lineHitMap: Map[Int, Int] =
(for {
xClass <- classes
line <- xClass \\ "line"
} yield (line \@ "number").toInt -> (line \@ "hits").toIntOrMaxValue).toMap
val map = mutable.Map.empty[Int, Int]

CoverageFileReport(sourceFilename, fileHit, lineHitMap)
for {
xClass <- classes
line <- xClass \\ "line"
} {
val key = (line \@ "number").toInt
val value = (line \@ "hits").toIntOrMaxValue

map(key) = map.get(key).getOrElse(0) + value
}

CoverageFileReport(sourceFilename, fileHit, map.toMap)
}
}
4 changes: 4 additions & 0 deletions coverage-parser/src/test/resources/test_cobertura.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="2"/>
<line number="7" hits="1"/>
<line number="7" hits="0"/>
<line number="8" hits="1"/>
<line number="8" hits="2"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="coverage-parser/src/test/resources/TestSourceFile.scala">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
CoverageFileReport(
"coverage-parser/src/test/resources/TestSourceFile.scala",
87,
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1)
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CoverageParserFactoryTest extends WordSpec with BeforeAndAfterAll with Mat
CoverageFileReport(
"coverage-parser/src/test/resources/TestSourceFile.scala",
87,
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1)
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion graalvm/build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export CC=$TOOLCHAIN_DIR/bin/gcc

zlib='zlib-1.2.13'
zlibtargz=$zlib.tar.gz
curl https://zlib.net/$zlibtargz --output $zlibtargz
curl https://zlib.net/fossils/$zlibtargz --output $zlibtargz
tar -xf $zlibtargz

(
Expand Down

0 comments on commit 590a6cb

Please sign in to comment.