Skip to content
This repository was archived by the owner on Dec 3, 2020. It is now read-only.

Commit 0dc8f4c

Browse files
committed
fix: Approximate to Int.MaxValue when a coverage value is too big CY-3310
This applies to Cobertura and LCOV only. Notice that a more long-term solution is to use `Long` to represent these possibly big numbers. The long term solution is stated in: https://codacy.atlassian.net/browse/CY-3314
1 parent 5c268ef commit 0dc8f4c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/main/scala/com/codacy/parsers/implementation/CoberturaParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.codacy.parsers.implementation
33
import java.io.File
44

55
import com.codacy.api.{CoverageFileReport, CoverageReport}
6+
import com.codacy.parsers.util.MathUtils._
67
import com.codacy.parsers.util.TextUtils
78
import com.codacy.parsers.{CoverageParser, XmlReportParser}
89

@@ -53,7 +54,7 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
5354
(for {
5455
xClass <- classes
5556
line <- xClass \\ "line"
56-
} yield (line \@ "number").toInt -> (line \@ "hits").toInt).toMap
57+
} yield (line \@ "number").toInt -> (line \@ "hits").toIntOrMaxValue).toMap
5758

5859
CoverageFileReport(sourceFilename, fileHit, lineHitMap)
5960
}

src/main/scala/com/codacy/parsers/implementation/LCOVParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codacy.parsers.implementation
22

33
import com.codacy.parsers.CoverageParser
4+
import com.codacy.parsers.util.MathUtils._
45
import com.codacy.api.{CoverageFileReport, CoverageReport}
56
import java.io.File
67

@@ -41,7 +42,7 @@ object LCOVParser extends CoverageParser {
4142
case Some(value) =>
4243
val coverage = next.stripPrefix(DA).split(",")
4344
if (coverage.length >= 2 && coverage.forall(_ forall Character.isDigit)) {
44-
val coverageValue = coverage.map(_.toInt)
45+
val coverageValue = coverage.map(_.toIntOrMaxValue)
4546
Right(
4647
value.copy(coverage = value.coverage + (coverageValue(0) -> coverageValue(1))) +: reports.tail
4748
)

src/main/scala/com/codacy/parsers/util/MathUtils.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@ object MathUtils {
55
def computePercentage(part: Int, total: Int): Int = {
66
if (total == 0) 0 else math.round((part.toFloat / total) * 100)
77
}
8+
9+
implicit class ParseIntOps(val s: String) extends AnyVal {
10+
11+
def toIntOrMaxValue: Int = {
12+
val long = s.toLong
13+
if (long > Int.MaxValue) Int.MaxValue
14+
else long.toInt
15+
}
16+
}
817
}

0 commit comments

Comments
 (0)