diff --git a/build.sbt b/build.sbt index bc334d1fa..2bc49de18 100644 --- a/build.sbt +++ b/build.sbt @@ -275,12 +275,11 @@ val jsdocs = project .settings( sharedSettings, publish / skip := true, - crossScalaVersions --= scala3, scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }, libraryDependencies ++= List( - "org.scala-js" %%% "scalajs-dom" % scalajsDom + "org.scala-js" %%% "scalajs-dom" % scalajsDom cross CrossVersion.for3Use2_13 ), scalaJSUseMainModuleInitializer := true, Compile / npmDependencies ++= List( @@ -342,7 +341,6 @@ lazy val unitJS = project .settings( sharedSettings, publish / skip := true, - crossScalaVersions --= scala3, Compile / unmanagedSourceDirectories ++= multiScalaDirectories("tests/unit-js").value, libraryDependencies ++= List( "org.scalameta" %% "munit" % V.munit % Test @@ -400,7 +398,6 @@ lazy val js = project .in(file("mdoc-js")) .settings( sharedSettings, - crossScalaVersions --= scala3, moduleName := "mdoc-js", Compile / unmanagedSourceDirectories ++= multiScalaDirectories("js").value, libraryDependencies ++= crossSetting( @@ -409,7 +406,9 @@ lazy val js = project "org.scala-js" % "scalajs-compiler" % scalajs cross CrossVersion.full, "org.scala-js" %% "scalajs-linker" % scalajs ), - if3 = List() + if3 = List( + "org.scala-js" %% "scalajs-linker" % scalajs cross CrossVersion.for3Use2_13 + ) ) ) .dependsOn(mdoc) diff --git a/mdoc-js/src/main/scala-2/mdoc/modifiers/CompilerCompat.scala b/mdoc-js/src/main/scala-2/mdoc/modifiers/CompilerCompat.scala new file mode 100644 index 000000000..64e9cffc7 --- /dev/null +++ b/mdoc-js/src/main/scala-2/mdoc/modifiers/CompilerCompat.scala @@ -0,0 +1,12 @@ +package mdoc.modifiers + +import scala.reflect.io.VirtualDirectory +import mdoc.internal.markdown.MarkdownCompiler +import scala.meta.inputs.Input +import mdoc.Reporter +import mdoc.internal.pos.TokenEditDistance +import mdoc.internal.markdown.FileImport + +private[modifiers] object CompilerCompat { + def abstractFile(tg: String) = new VirtualDirectory(tg, None) +} diff --git a/mdoc-js/src/main/scala-3/mdoc/modifiers/CompilerCompat.scala b/mdoc-js/src/main/scala-3/mdoc/modifiers/CompilerCompat.scala new file mode 100644 index 000000000..86ea50491 --- /dev/null +++ b/mdoc-js/src/main/scala-3/mdoc/modifiers/CompilerCompat.scala @@ -0,0 +1,13 @@ +package mdoc.modifiers + +import dotty.tools.io.{AbstractFile, VirtualDirectory} + +import mdoc.internal.markdown.MarkdownCompiler +import scala.meta.inputs.Input +import mdoc.Reporter +import mdoc.internal.pos.TokenEditDistance +import mdoc.internal.markdown.FileImport + +private[modifiers] object CompilerCompat { + def abstractFile(tg: String) = new VirtualDirectory(tg, None) +} diff --git a/mdoc-js/src/main/scala-2/mdoc/modifiers/JsConfig.scala b/mdoc-js/src/main/scala/mdoc/modifiers/JsConfig.scala similarity index 100% rename from mdoc-js/src/main/scala-2/mdoc/modifiers/JsConfig.scala rename to mdoc-js/src/main/scala/mdoc/modifiers/JsConfig.scala diff --git a/mdoc-js/src/main/scala-2/mdoc/modifiers/JsModifier.scala b/mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala similarity index 98% rename from mdoc-js/src/main/scala-2/mdoc/modifiers/JsModifier.scala rename to mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala index ff386232b..982fad3f3 100644 --- a/mdoc-js/src/main/scala-2/mdoc/modifiers/JsModifier.scala +++ b/mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala @@ -15,7 +15,6 @@ import scala.collection.mutable.ListBuffer import scala.meta.Term import scala.meta.inputs.Input import scala.meta.io.{AbsolutePath, Classpath} -import scala.reflect.io.VirtualDirectory import org.scalajs.linker.interface.StandardConfig import org.scalajs.linker.StandardImpl import org.scalajs.linker.PathIRContainer @@ -35,7 +34,7 @@ class JsModifier extends mdoc.PreModifier { override val name = "js" override def toString: String = s"JsModifier($config)" val irCache = new StandardIRFileCache - val target = new VirtualDirectory("(memory)", None) + val target = CompilerCompat.abstractFile("(memory)") var maybeCompiler: Option[MarkdownCompiler] = None var config = JsConfig() var linker: ClearableLinker = newLinker() @@ -147,6 +146,7 @@ class JsModifier extends mdoc.PreModifier { val input = Input.VirtualFile(ctx.relativePath.toString(), wrapped) val edit = TokenEditDistance.fromInputs(inputs, input) val oldErrors = ctx.reporter.errorCount + compiler.compileSources(input, ctx.reporter, edit, fileImports = Nil) val hasErrors = ctx.reporter.errorCount > oldErrors val sjsir = for { diff --git a/mdoc-js/src/main/scala-2/mdoc/modifiers/JsMods.scala b/mdoc-js/src/main/scala/mdoc/modifiers/JsMods.scala similarity index 100% rename from mdoc-js/src/main/scala-2/mdoc/modifiers/JsMods.scala rename to mdoc-js/src/main/scala/mdoc/modifiers/JsMods.scala diff --git a/mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala b/mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala index 0a09d81eb..6c101ec62 100644 --- a/mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala +++ b/mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala @@ -53,6 +53,7 @@ class MarkdownCompiler( target: AbstractFile = new VirtualDirectory("(memory)") ) { + private def newContext: FreshContext = { val defaultFlags = List("-color:never", "-unchecked", "-deprecation", "-Ximport-suggestion-timeout", "0") @@ -60,7 +61,14 @@ class MarkdownCompiler( val settings = options ::: defaultFlags ::: "-classpath" :: classpath :: Nil val driver = new InteractiveDriver(settings.distinct) - driver.currentCtx.fresh.setReporter(new CollectionReporter) + + val ctx = driver.currentCtx.fresh + + ctx + .setReporter(new CollectionReporter) + .setSetting( + ctx.settings.outputDir, target + ) } private var context = newContext @@ -106,20 +114,22 @@ class MarkdownCompiler( vreporter: Reporter, edit: TokenEditDistance, fileImports: List[FileImport], - context: Context + freshContext: Option[Context] = None ): Unit = { clearTarget() + val context = freshContext.getOrElse(newContext) val compiler = new Compiler val run = compiler.newRun(using context) val inputs = List(input) - scala.util.Try(run.compileSources(inputs.map(toSource))) + val res = scala.util.Try(run.compileSources(inputs.map(toSource))) report(vreporter, input, fileImports, run.runContext, edit) } class CollectionReporter extends dotty.tools.dotc.reporting.Reporter { val allDiags = List.newBuilder[Diagnostic] - override def doReport(dia: Diagnostic)(using Context) = allDiags += dia + override def doReport(dia: Diagnostic)(using Context) = + allDiags += dia override def pendingMessages(using Context) = allDiags.result() } @@ -139,7 +149,7 @@ class MarkdownCompiler( target ) - compileSources(input, vreporter, edit, fileImports, freshContext) + compileSources(input, vreporter, edit, fileImports, Some(freshContext)) if (!freshContext.reporter.hasErrors) { val loader = new AbstractFileClassLoader(target, appClassLoader) try { @@ -226,7 +236,6 @@ class MarkdownCompiler( ): Unit = { val infos = context.reporter.pendingMessages(using context).toSeq.sortBy(_.pos.source.path) - infos.foreach { case diagnostic if diagnostic.position.isPresent => val pos = diagnostic.position.get @@ -266,7 +275,6 @@ class MarkdownCompiler( new CodeBuilder() .println(s"${pos.source().path()}:${pos.line + 1} (mdoc generated code) \n $message") .println(pos.lineContent) - .println(pos.point().toString) .toString } diff --git a/project/plugins.sbt b/project/plugins.sbt index e2ea88675..430cc9c3b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1") addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0") libraryDependencies ++= List( diff --git a/tests/tests/src/main/scala/tests/BaseSuite.scala b/tests/tests/src/main/scala/tests/BaseSuite.scala index d1007d10d..ee2b2b038 100644 --- a/tests/tests/src/main/scala/tests/BaseSuite.scala +++ b/tests/tests/src/main/scala/tests/BaseSuite.scala @@ -5,8 +5,8 @@ import munit.Location import tests.markdown.Compat class BaseSuite extends FunSuite { - def postProcessObtained: Map[String, String => String] = Map.empty - def postProcessExpected: Map[String, String => String] = Map.empty + def postProcessObtained: Map[Compat.ScalaVersion, String => String] = Map.empty + def postProcessExpected: Map[Compat.ScalaVersion, String => String] = Map.empty override def assertNoDiff(obtained: String, expected: String, clue: => Any)(implicit loc: Location ): Unit = { diff --git a/tests/tests/src/main/scala/tests/markdown/Compat.scala b/tests/tests/src/main/scala/tests/markdown/Compat.scala index 31971cba8..005b623ed 100644 --- a/tests/tests/src/main/scala/tests/markdown/Compat.scala +++ b/tests/tests/src/main/scala/tests/markdown/Compat.scala @@ -3,46 +3,81 @@ package tests.markdown import tests.BuildInfo object Compat { + sealed trait ScalaVersion + case object Scala2 extends ScalaVersion + case object Scala211 extends ScalaVersion + case object Scala212 extends ScalaVersion + case object Scala213 extends ScalaVersion + case object Scala3 extends ScalaVersion + case class Full(ver: String) extends ScalaVersion + case object All extends ScalaVersion + + private def isCurrent(ver: ScalaVersion): Boolean = { + val full = BuildInfo.scalaVersion + val binary = BuildInfo.scalaBinaryVersion + + ver match { + case Scala2 => binary.startsWith("2.") + case Scala211 => full.startsWith("2.11") + case Scala212 => full.startsWith("2.12") + case Scala213 => full.startsWith("2.13") + case Scala3 => full.startsWith("3.0") || binary == "3" + case Full(v) => v == full + case All => true + } + } + + private def binary: ScalaVersion = { + BuildInfo.scalaBinaryVersion match { + case "2.11" => Scala211 + case "2.12" => Scala212 + case "2.13" => Scala213 + case "3" => Scala3 + case s if s.startsWith("3.0") => Scala3 + } + } + def isScala212: Boolean = BuildInfo.scalaVersion.startsWith("2.12") - def isScala3: Boolean = BuildInfo.scalaVersion.startsWith("3.0") - def postProcess(default: String, compat: Map[String, String => String]): String = { + def isScala3: Boolean = + BuildInfo.scalaVersion.startsWith("3.0") || BuildInfo.scalaBinaryVersion == "3" + + def postProcess(default: String, compat: Map[ScalaVersion, String => String]): String = { val processor = compat - .get(BuildInfo.scalaVersion) - .orElse(compat.get(BuildInfo.scalaBinaryVersion)) - .orElse(compat.get("all")) + .get(Full(BuildInfo.scalaVersion)) + .orElse(compat.get(binary)) + .orElse(compat.get(All)) processor match { case None => default case Some(fn) => fn(default) } } + def apply( default: String, - compat: Map[String, String], - postProcess: Map[String, String => String] = Map.empty + compat: Map[ScalaVersion, String], + postProcess: Map[ScalaVersion, String => String] = Map.empty ): String = { val result = compat - .collect { case (key, value) if BuildInfo.scalaVersion.startsWith(key) => value } + .collect { case (key, value) if isCurrent(key) => value } .headOption - .orElse(compat.get("all")) + .orElse(compat.get(All)) .getOrElse( - BuildInfo.scalaBinaryVersion match { - case "2.11" => - default - .replace("Predef.scala:288", "Predef.scala:230") - case "2.12" => - default - .replace("package.scala:219", "package.scala:220") - case "2.13" => - default - .replace("", "") - .replace("Predef.scala:288", "Predef.scala:347") - case other if other.startsWith("3.0") => - default - .replace("", "") - .replace("Predef.scala:288", "Predef.scala:345") - case _ => - default - } + if (isCurrent(Scala211)) + default + .replace("Predef.scala:288", "Predef.scala:230") + else if (isCurrent(Scala212)) + default + .replace("package.scala:219", "package.scala:220") + else if (isCurrent(Scala213)) + default + .replace("", "") + .replace("Predef.scala:288", "Predef.scala:347") + else if (isCurrent(Scala3)) + default + .replace("", "") + .replace("Predef.scala:288", "Predef.scala:345") + else + default ) this.postProcess(result, postProcess) } diff --git a/tests/unit-js/src/test/scala-2/tests/js/JsCliSuite.scala b/tests/unit-js/src/test/scala/tests/js/JsCliSuite.scala similarity index 100% rename from tests/unit-js/src/test/scala-2/tests/js/JsCliSuite.scala rename to tests/unit-js/src/test/scala/tests/js/JsCliSuite.scala diff --git a/tests/unit-js/src/test/scala-2/tests/js/JsModsSuite.scala b/tests/unit-js/src/test/scala/tests/js/JsModsSuite.scala similarity index 100% rename from tests/unit-js/src/test/scala-2/tests/js/JsModsSuite.scala rename to tests/unit-js/src/test/scala/tests/js/JsModsSuite.scala diff --git a/tests/unit-js/src/test/scala-2/tests/js/JsSuite.scala b/tests/unit-js/src/test/scala/tests/js/JsSuite.scala similarity index 80% rename from tests/unit-js/src/test/scala-2/tests/js/JsSuite.scala rename to tests/unit-js/src/test/scala/tests/js/JsSuite.scala index 80f2c9aa0..4e502b927 100644 --- a/tests/unit-js/src/test/scala-2/tests/js/JsSuite.scala +++ b/tests/unit-js/src/test/scala/tests/js/JsSuite.scala @@ -5,6 +5,7 @@ import scala.meta.io.Classpath import tests.markdown.StringSyntax._ import tests.markdown.BaseMarkdownSuite import tests.js.JsTests.suffix +import tests.markdown.Compat class JsSuite extends BaseMarkdownSuite { // NOTE(olafur) Optimization. Cache settings to reuse the Scala.js compiler instance. @@ -44,7 +45,17 @@ class JsSuite extends BaseMarkdownSuite { | required: Int |val x: Int = "" | ^^ - """.stripMargin + """.stripMargin, + compat = Map( + Compat.Scala3 -> + """ + |error: error.md:3:14: + |Found: ("" : String) + |Required: Int + |val x: Int = "" + | ^^ + """.stripMargin + ) ) check( @@ -93,7 +104,22 @@ class JsSuite extends BaseMarkdownSuite { | required: String |val y: String = 42 | ^^ - """.stripMargin + """.stripMargin, + compat = Map( + Compat.Scala3 -> + """ + |error: edit.md:3:14: + |Found: ("" : String) + |Required: Int + |val x: Int = "" + | ^^ + |error: edit.md:7:17: + |Found: (42 : Int) + |Required: String + |val y: String = 42 + | ^^ + """.stripMargin + ) ) checkError( @@ -110,7 +136,16 @@ class JsSuite extends BaseMarkdownSuite { """|error: isolated.md:7:9: not found: value x |println(x) | ^ - """.stripMargin + """.stripMargin, + compat = Map( + Compat.Scala3 -> + """ + |error: isolated.md:7:9: + |Not found: x + |println(x) + | ^ + """.stripMargin + ) ) checkCompiles( @@ -171,7 +206,17 @@ class JsSuite extends BaseMarkdownSuite { | required: String |val x: String = 42 | ^^ - """.stripMargin + """.stripMargin, + compat = Map( + Compat.Scala3 -> + """ + |error: compile-only-error.md:3:17: + |Found: (42 : Int) + |Required: String + |val x: String = 42 + | ^^ + """.stripMargin + ) ) // It's easy to mess up stripMargin multiline strings when generating code with strings. @@ -247,7 +292,24 @@ class JsSuite extends BaseMarkdownSuite { baseSettings.copy( site = baseSettings.site.updated("js-classpath", Classpath(noScalajsDom).syntax) ) - } + }, + compat = Map( + Compat.Scala3 -> + """ + |error: + |no-dom.md:3 (mdoc generated code) + | value scalajs is not a member of org + |def run0(node: _root_.org.scalajs.dom.raw.HTMLElement): Unit = { + | + | + |error: + |no-dom.md:3 (mdoc generated code) + | (#dom.raw : + | + |) is not a valid type prefix, since it is not an immutable path + |def run0(node: _root_.org.scalajs.dom.raw.HTMLElement): Unit = { + """.stripMargin + ) ) checkError( diff --git a/tests/unit-js/src/test/scala-2/tests/js/JsTests.scala b/tests/unit-js/src/test/scala/tests/js/JsTests.scala similarity index 100% rename from tests/unit-js/src/test/scala-2/tests/js/JsTests.scala rename to tests/unit-js/src/test/scala/tests/js/JsTests.scala diff --git a/tests/unit/src/main/scala/tests/cli/BaseCliSuite.scala b/tests/unit/src/main/scala/tests/cli/BaseCliSuite.scala index 133a093a9..75e9f8c2e 100644 --- a/tests/unit/src/main/scala/tests/cli/BaseCliSuite.scala +++ b/tests/unit/src/main/scala/tests/cli/BaseCliSuite.scala @@ -23,9 +23,9 @@ abstract class BaseCliSuite extends BaseSuite { } val in = new TemporaryDirectory("in") val out = new TemporaryDirectory("out") - override def postProcessObtained: Map[String, String => String] = + override def postProcessObtained: Map[Compat.ScalaVersion, String => String] = Map( - "all" -> { old => + Compat.All -> { old => old .replace(out().toString(), "") .replace(in().toString(), "") @@ -47,7 +47,7 @@ abstract class BaseCliSuite extends BaseSuite { expectedExitCode: => Int = 0, onStdout: String => Unit = _ => (), includeOutputPath: RelativePath => Boolean = _ => true, - compat: Map[String, String] = Map.empty + compat: Map[Compat.ScalaVersion, String] = Map.empty )(implicit loc: munit.Location): Unit = { test(name) { myStdout.reset() diff --git a/tests/unit/src/main/scala/tests/markdown/BaseMarkdownSuite.scala b/tests/unit/src/main/scala/tests/markdown/BaseMarkdownSuite.scala index 3a3057dac..d8b112ace 100644 --- a/tests/unit/src/main/scala/tests/markdown/BaseMarkdownSuite.scala +++ b/tests/unit/src/main/scala/tests/markdown/BaseMarkdownSuite.scala @@ -60,7 +60,7 @@ abstract class BaseMarkdownSuite extends tests.BaseSuite { original: String, expected: String, settings: Settings = baseSettings, - compat: Map[String, String] = Map.empty + compat: Map[Compat.ScalaVersion, String] = Map.empty )(implicit loc: munit.Location): Unit = { test(name) { val reporter = newReporter() @@ -73,8 +73,9 @@ abstract class BaseMarkdownSuite extends tests.BaseSuite { fansi.Str(myStdout.toString).plainText.trimLineEnds, postProcessObtained ) + assertNoDiff( - Compat(obtainedErrors, compat, postProcessObtained), + Compat(obtainedErrors, Map.empty, postProcessObtained), Compat(expected, compat, postProcessExpected) ) } @@ -107,7 +108,7 @@ abstract class BaseMarkdownSuite extends tests.BaseSuite { original: String, expected: String, settings: Settings = baseSettings, - compat: Map[String, String] = Map.empty + compat: Map[Compat.ScalaVersion, String] = Map.empty )(implicit loc: munit.Location): Unit = { checkCompiles( name, diff --git a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala index b4cc528bd..d37af6a07 100644 --- a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala +++ b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala @@ -173,7 +173,7 @@ class ScalacOptionsSuite extends BaseCliSuite { "-Ywarn-value-discard" ), compat = Map( - "2.13" -> + Compat.Scala213 -> """|/index.md |```scala |final case class Test(value: Int) @@ -194,7 +194,7 @@ class ScalacOptionsSuite extends BaseCliSuite { |// ^^^^^ |``` |""".stripMargin, - "3.0" -> + Compat.Scala3 -> """|/index.md |```scala |final case class Test(value: Int) diff --git a/tests/unit/src/test/scala/tests/imports/DependencySuite.scala b/tests/unit/src/test/scala/tests/imports/DependencySuite.scala index dc375e1ad..433de615f 100644 --- a/tests/unit/src/test/scala/tests/imports/DependencySuite.scala +++ b/tests/unit/src/test/scala/tests/imports/DependencySuite.scala @@ -1,12 +1,13 @@ package tests.imports import tests.markdown.BaseMarkdownSuite +import tests.markdown.Compat class DependencySuite extends BaseMarkdownSuite { val userHome = System.getProperty("user.home") - override def postProcessObtained: Map[String, String => String] = + override def postProcessObtained: Map[Compat.ScalaVersion, String => String] = Map( - "all" -> { old => + Compat.All -> { old => old.linesIterator .map { case line if line.contains(userHome) => diff --git a/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala b/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala index 8fead2cc2..c5b0cfbf1 100644 --- a/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala @@ -38,7 +38,7 @@ class AsyncSuite extends BaseMarkdownSuite { | at repl.MdocSession$.app(timeout.md:3) |""".stripMargin, compat = Map( - "2.11" -> + Compat.Scala211 -> """|error: timeout.md:4:1: Futures timed out after [10 milliseconds] |Await.result(Future(Thread.sleep(1000)), Duration("10ms")) |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ class AsyncSuite extends BaseMarkdownSuite { | at repl.MdocSession$App.(timeout.md:11) | at repl.MdocSession$.app(timeout.md:3) |""".stripMargin, - "2.13" -> + Compat.Scala213 -> """|error: timeout.md:4:1: Future timed out after [10 milliseconds] |Await.result(Future(Thread.sleep(1000)), Duration("10ms")) |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ class AsyncSuite extends BaseMarkdownSuite { | at repl.MdocSession$App.(timeout.md:11) | at repl.MdocSession$.app(timeout.md:3) |""".stripMargin, - "3.0" -> + Compat.Scala3 -> """|error: timeout.md:4:1: Future timed out after [10 milliseconds] |Await.result(Future(Thread.sleep(1000)), Duration("10ms")) |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ class AsyncSuite extends BaseMarkdownSuite { | 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.MdocSession$App.(timeout.md:11) + | at repl.MdocSession$App.(timeout.md:13) | at repl.MdocSession$.app(timeout.md:3) |""".stripMargin ) diff --git a/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala b/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala index cac75843a..9d816e306 100644 --- a/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala @@ -19,7 +19,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|```scala |val x = 1 |??? @@ -29,7 +29,7 @@ class CrashSuite extends BaseMarkdownSuite { |// at repl.MdocSession$App$$anonfun$3.apply(basic.md:14) |``` """.stripMargin, - "3.0" -> + Compat.Scala3 -> """|```scala |val x = 1 |??? @@ -87,7 +87,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |1 match { | case 2 => // boom! @@ -116,7 +116,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|```scala |??? |// scala.NotImplementedError: an implementation is missing @@ -125,7 +125,7 @@ class CrashSuite extends BaseMarkdownSuite { |// at repl.MdocSession$App$$anonfun$1.apply(relative.md:9) |``` """.stripMargin, - "3.0" -> + Compat.Scala3 -> """|```scala |??? |// scala.NotImplementedError: an implementation is missing @@ -151,7 +151,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |throw new StackOverflowError() |// java.lang.StackOverflowError @@ -176,7 +176,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |throw new NoClassDefFoundError() |// java.lang.NoClassDefFoundError @@ -201,7 +201,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |throw new NoSuchMethodError() |// java.lang.NoSuchMethodError @@ -226,7 +226,7 @@ class CrashSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |throw new IncompatibleClassChangeError() |// java.lang.IncompatibleClassChangeError diff --git a/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala b/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala index 2a24de9d5..6e708843b 100644 --- a/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala @@ -140,7 +140,7 @@ class DefaultSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|```scala |case class User(name: String, age: Int) |User("John", 42) diff --git a/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala b/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala index 5942a681c..2b72cbb43 100644 --- a/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala @@ -2,9 +2,9 @@ package tests.markdown class ErrorSuite extends BaseMarkdownSuite { - override def postProcessObtained: Map[String, String => String] = + override def postProcessObtained: Map[Compat.ScalaVersion, String => String] = Map( - "all" -> { old => + Compat.All -> { old => old.linesIterator .filterNot { line => line.startsWith("did you mean") || @@ -35,20 +35,24 @@ class ErrorSuite extends BaseMarkdownSuite { | at scala.Predef$.$qmark$qmark$qmark(Predef.scala:288) |""".stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|error: crash.md:10:1: an implementation is missing |x + y + z |^^^^^^^^^ |scala.NotImplementedError: an implementation is missing - | at scala.Predef$.$qmark$qmark$qmark(Predef.scala:347) + | at scala.Predef$.$qmark$qmark$qmark(Predef.scala:345) |""".stripMargin, - "3.0" -> + Compat.Scala3 -> { + // Anton: for some reason, the compiler(?) returns tab in this particular place + val tab = "\t" + """|error: crash.md:10:1: an implementation is missing |x + y + z |^^^^^^^^^ |scala.NotImplementedError: an implementation is missing - | at scala.Predef$.$qmark$qmark$qmark(Predef.scala:345) - |""".stripMargin + |at scala.Predef$.$qmark$qmark$qmark(Predef.scala:345) + """.stripMargin.replace("", tab) + } ) ) diff --git a/tests/unit/src/test/scala/tests/markdown/FailSuite.scala b/tests/unit/src/test/scala/tests/markdown/FailSuite.scala index 23afc9413..fb0e3b2dc 100644 --- a/tests/unit/src/test/scala/tests/markdown/FailSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/FailSuite.scala @@ -1,12 +1,15 @@ package tests.markdown import tests.markdown.StringSyntax._ +import tests.markdown.Compat class FailSuite extends BaseMarkdownSuite { - override def postProcessExpected: Map[String, String => String] = + override def postProcessExpected: Map[Compat.ScalaVersion, String => String] = Map( - "2.13" -> { old => old.replace("(fo: F[O])fs2.Stream[F,O]", "(fo: F[O]): fs2.Stream[F,O]") } + Compat.Scala213 -> { old => + old.replace("(fo: F[O])fs2.Stream[F,O]", "(fo: F[O]): fs2.Stream[F,O]") + } ) check( @@ -26,7 +29,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |val x: Int = "String" |// error: @@ -61,7 +64,7 @@ class FailSuite extends BaseMarkdownSuite { |``` |""".stripMargin.triplequoted, compat = Map( - "3.0" -> + Compat.Scala3 -> """ |```scala |val y: Int = '''Triplequote @@ -90,9 +93,9 @@ class FailSuite extends BaseMarkdownSuite { |^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """ - |error: fail-error.md:3:1 + |error: fail-error.md:3:1: |Not found: foobar |foobar |^^^^^^ @@ -131,9 +134,9 @@ class FailSuite extends BaseMarkdownSuite { | ^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """ - |error: mixed-error.md:3:9 + |error: mixed-error.md:3:9: |Not found: foobar |val x = foobar | ^^^^^^ @@ -165,7 +168,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |println(42) |// 42 @@ -207,7 +210,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |fs2.Stream.eval(println("Do not ever do this")) |// error: @@ -244,7 +247,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |println(notfound) |println(b) @@ -301,7 +304,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |val x = 1 |println(notfound) @@ -357,7 +360,7 @@ class FailSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """| |```scala |final case class FloatValue(val value: Float) extends AnyVal diff --git a/tests/unit/src/test/scala/tests/markdown/MarkdownCompilerSuite.scala b/tests/unit/src/test/scala/tests/markdown/MarkdownCompilerSuite.scala index 359089ff3..9a3ac5f9b 100644 --- a/tests/unit/src/test/scala/tests/markdown/MarkdownCompilerSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/MarkdownCompilerSuite.scala @@ -28,7 +28,7 @@ class MarkdownCompilerSuite extends FunSuite { name: String, original: List[String], expected: String, - compat: Map[String, String] = Map.empty + compat: Map[Compat.ScalaVersion, String] = Map.empty ): Unit = { test(name) { val inputs = original.map(s => Input.String(s)) @@ -72,7 +72,7 @@ class MarkdownCompilerSuite extends FunSuite { |``` """.stripMargin, compat = Map( - "2.11" -> + Compat.Scala211 -> """ |```scala |val x = 1.to(10) @@ -83,7 +83,7 @@ class MarkdownCompilerSuite extends FunSuite { |// y: Int = 10 |``` |""".stripMargin, - "2.12" -> + Compat.Scala212 -> """ |```scala |val x = 1.to(10) @@ -94,7 +94,7 @@ class MarkdownCompilerSuite extends FunSuite { |// y: Int = 10 |``` |""".stripMargin, - "3.0" -> + Compat.Scala3 -> """ |```scala |val x = 1.to(10) diff --git a/tests/unit/src/test/scala/tests/markdown/MultiModsSuite.scala b/tests/unit/src/test/scala/tests/markdown/MultiModsSuite.scala index cfc0e160b..dd189babd 100644 --- a/tests/unit/src/test/scala/tests/markdown/MultiModsSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/MultiModsSuite.scala @@ -27,7 +27,7 @@ class MultiModsSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """| |```scala |val x = 1 diff --git a/tests/unit/src/test/scala/tests/markdown/NamespaceHygieneSuite.scala b/tests/unit/src/test/scala/tests/markdown/NamespaceHygieneSuite.scala index 4e8f08d3b..aea604f37 100644 --- a/tests/unit/src/test/scala/tests/markdown/NamespaceHygieneSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/NamespaceHygieneSuite.scala @@ -28,12 +28,14 @@ class NamespaceHygieneSuite extends BaseMarkdownSuite { | ^^^^^^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """ |error: cannot import something called MdocSession.md:3:9: |Reference to MdocSession is ambiguous, |it is both defined in package repl |and imported by name subsequently by import util.{...} + |val x = MdocSession.nextInt(1) + | ^^^^^^^^^^^ """.stripMargin ) ) diff --git a/tests/unit/src/test/scala/tests/markdown/NestSuite.scala b/tests/unit/src/test/scala/tests/markdown/NestSuite.scala index fd002a0c2..64de792d3 100644 --- a/tests/unit/src/test/scala/tests/markdown/NestSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/NestSuite.scala @@ -2,9 +2,9 @@ package tests.markdown class NestSuite extends BaseMarkdownSuite { - override def postProcessExpected: Map[String, String => String] = + override def postProcessExpected: Map[Compat.ScalaVersion, String => String] = Map( - "2.13" -> { old => old.replace("of type => Int", "of type Int") } + Compat.Scala213 -> { old => old.replace("of type => Int", "of type Int") } ) check( @@ -73,7 +73,7 @@ class NestSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|```scala |case class User(name: String) |val susan = User("Susan") @@ -87,7 +87,7 @@ class NestSuite extends BaseMarkdownSuite { |// res0: App.this.type.User = User(name = "Susan") |``` |""".stripMargin, - "3.0" -> + Compat.Scala3 -> """|```scala |case class User(name: String) |val susan = User("Susan") @@ -247,22 +247,12 @@ class NestSuite extends BaseMarkdownSuite { |implicitly[Int] |``` """.stripMargin, - """|error: reset.md:9:1: could not find implicit value for parameter e: Int - |implicitly[Int] - |^^^^^^^^^^^^^^^ - |""".stripMargin, - compat = Map( - "3.0" -> - """ - | - |error: - |reset-scala3.md:26 (mdoc generated code) - | no implicit argument of type Int was found for parameter e of method implicitly in object - Predef - | implicitly[Int] - | + """ + |error: reset-scala3.md:9:15: + |no implicit argument of type Int was found for parameter e of method implicitly in object Predef + |implicitly[Int] + | ^ """.stripMargin - ) ) checkError( @@ -388,8 +378,8 @@ class NestSuite extends BaseMarkdownSuite { |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> - """|error: anyval-nok.md:6:1: + Compat.Scala3 -> + """|error: anyval-nok.md:6:7: |Value classes may not be a local class |class Foo(val x: Int) extends AnyVal | ^ @@ -424,7 +414,7 @@ class NestSuite extends BaseMarkdownSuite { | at repl.MdocSession$.app(stacktrace.md:3) |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|error: stacktrace.md:14:1: null |boom(x > 4) |^^^^^^^^^^^ @@ -460,7 +450,7 @@ class NestSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """ |error: |Not found: y diff --git a/tests/unit/src/test/scala/tests/markdown/ResetSuite.scala b/tests/unit/src/test/scala/tests/markdown/ResetSuite.scala index df445d9a1..9d244a813 100644 --- a/tests/unit/src/test/scala/tests/markdown/ResetSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/ResetSuite.scala @@ -38,7 +38,7 @@ class ResetSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|```scala |implicit val x: Int = 42 |// x: Int = 42 diff --git a/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala b/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala index 8bb90b0c6..261dda59f 100644 --- a/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala @@ -41,7 +41,7 @@ class SemanticsSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( - "2.13" -> + Compat.Scala213 -> """|```scala |case class User(name: String) |object User { diff --git a/tests/unit/src/test/scala/tests/markdown/WarnSuite.scala b/tests/unit/src/test/scala/tests/markdown/WarnSuite.scala index bba7cb2ee..5bc0a5d0b 100644 --- a/tests/unit/src/test/scala/tests/markdown/WarnSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/WarnSuite.scala @@ -18,7 +18,7 @@ class WarnSuite extends BaseMarkdownSuite { |``` |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """ | | warn: diff --git a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala index 19885c996..36a64f359 100644 --- a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala +++ b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala @@ -110,9 +110,9 @@ class WorksheetSuite extends BaseSuite { |... |""".stripMargin, compat = Map( - "3.0" -> """| // : Stream[Int] = Stre... - |res0: Stream[Int] = Stream(10, ) - |""".stripMargin + Compat.Scala3 -> """| // : Stream[Int] = Stre... + |res0: Stream[Int] = Stream(10, ) + |""".stripMargin ) ) @@ -141,7 +141,7 @@ class WorksheetSuite extends BaseSuite { |res0: List[Int] = List(2, 3) |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """| // : List[Int] = List(1... |list: List[Int] = List(1, 2, 3) | // : List[Int] = List(2,... @@ -207,14 +207,14 @@ class WorksheetSuite extends BaseSuite { |n: User = User("Susan") |""".stripMargin, compat = Map( - "3.0" -> """|case class User(name: String) - | // : User = User(Susan) - |n: User = User(Susan) - |""".stripMargin, - "2.13" -> """|case class User(name: String) - | // : User = User(name =... - |n: User = User(name = "Susan") - |""".stripMargin + Compat.Scala3 -> """|case class User(name: String) + | // : User = User(Susan) + |n: User = User(Susan) + |""".stripMargin, + Compat.Scala213 -> """|case class User(name: String) + | // : User = User(name =... + |n: User = User(name = "Susan") + |""".stripMargin ) ) @@ -230,7 +230,7 @@ class WorksheetSuite extends BaseSuite { | ^^^^^^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|type-error:2:21: error: |Found: ("not found" : String) |Required: Int @@ -256,7 +256,7 @@ class WorksheetSuite extends BaseSuite { |^^^^^^^^^^^^^^^ |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """|crash:4:1: error: java.lang.RuntimeException: boom | at repl.MdocSession$App.crash(crash.scala:7) | at repl.MdocSession$App.(crash.scala:15) @@ -280,7 +280,7 @@ class WorksheetSuite extends BaseSuite { |x: String = "foo" |""".stripMargin, compat = Map( - "3.0" -> + Compat.Scala3 -> """| // : String = foo |x: String = foo |""".stripMargin @@ -302,12 +302,12 @@ class WorksheetSuite extends BaseSuite { |res0: Parsed[Unit] = Success((), 1) |""".stripMargin, compat = Map( - "2.13" -> """|import $dep.`com.lihaoyi::fastparse:2.3.0` - |import fastparse._, MultiLineWhitespace._ - |def p[_:P] = P("a") - | // : Parsed[Unit] = Suc... - |res0: Parsed[Unit] = Success(value = (), index = 1) - |""".stripMargin + Compat.Scala213 -> """|import $dep.`com.lihaoyi::fastparse:2.3.0` + |import fastparse._, MultiLineWhitespace._ + |def p[_:P] = P("a") + | // : Parsed[Unit] = Suc... + |res0: Parsed[Unit] = Success(value = (), index = 1) + |""".stripMargin ) ) @@ -424,7 +424,7 @@ class WorksheetSuite extends BaseSuite { options: TestOptions, original: String, expected: String, - compat: Map[String, String] = Map.empty, + compat: Map[Compat.ScalaVersion, String] = Map.empty, modifier: Option[String] = None ): Unit = { test(options) { @@ -456,7 +456,7 @@ class WorksheetSuite extends BaseSuite { options: TestOptions, original: String, expected: String, - compat: Map[String, String] = Map.empty, + compat: Map[Compat.ScalaVersion, String] = Map.empty, modifier: Option[String] = None ): Unit = { test(options) {