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

Update discipline-scalatest #3259

Merged
Merged
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 @@ -8,7 +8,7 @@ import cats.syntax.{AllSyntax, EqOps}
import cats.tests.StrictCatsEquality
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.typelevel.discipline.scalatest.Discipline
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.matchers.should.Matchers
Expand All @@ -23,7 +23,7 @@ trait AlleycatsSuite
extends AnyFunSuiteLike
with Matchers
with ScalaCheckDrivenPropertyChecks
with Discipline
with FunSuiteDiscipline
with TestSettings
with AllInstances
with AllSyntax
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val scalatestplusScalaCheckVersion = "3.1.0.1"

val disciplineVersion = "1.0.2"

val disciplineScalatestVersion = "1.0.0-RC2"
val disciplineScalatestVersion = "1.0.0-RC4"

val kindProjectorVersion = "0.11.0"

Expand Down
14 changes: 8 additions & 6 deletions docs/src/main/tut/typeclasses/lawtesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ this conversion for two test frameworks: `ScalaTest` and `Specs2`.

* If you are using `Specs2`, extend your test class with `org.typelevel.discipline.specs2.Discipline` (provided by `discipline-specs2`).

* If you are using `ScalaTest`, extend your test class with `org.typelevel.discipline.scalatest.Discipline` (provided by `discipline-scalatest`) and `org.scalatest.funsuite.AnyFunSuiteLike`.
* If you are using `ScalaTest`, extend your test class with `org.typelevel.discipline.scalatest.FunSuiteDiscipline` (provided by `discipline-scalatest`) and `org.scalatest.funsuite.AnyFunSuiteLike`.

* For other test frameworks, you need to resort to their integration with `ScalaCheck` to test
the `ScalaCheck` `Properties` provided by `cats-laws`.
Expand All @@ -95,18 +95,19 @@ The following example is for ScalaTest.
import cats.implicits._
import cats.laws.discipline.FunctorTests
import org.scalatest.funsuite.AnyFunSuite
import org.typelevel.discipline.scalatest.Discipline
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import arbitraries._

