tkawachi / sbt-doctest

Doctest for scala
MIT License
182 stars 28 forks source link

Compile error in a Scala.js project #52

Open fthomas opened 9 years ago

fthomas commented 9 years ago

I'm trying to use sbt-doctest in refined which is a JVM/JS cross project. Compiling the test sources for Scala.js (sbt refinedJS/test) yields the following error:

[error] refined/js/target/scala-2.11/src_managed/test/eu/timepit/refined/numericDoctest.scala:16: You may not export a local class
[error] include(new org.scalacheck.Properties("numeric") {
[error] ^
[error] one error found
fthomas commented 9 years ago

I should mention that this can be reproduced by enabling sbt-doctest here: https://github.com/fthomas/refined/blob/d200633c714de3dcb980f55a35520129b1bc91c8/build.sbt#L178

fthomas commented 9 years ago

The above error can be fixed with

--- a/src/main/scala/com/github/tkawachi/doctest/ScalaCheckGen.scala
+++ b/src/main/scala/com/github/tkawachi/doctest/ScalaCheckGen.scala
@@ -22,9 +22,9 @@ object ScalaCheckGen extends TestGen {
   }

   def generateExample(basename: String, parsed: ParsedDoctest): String = {
-    s"""  include(new org.scalacheck.Properties("${parsed.symbol}") {
+    s"""  {
        |${parsed.components.map(gen(parsed.lineNo, _)).mkString("\n\n")}
-       |  })""".stripMargin
+       |  }""".stripMargin
   }

But now I'm getting runtime errors because of the usage of scala.runtime.ScalaRunTime in

  def sbtDoctestReplString(any: Any): String = {
    val s = scala.runtime.ScalaRunTime.replStringOf(any, 1000).init
    if (s.headOption == Some('\n')) s.tail else s
  }

The errors look like this:

[error] Referring to non-existent method jl_Class.getPackage__jl_Package
[error]   called from sr_ScalaRunTime$.packageOf$1__p1__O__T
[error]   called from sr_ScalaRunTime$.isScalaClass$1__p1__O__Z
[error]   called from sr_ScalaRunTime$.useOwnToString$1__p1__O__Z
[error]   called from sr_ScalaRunTime$.inner$1__p1__O__I__T
[error]   called from sr_ScalaRunTime$.$$anonfun$7__p1__I__O__T
[error]   called from sr_ScalaRunTime$.inner$1__p1__O__I__T
[error]     (already seen, not repeating call stack)
[error] involving instantiated classes:
[error]   sr_ScalaRunTime$
ceedubs commented 8 years ago

I think this is related: https://github.com/rickynils/scalacheck/issues/208

tkawachi commented 8 years ago

scala.runtime.ScalaRunTime.replStringOf() is used to get the same string representation as in REPL. It uses methods which is not implemented by Scala.js. https://github.com/scala/scala/blob/v2.11.7/src/library/scala/runtime/ScalaRunTime.scala#L264-L340

I'm afraid it's hard to port replStringOf() to scala.js.

tkawachi commented 8 years ago

The next version will require JvmPlugin. https://github.com/tkawachi/sbt-doctest/commit/08473ab86f2a0d96f20aa35b2d869aec8e03d16e#diff-80f647238c7cff18df190250d41c16eeR35

frgomes commented 7 years ago

You guys may eventually be interested on #78, #80, #84, #85

frgomes commented 7 years ago

The compilation error reported initially is over. But there's still some remaining leftovers. Evidences of that at https://github.com/fthomas/refined/issues/306