Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross publish native #477

Merged
merged 5 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def previousVersion = "0.7.0"
def scala213 = "2.13.6"
def scala212 = "2.12.15"
def scala211 = "2.11.12"
def scala3 = "3.0.1"
def scala3 = "3.1.1"
def junitVersion = "4.13.2"
def gcp = "com.google.cloud" % "google-cloud-storage" % "2.6.0"
inThisBuild(
Expand Down Expand Up @@ -49,8 +49,10 @@ addCommandAlias(
)
val isPreScala213 = Set[Option[(Long, Long)]](Some((2, 11)), Some((2, 12)))
val scala2Versions = List(scala213, scala212, scala211)

val scala3Versions = List(scala3)
val allScalaVersions = scala2Versions ++ scala3Versions

def isNotScala211(v: Option[(Long, Long)]): Boolean = !v.contains((2, 11))
def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
val isScala3Setting = Def.setting {
Expand Down Expand Up @@ -126,18 +128,21 @@ lazy val mimaEnable: List[Def.Setting[_]] = List(
else Set("org.scalameta" % moduleName.value % previousVersion)
}
)

val sharedJVMSettings: List[Def.Setting[_]] = List(
crossScalaVersions := allScalaVersions
) ++ mimaEnable

val sharedJSSettings: List[Def.Setting[_]] = List(
skipIdeaSettings,
crossScalaVersions := allScalaVersions.filterNot(_.startsWith("0."))
)
val sharedJSConfigure: Project => Project =
_.disablePlugins(MimaPlugin)

val sharedNativeSettings: List[Def.Setting[_]] = List(
skipIdeaSettings,
crossScalaVersions := scala2Versions
crossScalaVersions := allScalaVersions
kpodsiad marked this conversation as resolved.
Show resolved Hide resolved
)
val sharedNativeConfigure: Project => Project =
_.disablePlugins(ScalafixPlugin, MimaPlugin)
Expand Down Expand Up @@ -273,7 +278,7 @@ lazy val munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform)
libraryDependencies += {
val partialVersion = CrossVersion.partialVersion(scalaVersion.value)
if (isNotScala211(partialVersion))
"org.scalacheck" %%% "scalacheck" % "1.15.4"
"org.scalacheck" %%% "scalacheck" % "1.16.0"
else
"org.scalacheck" %%% "scalacheck" % "1.15.2"
}
Expand All @@ -287,6 +292,7 @@ lazy val munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform)
)
.jsConfigure(sharedJSConfigure)
.jsSettings(sharedJSSettings)

lazy val munitScalacheckJVM = munitScalacheck.jvm
lazy val munitScalacheckJS = munitScalacheck.js
lazy val munitScalacheckNative = munitScalacheck.native
Expand Down
6 changes: 3 additions & 3 deletions munit/non-jvm/src/main/scala/munit/Framework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import munit.internal.junitinterface.CustomRunners
import munit.internal.junitinterface.JUnitFramework

