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

Support for cats 0.8.0 #59

Closed
nmeln opened this issue Nov 2, 2016 · 14 comments
Closed

Support for cats 0.8.0 #59

nmeln opened this issue Nov 2, 2016 · 14 comments

Comments

@nmeln
Copy link

nmeln commented Nov 2, 2016

Xor is gone in cats 0.8.0.
typelevel/cats#1310

AFAIK kantan.csv-cats uses Xor, so migration to Either is needed.

@nrinaudo
Copy link
Owner

nrinaudo commented Nov 2, 2016

Yes, you're absolutely correct. I'm actually working on that as we speak, but it forces other issues to the front: I need to upgrade to more recent versions of scalacheck and discipline, which break a lot of things.

But yes, that's what's driving the next release and it's at the top of the list of priorities.

@ScalaWilliam
Copy link

ScalaWilliam commented Nov 3, 2016

Managed to reduce to:

import org.scalacheck._
import org.scalacheck.derive._
import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks

class Testor extends FunSuite with GeneratorDrivenPropertyChecks
  with DerivedInstances
{
  sealed trait Or[+A, +B] extends Product with Serializable

  case class Left[A](a: A) extends Or[A, Nothing]

  case class Right[B](b: B) extends Or[Nothing, B]

  type T = Unit  Float Or Boolean

  test("Rep again") {
    var good: Int = 0
    var bad: Int = 0
    var caught: Throwable = null
    val frall = Prop.forAll({
      (a: T) =>
        try {
          a(())
          good = good + 1
        }
        catch {
          case e: Throwable =>
            bad = bad + 1
            caught = e
        }
        Prop(true)
    })
    frall.main(Array.empty)
    info(s"Good = ${good}, Bad = ${bad}")
    throw caught
  }
}
[info] - Rep again *** FAILED ***
[info]   org.scalacheck.Gen$RetrievalError: couldn't generate value
[info]   at org.scalacheck.Gen.loop$1(Gen.scala:57)
[info]   at org.scalacheck.Gen.doPureApply(Gen.scala:58)
[info]   at org.scalacheck.Gen.pureApply(Gen.scala:72)
[info]   at org.scalacheck.GenArities$$anonfun$function1$1$$anonfun$1.apply(GenArities.scala:15)
[info]   at Testor$$anonfun$1$$anonfun$2.apply(Testor.scala:22)
[info]   at Testor$$anonfun$1$$anonfun$2.apply(Testor.scala:20)
[info]   at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
[info]   at org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:712)
[info]   at org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:712)
[info]   at org.scalacheck.Prop$.secure(Prop.scala:456)
[info]   ...
[info]   + Good = 99, Bad = 1 

@ScalaWilliam
Copy link

Changing to:

sealed trait Or[+A, +B] extends Product with Serializable
case class Left[A, B](a: A) extends Or[A, B]
case class Right[A, B](b: B) extends Or[A, B]

Fixes this for some reason. Do you necessarily needs the Nothing's?
Why not just use Scala's Either?

@ScalaWilliam
Copy link

ScalaWilliam commented Nov 3, 2016

Just looking at the cats, they moved it all to Scala's Either.
If vanilla Either is not working between both versions -- you can have multiple sources per Scala version, and create a type alias for your Or.

@nrinaudo
Copy link
Owner

nrinaudo commented Nov 3, 2016

Thanks a lot for the test cases, I need to look into them as soon as possible.

As or cats having moved to Either, that's not the point of this test. Its purpose is to use shapeless to derive automatic encoder and decoder instances for a "complex" ADT. Or is only ever used in this test.

@ScalaWilliam
Copy link

ScalaWilliam commented Nov 3, 2016

Good news. Reduced the test case further.

import org.scalacheck._
import org.scalacheck.derive._
import org.scalacheck.rng.Seed
import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks

class Testor extends FunSuite with GeneratorDrivenPropertyChecks
  with DerivedInstances {

  sealed trait Or[+A, +B]

  final case class Right[B](b: B) extends Or[Nothing, B]

  type T = Unit  Float Or Boolean

  test("Better test case") {
    val arb = implicitly[Arbitrary[T]].arbitrary
    arb.doPureApply(Gen.Parameters.default.withSize(0), seed = Seed.random(), retries = 0)
      .retrieve.get.apply(())
  }

}

Output:

[info] - Better test case *** FAILED ***
[info]   org.scalacheck.Gen$RetrievalError: couldn't generate value
[info]   at org.scalacheck.Gen.loop$1(Gen.scala:57)
[info]   at org.scalacheck.Gen.doPureApply(Gen.scala:58)
[info]   at org.scalacheck.Gen.pureApply(Gen.scala:72)
[info]   at org.scalacheck.GenArities$$anonfun$function1$1$$anonfun$1.apply(GenArities.scala:15)
[info]   at Testor$$anonfun$1.apply(Testor.scala:19)
[info]   at Testor$$anonfun$1.apply(Testor.scala:16)
[info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
[info]   ...

build.sbt for anyone:

resolvers += Resolver.sonatypeRepo("releases")

libraryDependencies += "com.github.alexarchambault" %% "scalacheck-shapeless_1.13" % "1.1.3"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
scalaVersion := "2.11.8"

When generation size is 0 then Gen.fail is used. I'm not sure what is the purpose of this is so far. Here's the specific line of code.

https://github.com/alexarchambault/scalacheck-shapeless/blob/master/core/shared/src/main/scala/org/scalacheck/derive/MkArbitrary.scala#L120

So:

  • Either ScalaCheck is wrongly calling generation size 0
  • Or MkArbitrary uses Gen.fail incorrectly.

@ScalaWilliam
Copy link

Maybe @alexarchambault has something to say?

@alexarchambault
Copy link

@ScalaWilliam
Copy link

@nrinaudo that should be a sufficient solution

@nrinaudo
Copy link
Owner

nrinaudo commented Nov 4, 2016

It would be, but it doesn't actually work - yet. I might be doing something wrong. Or, alternatively, if @alexarchambault intends to fix that at the scalacheck-shapeless level, I've no issue with disabling these tests and re-enabling them when a fix a available.

nrinaudo added a commit that referenced this issue Nov 4, 2016
Of particular interest, this means:
- upgrading to cats 0.8.0 (#59)
- upgrading to scalacheck 1.13.
@nrinaudo
Copy link
Owner

nrinaudo commented Nov 6, 2016

0.1.16-SNAPSHOT is being published as I type this and has support for cats 0.8.0.

@nrinaudo
Copy link
Owner

nrinaudo commented Nov 8, 2016

Note that I'm waiting on #58 before releasing 0.1.16. It's just a matter of time - I'm still waiting for a typelevel cats 2.12.0 build, which I believe is ready and just needs to be published.

@ScalaWilliam
Copy link

What resolver should I use? Doesn't work for me.

@nrinaudo
Copy link
Owner

nrinaudo commented Nov 9, 2016

@ScalaWilliam ah, yes, not everyone has sonatype-snapshots enabled by default :)

This is what you need:

scalaVersion := "2.11.8"

resolvers := Seq(Resolver.sonatypeRepo("snapshots"))

libraryDependencies += "com.nrinaudo" %% "kantan.csv" % "0.1.16-SNAPSHOT"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants