From 49bb27aaea53bae18c008b7c41127b1910234373 Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Wed, 20 Jan 2021 09:10:47 +0100 Subject: [PATCH] Add support for Scala Native 0.4.0 --- bin/test-release.sh | 8 +++++-- build.sbt | 24 ++++++++----------- docs/getting-started.md | 19 ++++++++------- .../scala/munit/internal/PlatformCompat.scala | 17 ++++++------- project/plugins.sbt | 2 +- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/bin/test-release.sh b/bin/test-release.sh index 5acc340b..6adc2716 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -12,7 +12,9 @@ coursier resolve \ org.scalameta:munit_3.0.0-M2:$version \ org.scalameta:munit_3.0.0-M3:$version \ org.scalameta:munit_0.27:$version \ - org.scalameta:munit_native0.4.0-M2_2.11:$version \ + org.scalameta:munit_native0.4.0_2.11:$version \ + org.scalameta:munit_native0.4.0_2.12:$version \ + org.scalameta:munit_native0.4.0_2.13:$version \ org.scalameta:munit_sjs1_2.11:$version \ org.scalameta:munit_sjs1_2.12:$version \ org.scalameta:munit_sjs1_2.13:$version \ @@ -22,7 +24,9 @@ coursier resolve \ 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_native0.4.0-M2_2.11:$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 \ org.scalameta:munit-scalacheck_sjs1_2.11:$version \ org.scalameta:munit-scalacheck_sjs1_2.12:$version \ org.scalameta:munit-scalacheck_sjs1_2.13:$version \ diff --git a/build.sbt b/build.sbt index 8ab72f07..e58c9d54 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject import sbtcrossproject.CrossPlugin.autoImport.CrossType import scala.collection.mutable val scalaJSVersion = "1.4.0" -val scalaNativeVersion = "0.4.0-M2" +val scalaNativeVersion = "0.4.0" def previousVersion = "0.7.0" def scala213 = "2.13.4" def scala212 = "2.12.13" @@ -66,12 +66,6 @@ val isScala3Setting = Def.setting { } def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 != 2) -val isScalaJS = Def.setting[Boolean]( - SettingKey[Boolean]("scalaJSUseMainModuleInitializer").?.value.isDefined -) -val isScalaNative = Def.setting[Boolean]( - SettingKey[String]("nativeGC").?.value.isDefined -) // NOTE(olafur): disable Scala.js and Native settings for IntelliJ. lazy val skipIdeaSettings = SettingKey[Boolean]("ide-skip-project") := true @@ -116,8 +110,7 @@ val sharedJSConfigure: Project => Project = _.disablePlugins(MimaPlugin) val sharedNativeSettings: List[Def.Setting[_]] = List( skipIdeaSettings, - scalaVersion := scala211, - crossScalaVersions := List(scala211) + crossScalaVersions := scala2Versions ) val sharedNativeConfigure: Project => Project = _.disablePlugins(ScalafixPlugin, MimaPlugin) @@ -174,9 +167,6 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform) val base = root / "shared" / "src" / "main" val result = mutable.ListBuffer.empty[File] val partialVersion = CrossVersion.partialVersion(scalaVersion.value) - if (isScalaJS.value || isScalaNative.value) { - result += root / "non-jvm" / "src" / "main" - } if (isPreScala213(partialVersion)) { result += base / "scala-pre-2.13" } @@ -203,7 +193,10 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform) sharedNativeSettings, libraryDependencies ++= List( "org.scala-native" %%% "test-interface" % scalaNativeVersion - ) + ), + unmanagedSourceDirectories.in(Compile) += baseDirectory + .in(ThisBuild) + .value / "munit" / "non-jvm" / "src" / "main" ) .jsConfigure(sharedJSConfigure) .jsSettings( @@ -213,7 +206,10 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform) .withDottyCompat(scalaVersion.value), ("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion) .withDottyCompat(scalaVersion.value) - ) + ), + unmanagedSourceDirectories.in(Compile) += baseDirectory + .in(ThisBuild) + .value / "munit" / "non-jvm" / "src" / "main" ) .jvmSettings( sharedJVMSettings, diff --git a/docs/getting-started.md b/docs/getting-started.md index b209b2a5..8b3176b9 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -44,7 +44,8 @@ object test extends Tests { ### Scala.js setup -Additionally, if you are using Scala.js you will need to export your tests as CommonJS modules: +Additionally, if you are using Scala.js you will need to export your tests as +CommonJS modules: **sbt:** @@ -58,18 +59,18 @@ Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) } ```scala object test extends Tests { ... - + override def moduleKind = T(mill.scalajslib.api.ModuleKind.CommonJSModule) } ``` -| Scala Version | JVM | Scala.js (0.6.x) | Scala.js (1.x) | Native (0.4.x) | -| ------------------------- | :-: | :--------------: | :------------: | :------------: | -| 2.11.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ | -| 2.12.x | ✅ | ✅ until 0.7.16 | ✅ | n/a | -| 2.13.x | ✅ | ✅ until 0.7.16 | ✅ | n/a | -| @SCALA3_PREVIOUS_VERSION@ | ✅ | n/a | ✅ | n/a | -| @SCALA3_STABLE_VERSION@ | ✅ | n/a | ✅ | n/a | +| Scala Version | JVM | Scala.js (0.6.x) | Scala.js (1.x) | Native (0.4.x) | +| ------------------------- | :-: | :--------------: | :------------: | :------------: | +| 2.11.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ | +| 2.12.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ | +| 2.13.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ | +| @SCALA3_PREVIOUS_VERSION@ | ✅ | n/a | ✅ | n/a | +| @SCALA3_STABLE_VERSION@ | ✅ | n/a | ✅ | n/a | Next, write a test suite. diff --git a/munit/native/src/main/scala/munit/internal/PlatformCompat.scala b/munit/native/src/main/scala/munit/internal/PlatformCompat.scala index 191370a9..464b3067 100644 --- a/munit/native/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/native/src/main/scala/munit/internal/PlatformCompat.scala @@ -3,7 +3,7 @@ package munit.internal import sbt.testing.TaskDef import munit.MUnitRunner import scala.concurrent.Future -import scala.scalanative.testinterface.PreloadedClassLoader +import scala.scalanative.reflect.Reflect import sbt.testing.Task import sbt.testing.EventHandler import sbt.testing.Logger @@ -33,13 +33,14 @@ object PlatformCompat { taskDef: TaskDef, classLoader: ClassLoader ): Option[MUnitRunner] = { - scala.util.Try { - val suite = classLoader - .asInstanceOf[PreloadedClassLoader] - .loadPreloaded(taskDef.fullyQualifiedName) - .asInstanceOf[munit.Suite] - new MUnitRunner(suite.getClass, () => suite) - }.toOption + Reflect + .lookupInstantiatableClass(taskDef.fullyQualifiedName()) + .map(cls => + new MUnitRunner( + cls.runtimeClass.asInstanceOf[Class[_ <: munit.Suite]], + () => cls.newInstance().asInstanceOf[munit.Suite] + ) + ) } private var myClassLoader: ClassLoader = _ def setThisClassLoader(loader: ClassLoader): Unit = myClassLoader = loader diff --git a/project/plugins.sbt b/project/plugins.sbt index f7d23d9e..45c31871 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,7 +6,7 @@ addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.25") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0") -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.4.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")