class Framework extends JUnitFramework {
override val name = "munit"
val munitFingerprint = new CustomFingerprint("munit.Suite", isModule = false)
override def name(): String = "munit"
val munitFingerprint = new CustomFingerprint("munit.Suite", _isModule = false)
val customRunners = new CustomRunners(
List(
munitFingerprint,
new CustomFingerprint("munit.Suite", isModule = true)
new CustomFingerprint("munit.Suite", _isModule = true)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import sbt.testing.SubclassFingerprint

class CustomFingerprint(
val suite: String,
val isModule: Boolean
_isModule: Boolean
kpodsiad marked this conversation as resolved.
Show resolved Hide resolved
) extends SubclassFingerprint {
override def isModule(): Boolean = _isModule
override def superclassName(): String = suite
override def requireNoArgConstructor(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import sbt.testing._

final class JUnitEvent(
taskDef: TaskDef,
val fullyQualifiedName: String,
val status: Status,
val selector: Selector,
val throwable: OptionalThrowable = new OptionalThrowable,
val duration: Long = -1L
_fullyQualifiedName: String,
_status: Status,
_selector: Selector,
_throwable: OptionalThrowable = new OptionalThrowable,
_duration: Long = -1L
) extends Event {
def fingerprint: Fingerprint = taskDef.fingerprint
override def status(): Status = _status
override def selector(): Selector = _selector
override def throwable(): OptionalThrowable = _throwable
override def duration(): Long = _duration
override def fullyQualifiedName(): String = _fullyQualifiedName
override def fingerprint(): Fingerprint = taskDef.fingerprint()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sbt.testing._

abstract class JUnitFramework extends Framework {

val name: String = "Scala.js JUnit test framework"
override def name(): String = "Scala.js JUnit test framework"

def customRunners: CustomRunners

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class JUnitReporter(
throwable: OptionalThrowable = new OptionalThrowable
): Unit = {
val testName =
taskDef.fullyQualifiedName + "." +
taskDef.fullyQualifiedName() + "." +
settings.decodeName(method)
val selector = new TestSelector(testName)
eventHandler.handle(
Expand Down Expand Up @@ -215,7 +215,7 @@ final class JUnitReporter(

private def findTestFileName(trace: Array[StackTraceElement]): String =
trace
.find(_.getClassName == taskDef.fullyQualifiedName)
.find(_.getClassName == taskDef.fullyQualifiedName())
.map(_.getFileName)
.orNull

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import munit.internal.PlatformCompat

final class JUnitRunner(
val args: Array[String],
val remoteArgs: Array[String],
_remoteArgs: Array[String],
runSettings: RunSettings,
classLoader: ClassLoader,
customRunners: CustomRunners
) extends Runner {
PlatformCompat.setThisClassLoader(classLoader)

def tasks(taskDefs: Array[TaskDef]): Array[Task] =
override def remoteArgs(): Array[String] = _remoteArgs

override def tasks(taskDefs: Array[TaskDef]): Array[Task] =
taskDefs.map(new JUnitTask(_, runSettings, classLoader))

def done(): String = ""
override def done(): String = ""

def serializeTask(task: Task, serializer: TaskDef => String): String =
serializer(task.taskDef)
override def serializeTask(
task: Task,
serializer: TaskDef => String
): String =
serializer(task.taskDef())

def deserializeTask(task: String, deserializer: String => TaskDef): Task =
override def deserializeTask(
task: String,
deserializer: String => TaskDef
): Task =
new JUnitTask(deserializer(task), runSettings, classLoader)

def receiveMessage(msg: String): Option[String] = None
override def receiveMessage(msg: String): Option[String] = None
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import scala.concurrent.ExecutionContext.Implicits.global
* under the hood and stay consistent with JVM JUnit.
*/
final class JUnitTask(
val taskDef: TaskDef,
_taskDef: TaskDef,
runSettings: RunSettings,
classLoader: ClassLoader
) extends Task {

def tags: Array[String] = Array.empty
override def taskDef(): TaskDef = _taskDef
override def tags(): Array[String] = Array.empty

def execute(
eventHandler: EventHandler,
Expand All @@ -36,12 +37,12 @@ final class JUnitTask(
loggers: Array[Logger],
continuation: Array[Task] => Unit
): Unit = {
PlatformCompat.newRunner(taskDef, classLoader) match {
PlatformCompat.newRunner(taskDef(), classLoader) match {
case None =>
case Some(runner) =>
runner.filter(runSettings.tags)
val reporter =
new JUnitReporter(eventHandler, loggers, runSettings, taskDef)
new JUnitReporter(eventHandler, loggers, runSettings, taskDef())
val notifier: RunNotifier = new MUnitRunNotifier(reporter)
runner.runAsync(notifier).foreach(_ => continuation(Array()))
}
Expand Down
5 changes: 4 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.23")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.9.0")

addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.4")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.6.0")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.0")
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.6.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class ScalaCheckExceptionFrameworkSuites
tags = Set(OnlyJVM),
onEvent = { event =>
if (
event.throwable.isDefined &&
event.throwable().get.getCause() != null
event.throwable().isDefined() &&
event.throwable().get().getCause() != null
) {
event
.throwable()
.get
.get()
.getCause
.getStackTrace()
.take(2)
Expand Down
3 changes: 1 addition & 2 deletions tests/shared/src/test/scala/munit/BaseFrameworkSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ abstract class BaseFrameworkSuite extends BaseSuite {
}
}
implicit val ec = munitExecutionContext
val elapsedTimePattern =
Pattern.compile(" \\d+\\.\\d+s ?", Pattern.MULTILINE)
val elapsedTimePattern = Pattern.compile(" \\d+\\.\\d+s ?")
TestingConsole.out = out
TestingConsole.err = out
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class ComparisonFailExceptionSuite extends BaseSuite {
// console still uses `munitPrint()`, which would have displayed `List("1",
// "2", "3")` instead of `List(1, 2, 3)`.
assertNoDiff(
e.getActual,
e.getActual(),
"List(1, 2, 3)"
)
assertNoDiff(
e.getExpected,
e.getExpected(),
"List(1, 2)"
)
assertEquals(e.expected, List(1, 2))
Expand Down