Skip to content

Commit

Permalink
Default to reset-class, fixes #190. (#201)
Browse files Browse the repository at this point in the history
Default to reset-class, fixes #190.
  • Loading branch information
olafurpg authored Nov 2, 2019
2 parents d3d4c8e + ef6ed9a commit 57a2770
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 44 deletions.
4 changes: 2 additions & 2 deletions mdoc/src/main/scala/mdoc/internal/markdown/Instrumenter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ object Instrumenter {
val wrapped = new StringBuilder()
.append("package repl\n")
.append("object Session extends _root_.mdoc.internal.document.DocumentBuilder {\n")
.append(" def app(): _root_.scala.Unit = {val _ = App}\n")
.append(" object App {\n")
.append(" def app(): _root_.scala.Unit = {val _ = new App()}\n")
.append(" class App {\n")
.append(body)
.append(" }\n")
.append("}\n")
Expand Down
4 changes: 4 additions & 0 deletions mdoc/src/main/scala/mdoc/internal/markdown/Mod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ object Mod {
case object ResetClass extends Mod {
override def toString: String = "reset-class"
}
case object ResetObject extends Mod {
override def toString: String = "reset-object"
}
case object ToString extends Mod {
override def toString: String = "to-string"
}
Expand All @@ -24,6 +27,7 @@ object Mod {
CompileOnly,
Reset,
ResetClass,
ResetObject,
Fail,
Crash,
Silent,
Expand Down
5 changes: 3 additions & 2 deletions mdoc/src/main/scala/mdoc/internal/markdown/Modifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ sealed abstract class Modifier(val mods: Set[Mod]) {
def isSilent: Boolean = mods(Silent)
def isInvisible: Boolean = mods(Invisible)
def isCompileOnly: Boolean = mods(CompileOnly)
def isReset: Boolean = mods(Reset) || isResetClass
def isResetClass: Boolean = mods(ResetClass)
def isReset: Boolean = isResetClass || isResetObject
def isResetClass: Boolean = mods(ResetClass) || mods(Reset)
def isResetObject: Boolean = mods(ResetObject)
def isToString: Boolean = mods(ToString)
}
object Modifier {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ScalacOptionsSuite extends BaseCliSuite {
val finalInput: String =
"""
|/in.md
|```scala mdoc
|```scala mdoc:reset-object
|sealed abstract class Maybe[+A] extends Product with Serializable
|
|final case class Just[A](value: A) extends Maybe[A]
Expand All @@ -68,7 +68,7 @@ class ScalacOptionsSuite extends BaseCliSuite {
"--scalac-options",
"-Ywarn-unused -Xfatal-warnings"
),
expected = finalInput.replaceFirst("scala mdoc", "scala")
expected = finalInput.replaceFirst("scala mdoc:reset-object", "scala")
)

checkCli(
Expand Down
42 changes: 18 additions & 24 deletions tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,76 +28,70 @@ class AsyncSuite extends BaseMarkdownSuite {
"""|error: timeout.md:4:1: Futures timed out after [10 milliseconds]
|Await.result(Future(Thread.sleep(1000)), Duration("10ms"))
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|java.lang.ExceptionInInitializerError
| at repl.Session$.app(timeout.md:3)
|Caused by: java.util.concurrent.TimeoutException: Futures timed out after [10 milliseconds]
|java.util.concurrent.TimeoutException: Futures timed out after [10 milliseconds]
| at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:259)
| at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:263)
| at scala.concurrent.Await$.$anonfun$result$1(package.scala:219)
| at scala.concurrent.Await$.$anonfun$result$1(package.scala:220)
| at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:57)
| at scala.concurrent.Await$.result(package.scala:146)
| at repl.Session$App$.<init>(timeout.md:11)
| at repl.Session$App$.<clinit>(timeout.md)
| ... 1 more
""".stripMargin,
| at repl.Session$App.<init>(timeout.md:11)
| at repl.Session$.app(timeout.md:3)
|""".stripMargin,
compat = Map(
"2.11" ->
"""|error: timeout.md:4:1: Futures timed out after [10 milliseconds]
|Await.result(Future(Thread.sleep(1000)), Duration("10ms"))
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|java.lang.ExceptionInInitializerError
| at repl.Session$.app(timeout.md:3)
|Caused by: java.util.concurrent.TimeoutException: Futures timed out after [10 milliseconds]
|java.util.concurrent.TimeoutException: Futures timed out after [10 milliseconds]
| at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:223)
| at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:227)
| at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:190)
| at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
| at scala.concurrent.Await$.result(package.scala:190)
| at repl.Session$App$.<init>(timeout.md:11)
| at repl.Session$App$.<clinit>(timeout.md)
| ... 1 more
| at repl.Session$App.<init>(timeout.md:11)
| at repl.Session$.app(timeout.md:3)
|""".stripMargin,
"2.13" ->
"""|error: timeout.md:4:1: Future timed out after [10 milliseconds]
|Await.result(Future(Thread.sleep(1000)), Duration("10ms"))
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|java.lang.ExceptionInInitializerError
| at repl.Session$.app(timeout.md:3)
|Caused by: java.util.concurrent.TimeoutException: Future timed out after [10 milliseconds]
|java.util.concurrent.TimeoutException: Future timed out after [10 milliseconds]
| at scala.concurrent.impl.Promise$DefaultPromise.tryAwait0(Promise.scala:212)
| at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:225)
| at scala.concurrent.Await$.$anonfun$result$1(package.scala:201)
| at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:62)
| at scala.concurrent.Await$.result(package.scala:124)
| at repl.Session$App$.<clinit>(timeout.md:11)
| ... 1 more
| at repl.Session$App.<init>(timeout.md:11)
| at repl.Session$.app(timeout.md:3)
|""".stripMargin
)
)

check(
"reset-class",
"""
|```scala mdoc:reset-class
|```scala mdoc
|import scala.concurrent._, duration._, ExecutionContext.Implicits.global
|val x = 1
|Await.result(Future(x), Duration("100ms"))
|```
""".stripMargin,
"""|```scala
"""|
|```scala
|import scala.concurrent._, duration._, ExecutionContext.Implicits.global
|val x = 1
|// x: Int = 1
|Await.result(Future(x), Duration("100ms"))
|// res1: Int = 1
|// res0: Int = 1
|```
""".stripMargin
|
|""".stripMargin
)

check(
"println",
"""
|```scala mdoc:reset-class
|```scala mdoc
|import scala.concurrent._, duration._, ExecutionContext.Implicits.global
|val done = scala.concurrent.Promise[Unit]()
|global.execute(new Runnable {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ object Compat {
val processor = compat
.get(BuildInfo.scalaVersion)
.orElse(compat.get(BuildInfo.scalaBinaryVersion))
.orElse(compat.get("all"))
processor match {
case None => default
case Some(fn) => fn(default)
Expand All @@ -21,6 +22,7 @@ object Compat {
val result = compat
.get(BuildInfo.scalaVersion)
.orElse(compat.get(BuildInfo.scalaBinaryVersion))
.orElse(compat.get("all"))
.getOrElse(
BuildInfo.scalaBinaryVersion match {
case "2.11" =>
Expand Down
20 changes: 7 additions & 13 deletions tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package tests.markdown
class ErrorSuite extends BaseMarkdownSuite {

override def postProcessObtained: Map[String, String => String] = Map(
"2.13" -> { old =>
old.linesIterator.filterNot(_.startsWith("did you mean")).mkString("\n")
}
)

override def postProcessExpected: Map[String, String => String] = Map(
"2.13" -> { old =>
old.linesIterator.filterNot(_.contains("<clinit>(crash.md)")).mkString("\n")
"all" -> { old =>
old.linesIterator
.filterNot { line =>
line.startsWith("did you mean") ||
line.contains("(crash.md")
}
.mkString("\n")
}
)

Expand All @@ -33,11 +32,6 @@ class ErrorSuite extends BaseMarkdownSuite {
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:288)
| at repl.Session$App$.crash(crash.md:17)
| at repl.Session$App$.z(crash.md:20)
| at repl.Session$App$.<init>(crash.md:26)
| at repl.Session$App$.<clinit>(crash.md)
| at repl.Session$.app(crash.md:3)
|""".stripMargin
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/test/scala/tests/markdown/FailSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class FailSuite extends BaseMarkdownSuite {
check(
"value-class",
"""
|```scala mdoc
|```scala mdoc:reset-object
|final case class FloatValue(val value: Float) extends AnyVal
|```
|
Expand Down

0 comments on commit 57a2770

Please sign in to comment.