tkawachi / sbt-doctest

Doctest for scala
MIT License
182 stars 28 forks source link

Remove hardcoded references to ScalaTest and/or ScalaCheck #84

Open frgomes opened 7 years ago

frgomes commented 7 years ago

I've noticed that TestGen contains

  def importArbitrary(examples: Seq[ParsedDoctest]): String =
    if (containsProperty(examples)) "import org.scalacheck.Arbitrary._" else ""

  def withCheckers(examples: Seq[ParsedDoctest]): String =
    if (containsProperty(examples)) "with org.scalatest.prop.Checkers" else ""

sbt-doctest should not assume that the user is always going to use ScalaTest + ScalaCheck.

I the case of ScalaJS, chances that the application developer is employing uTest both in the JVM side and JS side. So this issue seems to be related to #52

frgomes commented 7 years ago

@lloydmeta : The idea is that the user determines which test framework and which version of libraries the user needs. As far as I understand, ScalaTest changed the location of checkers and so, in this case, sbt-doctest must be prepared to provide these two flavours.

Ideally, sbt-doctest should not have any hardcoded stuff. However, for maximum convenience, we could refactor the harcoded stuff, keeping it in certain specific locations. Borrowing the example from #88, we could have something like this:

  1. Suppose that the user prefers ScalaTest 3.0.1. In this case, the user configures build.sbt more or less like this:
val scalaTestRunner = "doctest.runner.scalatest.v30.Framework"
val argsDocTest: Seq[String] = ...
val argsScalaTest: Seq[String] = ... // see: http://www.scalatest.org/user_guide/using_the_runner
val args = argsDocTest :: "--" :: argsScalaTest
...
val tf = new sbt.TestFramework(utestRunner)
testFrameworks ++= Seq(tf),
testOptions ++= Seq(Tests.Argument(tf, args)),
...

In this case, the class doctest.runner.scalatest.v30.Framework configures a certain setting which says that org.scalatest.prop.Checkers must be employed.

  1. On the other hand, if class doctest.runner.scalatest.v31.Framework is employed, it will configure a setting which says that org.scalatest.check.Checkers must be used instead.

Please let me know what you think. Suggestions are welcome! :-)

@tkawachi : your feedback, please.

lloydmeta commented 7 years ago

My only recommendation is that whatever solution is taken, that there be a reasonable default provided by this plugin that requires no additional configuration from the end user (e.g. add the this plugin and doctests "should work"). It could, for example that sbt-doctest works out of the box with Scalatest+Scalacheck for mindshare and legacy reasons, and the user can configure it to do otherwise, if they so wish.

tkawachi commented 7 years ago

This plugin generates tests, but not run these. By seeing Framework.java, it seems not for a test generator.

I'm rather thinking to add ScalaTest31 as a subclass of DoctestTestFramework.

tkawachi commented 7 years ago

withCheckers() is only used by ScalaTestGen. It is moved to ScalaTestGen at #92.