Skip to content

Add support for FreeSpec #408

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package scalatest
import org.scalactic.Prettifier
import org.scalactic.source.Position
import org.scalatest.flatspec.AnyFlatSpecLike
import org.scalatest.freespec.AnyFreeSpecLike
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.prop.Configuration
Expand Down Expand Up @@ -74,6 +75,21 @@ trait FlatSpecDiscipline extends Discipline { self: AnyFlatSpecLike with Configu
}
}

// Inherits `AnyFreeSpecLike` to access `FreeSpecStringWrapper`. Until Scala
// 2.13, it was possible to access protected fields of a self-type, but this
// behavior was removed in Scala 3.
trait FreeSpecDiscipline extends AnyFreeSpecLike with Discipline { self: Configuration =>
final def checkAll(name: String,
ruleSet: Laws#RuleSet
)(implicit config: PropertyCheckConfiguration, prettifier: Prettifier, pos: Position): Unit =
name - {
for ((id, prop) <- ruleSet.all.properties)
id in {
Checkers.check(prop)(convertConfiguration(config), prettifier, pos)
}
}
}

trait FunSpecDiscipline extends Discipline { self: AnyFunSpecLike with Configuration =>
final def checkAll(name: String,
ruleSet: Laws#RuleSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package org.typelevel.discipline
package scalatest

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.wordspec.AnyWordSpec
Expand All @@ -33,6 +34,7 @@ trait DummyBase extends Discipline with Checkers {
}

class DummyFlatSpec extends AnyFlatSpec with DummyBase with FlatSpecDiscipline
class DummyFreeSpec extends AnyFreeSpec with DummyBase with FreeSpecDiscipline
class DummyFunSpec extends AnyFunSpec with DummyBase with FunSpecDiscipline
class DummyFunSuite extends AnyFunSuite with DummyBase with FunSuiteDiscipline
class DummyWordSpec extends AnyWordSpec with DummyBase with WordSpecDiscipline