class TreeLawTests extends AnyFunSuite with Discipline {
class TreeLawTests extends AnyFunSuite with FunSuiteDiscipline with Checkers {
checkAll("Tree.FunctorLaws", FunctorTests[Tree].functor[Int, Int, String])
}
```

* `cats.implicits._` imports the instances we need for `Eq[Tree[Int]]`, which the laws use to compare trees.
* `FunctorTests` contains the functor laws.
* `AnyFunSuite` defines the style of ScalaTest.
* `Discipline` provides `checkAll`, and must be mixed into `AnyFunSuite`
* `FunSuiteDiscipline` provides `checkAll`, and must be mixed into `AnyFunSuite`
* `arbitraries._` imports the `Arbitrary[Tree[_]]` instances needed to check the laws.

Alternatively, you can use the `CatsSuite` provided by [Cats-testkit-scalatest](https://github.com/typelevel/cats-testkit-scalatest),
Expand Down Expand Up @@ -161,10 +162,11 @@ import cats.implicits._
import cats.kernel.laws.discipline.SemigroupTests
import cats.laws.discipline.FunctorTests
import org.scalatest.funsuite.AnyFunSuite
import org.typelevel.discipline.scalatest.Discipline
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import arbitraries._

class TreeLawTests extends AnyFunSuite with Discipline {
class TreeLawTests extends AnyFunSuite with FunSuiteDiscipline with Checkers {
checkAll("Tree[Int].SemigroupLaws", SemigroupTests[Tree[Int]].semigroup)
checkAll("Tree.FunctorLaws", FunctorTests[Tree].functor[Int, Int, String])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import cats.kernel.instances.all._
import cats.kernel.laws.discipline._
import cats.platform.Platform

import org.typelevel.discipline.scalatest.Discipline
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import org.scalacheck.{Arbitrary, Cogen, Gen}
import Arbitrary.arbitrary
import org.scalactic.anyvals.{PosInt, PosZInt}
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatestplus.scalacheck.Checkers

import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.collection.immutable.{BitSet, Queue, SortedMap, SortedSet}
Expand Down Expand Up @@ -133,17 +134,19 @@ object KernelCheck {
}
}

class Tests extends AnyFunSuiteLike with Discipline with ScalaVersionSpecificTests {

import KernelCheck._

class TestsConfig extends Checkers {
// The ScalaCheck defaults (100,100) are too high for Scala.js.
final val PropMaxSize: PosZInt = if (Platform.isJs) 10 else 100
final val PropMinSuccessful: PosInt = if (Platform.isJs) 10 else 100
final val PropWorkers: PosInt = if (Platform.isJvm) PosInt(2) else PosInt(1)

implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
PropertyCheckConfiguration(minSuccessful = PropMinSuccessful, sizeRange = PropMaxSize, workers = PropWorkers)
}

class Tests extends TestsConfig with AnyFunSuiteLike with FunSuiteDiscipline with ScalaVersionSpecificTests {

import KernelCheck._

{
// needed for Cogen[Map[...]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package discipline
import cats.instances.all._
import cats.laws.discipline.arbitrary._
import org.scalatest.funsuite.AnyFunSuiteLike
import org.typelevel.discipline.scalatest.Discipline
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline

class MonadTestsTests extends AnyFunSuiteLike with Discipline {
class MonadTestsTests extends AnyFunSuiteLike with FunSuiteDiscipline with Checkers {
// We don't use `stackUnsafeMonad` in our laws checking for instances in Cats,
// so we confirm here that the laws pass for `Eval` (the monad instance for
// which is actually stack safe, like all other monad instances in Cats.)
Expand Down
3 changes: 2 additions & 1 deletion tests/src/test/scala/cats/tests/AndThenSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import cats.arrow._
import cats.laws.discipline.eq._
import cats.laws.discipline.arbitrary._
import cats.platform.Platform
import org.scalatestplus.scalacheck.Checkers

class AndThenSuite extends CatsSuite {
class AndThenSuite extends CatsSuite with Checkers {
checkAll("AndThen[MiniInt, Int]", SemigroupalTests[AndThen[MiniInt, *]].semigroupal[Int, Int, Int])
checkAll("Semigroupal[AndThen[Int, *]]", SerializableTests.serializable(Semigroupal[AndThen[Int, *]]))

Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/CatsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.Configuration
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.typelevel.discipline.scalatest.Discipline
import org.typelevel.discipline.scalatest.FunSuiteDiscipline

trait TestSettings extends Configuration with Matchers {

Expand All @@ -35,7 +35,7 @@ trait CatsSuite
extends AnyFunSuiteLike
with Matchers
with ScalaCheckDrivenPropertyChecks
with Discipline
with FunSuiteDiscipline
with TestSettings
with AllInstances
with AllInstancesBinCompat0
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/ParallelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import org.scalatest.funsuite.AnyFunSuiteLike
import cats.laws.discipline.{ApplicativeErrorTests, MiniInt, NonEmptyParallelTests, ParallelTests, SerializableTests}
import cats.laws.discipline.eq._
import cats.laws.discipline.arbitrary._
import org.typelevel.discipline.scalatest.Discipline
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import scala.collection.immutable.SortedSet
import kernel.compat.scalaVersionSpecific._

Expand Down Expand Up @@ -498,7 +499,7 @@ class ParallelSuite extends CatsSuite with ApplicativeErrorForEitherTest with Sc
}
}

trait ApplicativeErrorForEitherTest extends AnyFunSuiteLike with Discipline {
trait ApplicativeErrorForEitherTest extends AnyFunSuiteLike with FunSuiteDiscipline with Checkers {

import cats.instances.either._
import cats.instances.string._
Expand Down