Skip to content

Commit

Permalink
fix(coverage): fix for absolute vs relative paths
Browse files Browse the repository at this point in the history
fix for maven sending absolute paths and sonar-runner sending relative paths
  • Loading branch information
Sebastian Chmielewski committed Aug 17, 2017
1 parent 1c7c452 commit e784a3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ class XmlScoverageReportConstructingParser(source: Source, pathSanitizer: PathSa
val childNodes = children.map(_.toStatementCoverage)

childNodes match {
case Nil => coverage.get
case Nil => coverage match {
case None => FileStatementCoverage("Nothing", 0, 0, List.empty[CoveredStatement])
case _ => coverage.get
}
case _ => DirectoryStatementCoverage(name, childNodes)
}
}
Expand Down Expand Up @@ -224,4 +227,4 @@ class XmlScoverageReportConstructingParser(source: Source, pathSanitizer: PathSa

private def coveredStatements(statements: Iterable[CoveredStatement]) =
statements.count(_.hitCount > 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ import com.buransky.plugins.scoverage.NodeStatementCoverage
class XmlScoverageReportConstructingParserSpec extends FlatSpec with Matchers {
behavior of "parse source"

it must "parse empty coverage file correctly" in {
val sanitizer = new PathSanitizer() {
def getSourceRelativePath(path: Seq[String]): Option[Seq[String]] = {
// do nothing
Some(path)
}
}
assertReportFile(XmlReportFile1.emptyCoverage, 0, sanitizer)(assertEmptyCoverage)
}

it must "parse old broken Scoverage 0.95 file correctly" in {
val sanitizer = new PathSanitizer() {
def getSourceRelativePath(path: Seq[String]): Option[Seq[String]] = {
Expand Down Expand Up @@ -130,4 +140,15 @@ class XmlScoverageReportConstructingParserSpec extends FlatSpec with Matchers {

node.children
}

private def assertEmptyCoverage(projectCoverage: ProjectStatementCoverage): Unit = {
// Assert structure
projectCoverage.name should equal("")

val projectChildren = projectCoverage.children.toList
projectChildren.length should equal(0)
projectCoverage.coveredStatementsCount should equal(0)
projectCoverage.statementCount should equal(0)
projectCoverage.coveredStatementsCount should equal(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -834,4 +834,10 @@ object XmlReportFile1 {
| </packages>
|</scoverage>
""".stripMargin

val emptyCoverage =
"""<scoverage
|statement-count="0" statements-invoked="0" statement-rate="100.00" branch-rate="100.00" version="1.0" timestamp="1502284526688">
| <packages> </packages>
|</scoverage>""".stripMargin
}

0 comments on commit e784a3f

Please sign in to comment.