From cfc27b918f1238068b3a8bf78733aa9ad23c98de Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 16 Feb 2021 16:57:23 +0100 Subject: [PATCH] Update to Scala 3.0.0-RC1 Fixes https://github.com/scalameta/munit/issues/311 --- bin/test-release.sh | 4 +- build.sbt | 12 +++-- .../munit/internal/MacroCompat.scala | 52 ------------------- .../munit/internal/MacroCompat.scala | 2 +- tests/shared/src/main/scala/munit/Tags.scala | 1 - .../test/scala/munit/AssertionsSuite.scala | 2 +- .../src/test/scala/munit/BaseSuite.scala | 4 -- .../src/test/scala/munit/TypeCheckSuite.scala | 13 ++++- website/i18n/en.json | 3 ++ 9 files changed, 28 insertions(+), 65 deletions(-) delete mode 100644 munit/shared/src/main/scala-3.0.0-M2/munit/internal/MacroCompat.scala rename munit/shared/src/main/{scala-3.0.0-M3 => scala-3}/munit/internal/MacroCompat.scala (96%) diff --git a/bin/test-release.sh b/bin/test-release.sh index 6adc2716..3469c862 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -9,8 +9,8 @@ coursier resolve \ org.scalameta:munit_2.11:$version \ org.scalameta:munit_2.12:$version \ org.scalameta:munit_2.13:$version \ - org.scalameta:munit_3.0.0-M2:$version \ org.scalameta:munit_3.0.0-M3:$version \ + org.scalameta:munit_3.0.0-RC1:$version \ org.scalameta:munit_0.27:$version \ org.scalameta:munit_native0.4.0_2.11:$version \ org.scalameta:munit_native0.4.0_2.12:$version \ @@ -22,8 +22,8 @@ coursier resolve \ org.scalameta:munit-scalacheck_2.12:$version \ org.scalameta:munit-scalacheck_2.13:$version \ org.scalameta:munit-scalacheck_0.27:$version \ - org.scalameta:munit-scalacheck_3.0.0-M2:$version \ org.scalameta:munit-scalacheck_3.0.0-M3:$version \ + org.scalameta:munit-scalacheck_3.0.0-RC1:$version \ org.scalameta:munit-scalacheck_native0.4.0_2.11:$version \ org.scalameta:munit-scalacheck_native0.4.0_2.12:$version \ org.scalameta:munit-scalacheck_native0.4.0_2.13:$version \ diff --git a/build.sbt b/build.sbt index 38113820..c9bd3d1d 100644 --- a/build.sbt +++ b/build.sbt @@ -10,8 +10,8 @@ def previousVersion = "0.7.0" def scala213 = "2.13.4" def scala212 = "2.12.13" def scala211 = "2.11.12" -def scala3Stable = "3.0.0-M3" -def scala3Previous = List("3.0.0-M2") +def scala3Stable = "3.0.0-RC1" +def scala3Previous = List("3.0.0-M3") def junitVersion = "4.13.2" def gcp = "com.google.cloud" % "google-cloud-storage" % "1.113.9" inThisBuild( @@ -250,7 +250,13 @@ lazy val munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform) .settings( moduleName := "munit-scalacheck", sharedSettings, - libraryDependencies += "org.scalacheck" %%% "scalacheck" % "1.15.2" + libraryDependencies += { + val partialVersion = CrossVersion.partialVersion(scalaVersion.value) + if (isNotScala211(partialVersion)) + "org.scalacheck" %%% "scalacheck" % "1.15.3" + else + "org.scalacheck" %%% "scalacheck" % "1.15.2" + } ) .jvmSettings( sharedJVMSettings diff --git a/munit/shared/src/main/scala-3.0.0-M2/munit/internal/MacroCompat.scala b/munit/shared/src/main/scala-3.0.0-M2/munit/internal/MacroCompat.scala deleted file mode 100644 index 2577eb5c..00000000 --- a/munit/shared/src/main/scala-3.0.0-M2/munit/internal/MacroCompat.scala +++ /dev/null @@ -1,52 +0,0 @@ -package munit.internal - -import munit.Clue -import munit.Location -import scala.quoted._ -import scala.language.experimental.macros - -object MacroCompat { - - trait LocationMacro { - inline implicit def generate: Location = ${ locationImpl() } - implicit def generate: Location = macro MacroCompatScala2.locationImpl - } - - def locationImpl()(using Quotes): Expr[Location] = { - import quotes.reflect._ - val pos = Position.ofMacroExpansion - val path = pos.sourceFile.jpath.toString - val startLine = pos.startLine + 1 - '{ new Location(${Expr(path)}, ${Expr(startLine)}) } - } - - trait ClueMacro { - inline implicit def generate[T](value: T): Clue[T] = ${ clueImpl('value) } - implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl - } - - def clueImpl[T: Type](value: Expr[T])(using Quotes): Expr[Clue[T]] = { - import quotes.reflect._ - val source = Term.of(value).pos.sourceCode - val valueType = Type.show[T] - '{ new Clue(${Expr(source)}, $value, ${Expr(valueType)}) } - } - - trait CompileErrorMacro { - inline def compileErrors(inline code: String): String = { - val errors = scala.compiletime.testing.typeCheckErrors(code) - errors.map { error => - val indent = " " * (error.column - 1) - val trimMessage = error.message.linesIterator.map { line => - if (line.matches(" +")) "" - else line - }.mkString("\n") - val separator = if (error.message.contains('\n')) "\n" else " " - s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^" - }.mkString("\n") - } - def compileErrors(code: String): String = macro MacroCompatScala2.compileErrorsImpl - } - - -} diff --git a/munit/shared/src/main/scala-3.0.0-M3/munit/internal/MacroCompat.scala b/munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala similarity index 96% rename from munit/shared/src/main/scala-3.0.0-M3/munit/internal/MacroCompat.scala rename to munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala index f95ea1ba..7933f684 100644 --- a/munit/shared/src/main/scala-3.0.0-M3/munit/internal/MacroCompat.scala +++ b/munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala @@ -27,7 +27,7 @@ object MacroCompat { def clueImpl[T: Type](value: Expr[T])(using Quotes): Expr[Clue[T]] = { import quotes.reflect._ - val source = Term.of(value).pos.sourceCode.getOrElse("") + val source = value.asTerm.pos.sourceCode.getOrElse("") val valueType = TypeTree.of[T].show(using Printer.TreeShortCode) '{ new Clue(${Expr(source)}, $value, ${Expr(valueType)}) } } diff --git a/tests/shared/src/main/scala/munit/Tags.scala b/tests/shared/src/main/scala/munit/Tags.scala index 1fa0c82d..b7ed879f 100644 --- a/tests/shared/src/main/scala/munit/Tags.scala +++ b/tests/shared/src/main/scala/munit/Tags.scala @@ -2,5 +2,4 @@ package munit object OnlyJVM extends Tag("OnlyJVm") {} object NoDotty extends Tag("NoDotty") {} -object OnlyFromM3 extends Tag("OnlyFromM3") {} object Only213 extends Tag("Only213") {} diff --git a/tests/shared/src/test/scala/munit/AssertionsSuite.scala b/tests/shared/src/test/scala/munit/AssertionsSuite.scala index 83148fbf..2b171f19 100644 --- a/tests/shared/src/test/scala/munit/AssertionsSuite.scala +++ b/tests/shared/src/test/scala/munit/AssertionsSuite.scala @@ -8,7 +8,7 @@ class AssertionsSuite extends BaseSuite { cond: => Boolean, expected: String )(implicit loc: Location): Unit = - test(name.tag(OnlyFromM3)) { + test(name) { val (_, clues) = munitCaptureClues(cond) assertNoDiff(Printers.print(clues), expected) } diff --git a/tests/shared/src/test/scala/munit/BaseSuite.scala b/tests/shared/src/test/scala/munit/BaseSuite.scala index a72b4134..ba35cedf 100644 --- a/tests/shared/src/test/scala/munit/BaseSuite.scala +++ b/tests/shared/src/test/scala/munit/BaseSuite.scala @@ -15,10 +15,6 @@ class BaseSuite extends FunSuite { BuildInfo.scalaVersion.startsWith("2.13") || isDotty if (test.tags(NoDotty) && isDotty) { test.tag(Ignore) - } else if ( - test.tags(OnlyFromM3) && "3.0.0-M2" == BuildInfo.scalaVersion - ) { - test.tag(Ignore) } else if (test.tags(Only213) && !is213) { test.tag(Ignore) } else if (test.tags(OnlyJVM) && !PlatformCompat.isJVM) { diff --git a/tests/shared/src/test/scala/munit/TypeCheckSuite.scala b/tests/shared/src/test/scala/munit/TypeCheckSuite.scala index cb6a1edc..8dcaadd3 100644 --- a/tests/shared/src/test/scala/munit/TypeCheckSuite.scala +++ b/tests/shared/src/test/scala/munit/TypeCheckSuite.scala @@ -35,7 +35,7 @@ class TypeCheckSuite extends FunSuite { |msg.foobar | ^ |""".stripMargin, - "3" -> + "3.0.0-M3" -> """|error: |value foobar is not a member of String, but could be made available as an extension method. | @@ -45,6 +45,17 @@ class TypeCheckSuite extends FunSuite { | |msg.foobar | ^ + |""".stripMargin, + "3.0.0-RC1" -> + """|error: + |value foobar is not a member of String, but could be made available as an extension method. + | + |The following import might make progress towards fixing the problem: + | + | import munit.Clue.generate + | + |msg.foobar + | ^ |""".stripMargin ) ) diff --git a/website/i18n/en.json b/website/i18n/en.json index 6a16aea1..3888167c 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -17,6 +17,9 @@ "getting-started": { "title": "Getting started" }, + "integrations/external-integrations": { + "title": "External Integrations" + }, "integrations/scalacheck": { "title": "ScalaCheck" },