From ef6ed9aa6bc3d3949703325e619ac1d2f659b552 Mon Sep 17 00:00:00 2001 From: Olafur Pall Geirsson Date: Sat, 2 Nov 2019 12:27:41 +0000 Subject: [PATCH] Default to reset-class, fixes #190. --- .../mdoc/internal/markdown/Instrumenter.scala | 4 +- .../scala/mdoc/internal/markdown/Mod.scala | 4 ++ .../mdoc/internal/markdown/Modifier.scala | 5 ++- .../scala/tests/cli/ScalacOptionsSuite.scala | 4 +- .../scala/tests/markdown/AsyncSuite.scala | 42 ++++++++----------- .../test/scala/tests/markdown/Compat.scala | 2 + .../scala/tests/markdown/ErrorSuite.scala | 20 ++++----- .../test/scala/tests/markdown/FailSuite.scala | 2 +- 8 files changed, 39 insertions(+), 44 deletions(-) diff --git a/mdoc/src/main/scala/mdoc/internal/markdown/Instrumenter.scala b/mdoc/src/main/scala/mdoc/internal/markdown/Instrumenter.scala index ba92041cf..a2be44405 100644 --- a/mdoc/src/main/scala/mdoc/internal/markdown/Instrumenter.scala +++ b/mdoc/src/main/scala/mdoc/internal/markdown/Instrumenter.scala @@ -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") diff --git a/mdoc/src/main/scala/mdoc/internal/markdown/Mod.scala b/mdoc/src/main/scala/mdoc/internal/markdown/Mod.scala index d17f133b2..ca069522b 100644 --- a/mdoc/src/main/scala/mdoc/internal/markdown/Mod.scala +++ b/mdoc/src/main/scala/mdoc/internal/markdown/Mod.scala @@ -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" } @@ -24,6 +27,7 @@ object Mod { CompileOnly, Reset, ResetClass, + ResetObject, Fail, Crash, Silent, diff --git a/mdoc/src/main/scala/mdoc/internal/markdown/Modifier.scala b/mdoc/src/main/scala/mdoc/internal/markdown/Modifier.scala index f22a44581..6d688d880 100644 --- a/mdoc/src/main/scala/mdoc/internal/markdown/Modifier.scala +++ b/mdoc/src/main/scala/mdoc/internal/markdown/Modifier.scala @@ -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 { diff --git a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala index 8cb84cd32..138f2a058 100644 --- a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala +++ b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala @@ -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] @@ -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( diff --git a/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala b/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala index 142998357..20c87c1c9 100644 --- a/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala @@ -28,49 +28,41 @@ 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$.(timeout.md:11) - | at repl.Session$App$.(timeout.md) - | ... 1 more - """.stripMargin, + | at repl.Session$App.(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$.(timeout.md:11) - | at repl.Session$App$.(timeout.md) - | ... 1 more + | at repl.Session$App.(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$.(timeout.md:11) - | ... 1 more + | at repl.Session$App.(timeout.md:11) + | at repl.Session$.app(timeout.md:3) |""".stripMargin ) ) @@ -78,26 +70,28 @@ class AsyncSuite extends BaseMarkdownSuite { 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 { diff --git a/tests/unit/src/test/scala/tests/markdown/Compat.scala b/tests/unit/src/test/scala/tests/markdown/Compat.scala index 39513c087..21663781c 100644 --- a/tests/unit/src/test/scala/tests/markdown/Compat.scala +++ b/tests/unit/src/test/scala/tests/markdown/Compat.scala @@ -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) @@ -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" => diff --git a/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala b/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala index 5a593cec3..df30ed41c 100644 --- a/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala @@ -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("(crash.md)")).mkString("\n") + "all" -> { old => + old.linesIterator + .filterNot { line => + line.startsWith("did you mean") || + line.contains("(crash.md") + } + .mkString("\n") } ) @@ -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$.(crash.md:26) - | at repl.Session$App$.(crash.md) - | at repl.Session$.app(crash.md:3) |""".stripMargin ) diff --git a/tests/unit/src/test/scala/tests/markdown/FailSuite.scala b/tests/unit/src/test/scala/tests/markdown/FailSuite.scala index 56c68cf98..122f86774 100644 --- a/tests/unit/src/test/scala/tests/markdown/FailSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/FailSuite.scala @@ -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 |``` |