Skip to content

Commit

Permalink
Make flaky tag work with Scalacheck suites (scalameta#478)
Browse files Browse the repository at this point in the history
* Make flaky tag work with Scalacheck suites

Previously, the Scalacheck suite transform was registered after the
`.flaky` transform so a flaky test would fail even if it was OK to
ignore flaky failures. Reordering the transforms fixes the issue.

* Fix duplicate reporting of ignored tests in JS/Native

There was a bug in the JS/Native implementation of `RunNotifier` so that
it would report that a test was both ignored and that it succeeded.
  • Loading branch information
olafurpg authored Jan 17, 2022
1 parent 4b77d81 commit 9653a0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import scala.util.Try
import munit.internal.FutureCompat._

trait ScalaCheckSuite extends FunSuite {

def property(
name: String
)(body: => Prop)(implicit loc: Location): Unit = {
Expand All @@ -29,7 +28,7 @@ trait ScalaCheckSuite extends FunSuite {
implicit def unitToProp(unit: Unit): Prop = Prop.passed

override def munitTestTransforms: List[TestTransform] =
super.munitTestTransforms :+ scalaCheckPropTransform
scalaCheckPropTransform +: super.munitTestTransforms

protected def scalaCheckTestParameters = ScalaCheckTest.Parameters.default

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MUnitRunNotifier(reporter: JUnitReporter) extends RunNotifier {
var ignored = 0
var total = 0
var startedTimestamp = 0L
val isFailed: mutable.Set[String] = mutable.Set.empty[String]
val isReported: mutable.Set[Description] = mutable.Set.empty[Description]
override def fireTestSuiteStarted(description: Description): Unit = {
reporter.reportTestSuiteStarted()
}
Expand All @@ -23,11 +23,13 @@ class MUnitRunNotifier(reporter: JUnitReporter) extends RunNotifier {
}
override def fireTestIgnored(description: Description): Unit = {
ignored += 1
isReported += description
reporter.reportTestIgnored(description.getMethodName)
}
override def fireTestAssumptionFailed(
failure: notification.Failure
): Unit = {
isReported += failure.description
reporter.reportAssumptionViolation(
failure.description.getMethodName,
elapsedMillis(),
Expand All @@ -36,7 +38,7 @@ class MUnitRunNotifier(reporter: JUnitReporter) extends RunNotifier {
}
override def fireTestFailure(failure: notification.Failure): Unit = {
val methodName = failure.description.getMethodName
isFailed += methodName
isReported += failure.description
reporter.reportTestFailed(
methodName,
failure.ex,
Expand All @@ -46,7 +48,7 @@ class MUnitRunNotifier(reporter: JUnitReporter) extends RunNotifier {
override def fireTestFinished(description: Description): Unit = {
val methodName = description.getMethodName
total += 1
if (!isFailed(methodName)) {
if (!isReported(description)) {
reporter.reportTestPassed(
methodName,
elapsedMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class ScalaCheckFrameworkSuite extends ScalaCheckSuite {
}
}

override def munitFlakyOK: Boolean = true
test("flaky test".flaky) {
forAll { (i: Int) =>
assertEquals(1, 0)
}
}

}

object ScalaCheckFrameworkSuite
Expand Down Expand Up @@ -78,5 +85,6 @@ object ScalaCheckFrameworkSuite
|Falsified after 0 passed tests.
|> ARG_0: -1
|> ARG_0_ORIGINAL: 2147483647
|==> skipped munit.ScalaCheckFrameworkSuite.flaky test - ignoring flaky test failure
|""".stripMargin
)

0 comments on commit 9653a0e

Please sign in to comment.