scalacheck-effect-munit


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

org.typelevel
ArtifactId

ArtifactId

scalacheck-effect-munit_0.27
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

scalacheck-effect-munit
scalacheck-effect-munit
Project URL

Project URL

https://github.com/typelevel/scalacheck-effect
Project Organization

Project Organization

Typelevel
Source Code Management

Source Code Management

https://github.com/typelevel/scalacheck-effect

Download scalacheck-effect-munit_0.27

How to add to project

<!-- https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.27/ -->
<dependency>
    <groupId>org.typelevel</groupId>
    <artifactId>scalacheck-effect-munit_0.27</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.27/
implementation 'org.typelevel:scalacheck-effect-munit_0.27:0.5.0'
// https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.27/
implementation ("org.typelevel:scalacheck-effect-munit_0.27:0.5.0")
'org.typelevel:scalacheck-effect-munit_0.27:jar:0.5.0'
<dependency org="org.typelevel" name="scalacheck-effect-munit_0.27" rev="0.5.0">
  <artifact name="scalacheck-effect-munit_0.27" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.typelevel', module='scalacheck-effect-munit_0.27', version='0.5.0')
)
libraryDependencies += "org.typelevel" % "scalacheck-effect-munit_0.27" % "0.5.0"
[org.typelevel/scalacheck-effect-munit_0.27 "0.5.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.typelevel : scalacheck-effect_0.27 jar 0.5.0
ch.epfl.lamp : dotty-library_0.27 jar 0.27.0-RC1
org.scalameta : munit-scalacheck_0.27 jar 0.7.16

Project Modules

There are no modules declared in this project.

ScalaCheck Effect

Continuous Integration Gitter Chat Latest version

ScalaCheck Effect is a library that extends the functionality of ScalaCheck to support "effectful" properties. An effectful property is one that evaluates each sample in some type constructor F[_]. For example:

import org.scalacheck.effect.PropF
import org.scalacheck.Test
import cats.effect.{ExitCode, IO, IOApp}

object Example extends IOApp {
  def run(args: List[String]): IO[ExitCode] = {
    val p: PropF[IO] = 
      PropF.forAllF { (x: Int) =>
        IO(x).start.flatMap(_.join).map(res => assert(res == x))
      }

    val result: IO[Test.Result] = p.check()

    result.flatMap(r => IO(println(r))).as(ExitCode.Success)
  }
}

Running this program results in the output: Result(Passed,100,0,Map(),0).

This library provides the org.scalacheck.effect.PropF type, which is the effectul analog to org.scalacheck.Prop. In this example, we use PropF.forAllF to write a property of the shape Int => IO[Unit]. This example uses cats.effect.IO as the type constructor, but any effect F[_] with an instance of MonadError[F, Throwable] can be used, including scala.concurrent.Future.

The key idea here is using the PropF.{forAllF, forAllNoShrinkF} methods to create PropF[F] instances. The check() method on PropF converts a PropF[F] to a F[Test.Result].

sbt dependency

libraryDependencies += "org.typelevel" %% "scalacheck-effect" % scalacheckEffectVersion

MUnit Integration

This project also provides support for checking PropF values from within MUnit based test suites.

import munit.{CatsEffectSuite, ScalaCheckEffectSuite}
import org.scalacheck.effect.PropF

// Example assumes https://github.com/scalameta/munit/pull/134 is merged, which adds CatsEffectSuite to munit

class ExampleSuite extends ScalaCheckEffectSuite with CatsEffectSuite {
  test("first PropF test") {
    PropF.forAllF { (x: Int) =>
      IO(x).start.flatMap(_.join).map(res => assert(res == x))
    }
  }
}

Design Goals

  • Support effectful properties without blocking.
  • Compatibility with Gen/Cogen/Arbitrary.
  • Parity with Prop features, including shrinking.
  • Follow same style as ScalaCheck and use ScalaCheck reporting.
  • Integrate well with popular test frameworks.
  • Non-goal: provide direct support for checking effectful properties directly from SBT or from standalone app.

Frequently Asked Questions

Why not just call Await.result / unsafeRunSync inside a property definition?

Calling Await.result, unsafeRunSync() or a similar blocking operation is not possible on Scala.js.

Acknowledgements

This library builds heavily on the ideas in ScalaCheck. It grew out of the FS2 AsyncPropertySuite, which only implemented a handful of features. The Weaver Test framework also has similar support for effectful properties. Finally, the Scala Hedgehog library has a prototype of similar functionality.

org.typelevel

typelevel.scala

Let the Scala compiler work for you.

Versions

Version
0.5.0
0.4.0
0.3.0
0.2.0
0.1-6265580
0.1-2865108
0.1-850864b
0.1-24199c8
0.1-7095afb
0.1-00731f7
0.1-604abc9
0.1-435d4be
0.1-284a244
0.1-156ac13
0.1-68b2a4b
0.1-49a2bca
0.1-47e7b17
0.1-22c7f54
0.1-19-c573649
0.1-17-6b5f003
0.1-15-c70cc11
0.1-9b423f7
0.1-08fbacd
0.1-7bf552b
0.1-6e17247
0.1-6b2df32
0.1-5b0b85a
0.1-03fe43f
0.1-3dcb32f
0.1-1eee311
0.1-1e36296
0.1-1a1a4ff
0.1-fdd6fbe
0.1-f496545
0.1-f7ca13d
0.1-ef7d21b
0.1-e68635e
0.1-e2cca09
0.1-d226688
0.1-00d2728
0.1-d8d0d55
0.1-d7c4f06
0.1-bee8d62
0.1-ad94149
0.1.0
0.1-b8f258c
0.1-b5f9ccc
0.1-a6444b4
0.1-a8aafb5
0.1-a6fe8cc
0.0-5835409