Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive 100% coverage #426

Open
andreisilviudragnea opened this issue Dec 15, 2021 · 4 comments
Open

False positive 100% coverage #426

andreisilviudragnea opened this issue Dec 15, 2021 · 4 comments

Comments

@andreisilviudragnea
Copy link

There are cases when coverage is mistakenly reported as 100%, even if it is not true:

package org.example

import com.typesafe.scalalogging.Logger

import java.util.concurrent.CompletableFuture

class Class(logger: Logger) {
  def brokenCoverage1(input: Option[String]): String = {
    input match {
      case Some(value) => value
      case None        => ""
    }
  }

  def brokenCoverage2(input: Option[String]): String = {
    input match {
      case Some(value) => {
        value
      }
      case None => ""
    }
  }

  def brokenCoverage3(): Unit = {
    CompletableFuture.completedFuture("").whenComplete { (_, throwable) =>
      Option(throwable) match {
        case Some(_) => logger.error("Error completing future")
        case None    => ()
      }
    }
  }

  def brokenCoverage4(): Unit = {
    CompletableFuture.completedFuture("").whenComplete { (_, throwable) =>
      Option(throwable) match {
        case Some(_) => {
          logger.error("Error completing future")
        }
        case None => ()
      }
    }
  }

  def brokenCoverage5(input: Option[String]): String = {
    input match {
      case Some(_) => s"something"
      case None    => ""
    }
  }

  def brokenCoverage6(input: Option[String]): String = {
    input match {
      case Some(value) => s"something $value"
      case None        => ""
    }
  }

  def brokenCoverage7(input: Option[String]): String = {
    input match {
      case Some(value) => {
        s"something $value"
      }
      case None => ""
    }
  }
}
package org.example

import com.typesafe.scalalogging.Logger
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should
import org.slf4j.LoggerFactory

class ScoverageSpec extends AnyFunSuite with should.Matchers {

  test("scoverage") {
    val logger: Logger = Logger(LoggerFactory.getLogger("[Gomez]"))
    new Class(logger).brokenCoverage1(None) shouldBe ""
    new Class(logger).brokenCoverage2(None) shouldBe ""
    new Class(logger).brokenCoverage3() shouldBe ()
    new Class(logger).brokenCoverage4() shouldBe ()
    new Class(logger).brokenCoverage5(None) shouldBe ""
    new Class(logger).brokenCoverage6(None) shouldBe ""
    new Class(logger).brokenCoverage7(None) shouldBe ""
  }
}

Running sbt coverage test coverageReport does not fail as it should, but reports 100% coverage. I have reproduced the bug here: https://github.com/andreisilviudragnea/scoverage-bugs

@andreisilviudragnea
Copy link
Author

@ckipp01 Is there anyone checking bug reports? This seems like a major bug to me, which affects both V1 and V2.

@ckipp01
Copy link
Member

ckipp01 commented Dec 21, 2021

Hey @andreisilviudragnea, at the moment I'm not actively working on scoverage. The attempt to add Scala 3 support and getting the V2 out was all being done on my free time, and it was taking a pretty large chunk of it that I'd prefer to be used on the other projects I have. However I do still plan to cut releases for new Scala versions and address anything that requires an immediate response.

Potentially over break I'll get back to some of this and try to wrap it all up, look into some of the issue reports, etc, but no promises.

@andreisilviudragnea
Copy link
Author

@ckipp01 Is there an active maintainer for scoverage?

I am asking because my team is checking Scala community support for the dependencies in our project, since lack of support affects our usage of Scala language in the future.

@ckipp01
Copy link
Member

ckipp01 commented Dec 21, 2021

@ckipp01 Is there an active maintainer for scoverage?

At the moment I'm really the only one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants