org.typelevel.discipline.scalatest.FunSuiteDiscipline Scala Examples
The following examples show how to use org.typelevel.discipline.scalatest.FunSuiteDiscipline.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: BaseLawsSpec.scala From seals with Apache License 2.0 | 5 votes |
package dev.tauri.seals package tests import java.util.UUID import cats.Eq import cats.kernel.laws.discipline._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.prop.Configuration import org.scalacheck.{ Arbitrary, Gen } import org.scalacheck.util.Buildable import org.typelevel.discipline.scalatest.FunSuiteDiscipline import laws.{ AnyLaws, AtomicLaws } trait BaseLawsSpec extends AnyFunSuite with FunSuiteDiscipline with Configuration with laws.TestEqInstances with laws.TestArbInstances { implicit val eqForUuid: Eq[UUID] = Eq.fromUniversalEquals implicit def eqForJavaEnums[A <: java.lang.Enum[A]]: Eq[A] = referenceEq[A] def checkAtomicLaws[A](name: String)(implicit a: Arbitrary[A], e: Eq[A], at: Atomic[A]): Unit = { checkAll(s"Atomic[$name].AnyLaws.any", AnyLaws[Atomic[A]].any) checkAll(s"Atomic[$name].AnyLaws.equalitySerializability", AnyLaws[Atomic[A]].equalitySerializability) checkAll(s"Atomic[$name].AnyLaws.referenceEquality", AnyLaws[Atomic[A]].referenceEquality) checkAll(s"Atomic[$name].EqTests.eqv", EqTests[Atomic[A]].eqv) checkAll(s"Atomic[$name].AtomicLaws.roundtrip", AtomicLaws[A].roundtrip) } protected val maxContainerSize = 3 object LimitedContainers { implicit def arbCont[F[_], A]( implicit A: Arbitrary[A], B: Buildable[A, F[A]], T: F[A] => Traversable[A] ): Arbitrary[F[A]] = Arbitrary { for { n <- Gen.choose(0, maxContainerSize) v <- Gen.containerOfN[F, A](n, A.arbitrary) } yield v } } }
Example 2
Source File: LawTests.scala From paiges with Apache License 2.0 | 5 votes |
package org.typelevel.paiges import cats.Semigroupal import cats.Contravariant import cats.kernel.{Eq, Monoid} import cats.laws.discipline.{ContravariantTests, DeferTests, ExhaustiveCheck, SemigroupalTests, SerializableTests} import cats.kernel.laws.discipline.MonoidTests import cats.laws.discipline.eq.catsLawsEqForFn1Exhaustive import org.typelevel.discipline.scalatest.FunSuiteDiscipline import org.scalacheck.Arbitrary import org.scalactic.anyvals.{PosInt, PosZDouble, PosZInt} import org.scalatest.funsuite.AnyFunSuite import org.scalatest.prop.Configuration class LawTests extends LawChecking with CatsDocument { import org.typelevel.paiges.Generators._ import org.typelevel.paiges.instances._ implicit val docEq: Eq[Doc] = Eq.instance((x: Doc, y: Doc) => PaigesTest.docEquiv.equiv(x, y)) implicit def monoidTests[A: Eq: Arbitrary: Monoid] = MonoidTests[A] implicit def arbitraryForDocument[A]: Arbitrary[Document[A]] = Arbitrary(Document.useToString[A]) implicit def eqForDocument[A: ExhaustiveCheck]: Eq[Document[A]] = Eq.by[Document[A], A => Doc](inst => (a: A) => inst.document(a)) implicit val eqBool: Eq[Boolean] = Eq.instance[Boolean](_ == _) checkAll("Monoid[Doc]", MonoidTests[Doc].monoid) checkAll("Monoid[Style]", MonoidTests[Style].monoid) checkAll("Contravariant[Document]", ContravariantTests[Document].contravariant[Boolean, Boolean, Boolean]) checkAll("Contravariant[Document]", SerializableTests.serializable(Contravariant[Document])) checkAll("Defer[Document]", DeferTests[Document].defer[Boolean]) { implicit val semigroupalDocument: Semigroupal[Document] = CatsDocument.semigroupalDocument(Doc.char(',')) checkAll("Semigroupal[Document]", SemigroupalTests[Document].semigroupal[Boolean, Boolean, Boolean]) checkAll("Semigroupal[Document]", SerializableTests.serializable(Semigroupal[Document])) } } abstract class LawChecking extends AnyFunSuite with Configuration with FunSuiteDiscipline { lazy val checkConfiguration: PropertyCheckConfiguration = PropertyCheckConfiguration( minSuccessful = if (Platform.isJvm) PosInt(50) else PosInt(5), maxDiscardedFactor = if (Platform.isJvm) PosZDouble(5.0) else PosZDouble(50.0), minSize = PosZInt(0), sizeRange = if (Platform.isJvm) PosZInt(10) else PosZInt(5), workers = PosInt(1) ) // The scalacheck defaults 'sizeRange' (100) is too high for Scala-js, so we reduce to 10. // We also set `minSuccessful` to 100 unconditionally. implicit override val generatorDrivenConfig: PropertyCheckConfiguration = if (Platform.isJvm) PropertyCheckConfiguration(sizeRange = 100, minSuccessful = 100) else PropertyCheckConfiguration(sizeRange = 10, minSuccessful = 100) }
Example 3
Source File: service.scala From catbird with Apache License 2.0 | 5 votes |
package io.catbird.finagle import cats.instances.int._ import cats.kernel.Eq import cats.laws.discipline._ import cats.laws.discipline.eq._ import com.twitter.conversions.DurationOps._ import com.twitter.finagle.Service import org.scalatest.funsuite.AnyFunSuite import org.scalatest.prop.Configuration import org.typelevel.discipline.scalatest.FunSuiteDiscipline class ServiceSuite extends AnyFunSuite with FunSuiteDiscipline with Configuration with ServiceInstances with ArbitraryInstances with EqInstances { implicit val eq: Eq[Service[Boolean, Int]] = serviceEq(1.second) checkAll("Service", CategoryTests[Service].compose[Boolean, Int, Boolean, Int]) checkAll("Service", CategoryTests[Service].category[Boolean, Int, Boolean, Int]) checkAll("Service", ProfunctorTests[Service].profunctor[Boolean, Int, Boolean, Int, Boolean, Int]) }
Example 4
Source File: RerunnableSuite.scala From catbird with Apache License 2.0 | 5 votes |
package io.catbird.util.effect import cats.effect.laws.discipline.EffectTests import cats.effect.laws.discipline.arbitrary.catsEffectLawsArbitraryForIO import cats.effect.laws.util.{ TestContext, TestInstances } import cats.effect.{ Bracket, IO } import cats.instances.either._ import cats.instances.int._ import cats.instances.tuple._ import cats.instances.unit._ import cats.kernel.Eq import cats.laws.discipline.arbitrary._ import com.twitter.util.{ Await, Monitor, Throw } import io.catbird.util.{ ArbitraryInstances, Rerunnable } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.prop.Configuration import org.typelevel.discipline.scalatest.FunSuiteDiscipline class RerunnableSuite extends AnyFunSuite with FunSuiteDiscipline with Configuration with ArbitraryInstances with TestInstances { implicit val context: TestContext = TestContext() implicit def rerunnableEq[A](implicit A: Eq[A]): Eq[Rerunnable[A]] = Eq.by[Rerunnable[A], IO[A]](rerunnableToIO) checkAll("Rerunnable[Int]", EffectTests[Rerunnable].effect[Int, Int, Int]) test("Exceptions thrown by release are handled by Monitor") { val useException = new Exception("thrown by use") val releaseException = new Exception("thrown by release") var monitoredException: Throwable = null val monitor = Monitor.mk { case e => monitoredException = e; true; } val rerunnable = Bracket[Rerunnable, Throwable] .bracket(Rerunnable.Unit)(_ => Rerunnable.raiseError(useException))(_ => Rerunnable.raiseError(releaseException)) .liftToTry val result = Await.result(Monitor.using(monitor)(rerunnable.run)) assert(result == Throw(useException)) assert(monitoredException == releaseException) } }
Example 5
Source File: KittensSuite.scala From kittens with Apache License 2.0 | 5 votes |
package cats.derived import cats.syntax.AllSyntax import cats.tests.{StrictCatsEquality, TestSettings} import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import org.scalatestplus.scalacheck.Checkers import org.typelevel.discipline.scalatest.FunSuiteDiscipline abstract class KittensSuite extends AnyFunSuite with Matchers with Checkers with FunSuiteDiscipline with TestSettings with AllSyntax with StrictCatsEquality { implicit override val generatorDrivenConfig: PropertyCheckConfiguration = checkConfiguration }
Example 6
Source File: BifunctorSpec.scala From kafka4s with Apache License 2.0 | 5 votes |
package com.banno.kafka import cats.laws.discipline.BifunctorTests import com.banno.kafka.test._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import org.scalatestplus.scalacheck.Checkers import org.typelevel.discipline.scalatest.FunSuiteDiscipline class BifunctorSpec extends AnyFunSuite with Matchers with Checkers with FunSuiteDiscipline { checkAll( "ProducerRecordBifunctor", BifunctorTests(ProducerRecordBifunctor).bifunctor[Int, Int, Int, String, String, String] ) checkAll( "ConsumerRecordBifunctor", BifunctorTests(ConsumerRecordBifunctor).bifunctor[Int, Int, Int, String, String, String] ) }
Example 7
Source File: BaseTestsSuite.scala From cats-effect with Apache License 2.0 | 5 votes |
package cats.effect import cats.effect.internals.TestUtils import cats.effect.laws.util.{TestContext, TestInstances} import org.scalactic.source import org.scalatest.Tag import org.scalatest.matchers.should.Matchers import org.scalatest.funsuite.AnyFunSuite import org.scalatestplus.scalacheck.Checkers import org.typelevel.discipline.Laws import org.typelevel.discipline.scalatest.FunSuiteDiscipline class BaseTestsSuite extends AnyFunSuite with Matchers with Checkers with FunSuiteDiscipline with TestInstances with TestUtils { def testAsync[A](name: String, tags: Tag*)(f: TestContext => Unit)(implicit pos: source.Position): Unit = // Overriding System.err test(name, tags: _*)(silenceSystemErr(f(TestContext())))(pos) def checkAllAsync(name: String, f: TestContext => Laws#RuleSet): Unit = { val context = TestContext() val ruleSet = f(context) for ((id, prop) <- ruleSet.all.properties) test(name + "." + id) { silenceSystemErr(check(prop)) } } }
Example 8
Source File: catzSpecBase.scala From interop-cats with Apache License 2.0 | 5 votes |
package zio.interop import cats.Eq import cats.effect.laws.util.{ TestContext, TestInstances } import cats.implicits._ import org.scalacheck.Arbitrary import org.scalatest.funsuite.AnyFunSuite import org.scalatest.prop.Configuration import org.typelevel.discipline.Laws import org.typelevel.discipline.scalatest.FunSuiteDiscipline import zio.clock.Clock import zio.console.Console import zio.internal.{ Executor, Platform, Tracing } import zio.interop.catz.taskEffectInstance import zio.random.Random import zio.system.System import zio.{ =!=, Cause, IO, Runtime, Task, UIO, ZIO, ZManaged } private[zio] trait catzSpecBase extends AnyFunSuite with FunSuiteDiscipline with Configuration with TestInstances with catzSpecBaseLowPriority { type Env = Clock with Console with System with Random implicit def rts(implicit tc: TestContext): Runtime[Unit] = Runtime( (), Platform .fromExecutor(Executor.fromExecutionContext(Int.MaxValue)(tc)) .withTracing(Tracing.disabled) .withReportFailure(_ => ()) ) implicit val zioEqCauseNothing: Eq[Cause[Nothing]] = Eq.fromUniversalEquals implicit def zioEqIO[E: Eq, A: Eq](implicit rts: Runtime[Any], tc: TestContext): Eq[IO[E, A]] = Eq.by(_.either) implicit def zioEqTask[A: Eq](implicit rts: Runtime[Any], tc: TestContext): Eq[Task[A]] = Eq.by(_.either) implicit def zioEqUIO[A: Eq](implicit rts: Runtime[Any], tc: TestContext): Eq[UIO[A]] = Eq.by(uio => taskEffectInstance.toIO(uio.sandbox.either)) implicit def zioEqZManaged[E: Eq, A: Eq](implicit rts: Runtime[Any], tc: TestContext): Eq[ZManaged[Any, E, A]] = Eq.by( zm => ZManaged.ReleaseMap.make.flatMap(releaseMap => zm.zio.provideSome[Any]((_, releaseMap)).map(_._2).either) ) def checkAllAsync(name: String, f: TestContext => Laws#RuleSet): Unit = checkAll(name, f(TestContext())) } private[interop] sealed trait catzSpecBaseLowPriority { this: catzSpecBase => implicit def zioEq[R: Arbitrary, E: Eq, A: Eq](implicit rts: Runtime[Any], tc: TestContext): Eq[ZIO[R, E, A]] = { def run(r: R, zio: ZIO[R, E, A]) = taskEffectInstance.toIO(zio.provide(r).either) Eq.instance((io1, io2) => Arbitrary.arbitrary[R].sample.fold(false)(r => catsSyntaxEq(run(r, io1)) eqv run(r, io2))) } // 'R =!= Any' evidence fixes the 'diverging implicit expansion for type Arbitrary' error reproducible on scala 2.12 and 2.11. implicit def zmanagedEq[R: * =!= Any: Arbitrary, E: Eq, A: Eq]( implicit rts: Runtime[Any], tc: TestContext ): Eq[ZManaged[R, E, A]] = { def run(r: R, zm: ZManaged[R, E, A]) = taskEffectInstance.toIO( ZManaged.ReleaseMap.make.flatMap(releaseMap => zm.zio.provide((r, releaseMap)).map(_._2).either) ) Eq.instance((io1, io2) => Arbitrary.arbitrary[R].sample.fold(false)(r => catsSyntaxEq(run(r, io1)) eqv run(r, io2))) } }
Example 9
Source File: Cron4sLawSuite.scala From cron4s with Apache License 2.0 | 4 votes |
package cron4s.testkit import cats.instances.AllInstances import cats.syntax.AllSyntax import cron4s.platform.Platform import org.typelevel.discipline.scalatest.FunSuiteDiscipline import org.scalactic.anyvals.{PosInt, PosZInt} import org.scalatest.matchers.should.Matchers import org.scalatest.funsuite.AnyFunSuite import org.scalatest.propspec.AnyPropSpec import org.scalatest.prop.Configuration import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks trait TestSettings extends Configuration { lazy val defaultPropertyCheckConfig: PropertyCheckConfiguration = PropertyCheckConfiguration( minSuccessful = if (Platform.isJvm) PosInt(50) else PosInt(5), minSize = PosZInt(0), sizeRange = if (Platform.isJvm) PosZInt(10) else PosZInt(5), workers = PosInt(1) ) lazy val slowPropertyCheckConfig: PropertyCheckConfiguration = if (Platform.isJvm) defaultPropertyCheckConfig else PropertyCheckConfiguration(minSuccessful = 1, sizeRange = 1) } trait Cron4sLawSuite extends AnyFunSuite with Matchers with ScalaCheckDrivenPropertyChecks with FunSuiteDiscipline with TestSettings with AllInstances with AllSyntax { implicit override val generatorDrivenConfig: PropertyCheckConfiguration = defaultPropertyCheckConfig } trait SlowCron4sLawSuite extends Cron4sLawSuite { implicit override val generatorDrivenConfig: PropertyCheckConfiguration = slowPropertyCheckConfig } abstract class Cron4sPropSpec extends AnyPropSpec with TestSettings { override implicit val generatorDrivenConfig: PropertyCheckConfiguration = defaultPropertyCheckConfig } abstract class SlowCron4sPropSpec extends AnyPropSpec with TestSettings { override implicit val generatorDrivenConfig: PropertyCheckConfiguration = slowPropertyCheckConfig }