Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

mrdziuban/scalacheck-magnolia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecation Notice

This library is deprecated and no longer kept up to date or otherwise maintained. Consider using magnolify-scalacheck module instead.

scalacheck-magnolia

scalacheck-magnolia performs generic derivation of scalacheck Arbitrary instances for product and sum types, i.e. case classes and ADTs, using Magnolia. Much of the code was inspired by scalacheck-shapeless, which I've found to work reliably, but cause huge compile time increases, especially for deeply nested case classes.

Usage

Add to your build.sbt:

resolvers += "mrdziuban-maven" at "https://raw.githubusercontent.com/mrdziuban/maven-repo/master"
libraryDependencies += "com.mrdziuban" %% "scalacheck-magnolia" % "0.5.0"

This will pull in scalacheck 1.15.4 and magnolia 0.17.0.

To materialize Arbitrary instances for your case classes or sealed traits, import com.mrdziuban.ScalacheckMagnolia._. Magnolia can derive Arbitrary instances for case classes

import com.mrdziuban.ScalacheckMagnolia._
import org.scalacheck.Arbitrary

case class Test(i: Int, b: Boolean, s: String)

implicitly[Arbitrary[Test]]

as well as for sealed traits

sealed trait Foo
case object Bar extends Foo
case class Baz(s: String) extends Foo

implicitly[Arbitrary[Foo]]

It can be used in scalacheck property tests like so:

import org.scalacheck.Prop.forAll

forAll((_: Test) => true /* check some properties of Test */)

License

Released under the Apache 2.0 license. See the LICENSE file for more details.

About

Scalacheck Arbitrary derivation using magnolia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages