These are chat archives for etorreborre/specs2

22nd
Jan 2018
Marko Dimjašević
@mdimjasevic
Jan 22 2018 10:09
Hi all!
It seems to me that this is a frequently asked question: how to set a seed when using specs2 with ScalaCheck?
Eric Torreborre
@etorreborre
Jan 22 2018 10:16
Hi, I don't think this is possible because ScalaCheck does not expose it as a parameter (last time I checked). If someone had some time to investigate the current ScalaCheck sources and prove me wrong, I would be happy to change specs2 and expose the seed as well. Do you have time to do that @mdimjasevic ?
Marko Dimjašević
@mdimjasevic
Jan 22 2018 10:24
Eric, I'll take a look at it as I've been using the specs2+scalacheck combo for a while now and this is a really important feature that has been missing
Eric Torreborre
@etorreborre
Jan 22 2018 10:25
Thank you (I'm really short on time ATM). Maybe if it is not exposed in ScalaCheck, it is just a PR away?
Marko Dimjašević
@mdimjasevic
Jan 22 2018 10:29
I'm not too familiar with ScalaCheck internals, so I don't know where a change would have to be made
You can use a Prop inside a specs2 example and use this method but the best would be to integrate it with the rest of the specs2 API for ScalaCheck. Do you want me to guide you so you can PR this? The other option is to give me a bit more time this week to have a go at it
Marko Dimjašević
@mdimjasevic
Jan 22 2018 10:47
sure, I'd be happy to be guided
Just as a heads up, I vaguely remember trying to use useSeed or something like it for setting the seed before, but without luck
I believe I was trying to use something from the Gen object, not from Prop.
Marko Dimjašević
@mdimjasevic
Jan 22 2018 10:54
Before we dive into this, can you tell me how this is gonna be used?
Eric Torreborre
@etorreborre
Jan 22 2018 11:00

I am expecting something like

class MySpec extends Specification with ScalaCheck { def is = s2"""

  this is a property $p1

""" 
  def p1 = prop { n: Int =>
      n + 1 === 1 + n
  }.setSeed(123456789L)
}

And you should be able to set the seed from the command-line as well (like other scalacheck properties in specs2)

sbt> testOnly *MySpec -- scalacheck.seed 123456789
Marko Dimjašević
@mdimjasevic
Jan 22 2018 11:00
that would be cool!
In the case of failure, would it print out the seed?
Maybe that's another thing to take care of
Eric Torreborre
@etorreborre
Jan 22 2018 11:01
Yes definitely
Marko Dimjašević
@mdimjasevic
Jan 22 2018 11:02
Cool, please let me what should I start with!
Marko Dimjašević
@mdimjasevic
Jan 22 2018 11:38
Wow, thanks for this! I'll get started right away.
Marko Dimjašević
@mdimjasevic
Jan 22 2018 12:01
Should I make the seed argument of type Option[Long]?
Eric Torreborre
@etorreborre
Jan 22 2018 12:10
Yes, I think that we can use Seed.apply to create a Seed passed to useSeed
Marko Dimjašević
@mdimjasevic
Jan 22 2018 12:13
Sounds good.
Marko Dimjašević
@mdimjasevic
Jan 22 2018 13:21
@etorreborre: I didn't get your comments about using code generation. If I didn't do something incorrect, I simply added the setSeed method to the ScalaCheckFunction trait like this:
  def setSeed(seed: Option[Long]): SelfType =
    setParameters(parameters.copy(seed = seed))
Probably I should make it of type Long => SelfType instead so that an end-user doesn't have to wrap a seed value with the Some constructor.
Btw, my hunch is that you are missing a link in your 5th bullet point above
Marko Dimjašević
@mdimjasevic
Jan 22 2018 14:27