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

enable scala-native junit tests #1229

Merged
merged 3 commits into from
Feb 10, 2022
Merged
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
19 changes: 16 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ addCommandAlias("examples", ";project examplesJVM")
addCommandAlias("validate", ";root;validateJVM;validateJS;validateNative")
addCommandAlias("validateJVM", ";coreJVM/compile;coreJVM/mimaReportBinaryIssues;coreJVM/test;examplesJVM/compile;examplesJVM/test;coreJVM/doc")
addCommandAlias("validateJS", ";coreJS/compile;coreJS/mimaReportBinaryIssues;coreJS/test;examplesJS/compile;examplesJS/test;coreJS/doc")
addCommandAlias("validateNative", ";coreNative/compile;nativeTest/run;examplesNative/compile")
addCommandAlias("validateNative", ";coreNative/compile;coreNative/test;nativeTest/run;examplesNative/compile;examplesNative/test;coreNative/doc")
addCommandAlias("runAll", ";examplesJVM/runAll")

def scalacOptionsAll(pluginJar: File) = List(
Expand Down Expand Up @@ -121,6 +121,21 @@ def configureJUnit(crossProject: CrossProject) = {
libraryDependencies +=
"com.github.sbt" % "junit-interface" % "0.13.3" % "test"
)
.nativeSettings(
libraryDependencies += "org.scala-native" %%% "junit-runtime" % nativeVersion,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not % Test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scala-native compiler plugin( "org.scala-native" % "junit-plugin" ) throw error in compile time if set % Test.

[error] scala.reflect.internal.MissingRequirementError: object org.junit.Test in compiler mirror not found.
[error] scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:24)
[error] scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$6(Mirrors.scala:66)
[error] scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
[error] scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:56)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$JUnitAnnots$.<init>(ScalaNativeJUnitPlugin.scala:48)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$.JUnitAnnots$lzycompute$1(ScalaNativeJUnitPlugin.scala:47)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$.scala$scalanative$junit$plugin$ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$$JUnitAnnots(ScalaNativeJUnitPlugin.scala:47)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer.$anonfun$transform$1(ScalaNativeJUnitPlugin.scala:97)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer.$anonfun$transform$1$adapted(ScalaNativeJUnitPlugin.scala:96)
[error] scala.collection.IterableOnceOps.exists(IterableOnce.scala:591)
[error] scala.collection.IterableOnceOps.exists$(IterableOnce.scala:588)
[error] scala.collection.AbstractIterable.exists(Iterable.scala:926)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer.hasTests$1(ScalaNativeJUnitPlugin.scala:96)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer.scala$scalanative$junit$plugin$ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer$$isTest$1(ScalaNativeJUnitPlugin.scala:107)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer$$anonfun$1.applyOrElse(ScalaNativeJUnitPlugin.scala:111)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer$$anonfun$1.applyOrElse(ScalaNativeJUnitPlugin.scala:110)
[error] scala.collection.immutable.List.collect(List.scala:267)
[error] scala.scalanative.junit.plugin.ScalaNativeJUnitPlugin$ScalaNativeJUnitPluginComponent$ScalaNativeJUnitPluginTransformer.transform(ScalaNativeJUnitPlugin.scala:110)
[error] scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:183)
[error] scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:32)
[error] scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:459)
[error] scala.tools.nsc.Global$GlobalPhase.run(Global.scala:406)
[error] scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1524)
[error] scala.tools.nsc.Global$Run.compileUnits(Global.scala:1508)
[error] scala.tools.nsc.Global$Run.compileSources(Global.scala:1500)
[error] scala.tools.nsc.Global$Run.compileFiles(Global.scala:1613)
[error] xsbt.CachedCompiler0.run(CompilerBridge.scala:163)

Copy link
Contributor Author

@xuwei-k xuwei-k Jan 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I noticed that it works in shapeless-3 - how is that possible? 🤔

addCompilerPlugin("org.scala-native" % "junit-plugin" % nativeVersion cross CrossVersion.full),
pomPostProcess := { node =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import scala.xml._
import scala.xml.transform._
new RuleTransformer(new RewriteRule{
override def transform(n: Node) =
if (n.label == "dependency" && (n \ "artifactId").text.startsWith("junit-runtime_native"))
NodeSeq.Empty
else
n
}).transform(node)(0)
},
)
}

lazy val commonJsSettings = Seq(
Expand Down Expand Up @@ -180,7 +195,6 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(
Compile / packageDoc / publishArtifact := false,
packageDoc / publishArtifact := false,
Compile / doc / sources := Nil,
Test / sources := Nil
)

lazy val coreJVM = core.jvm
Expand Down Expand Up @@ -224,7 +238,6 @@ lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossT
.jvmSettings(commonJvmSettings:_*)
.nativeSettings(
Compile / sources ~= (_.filterNot(_.getName == "sexp.scala")),
Test / sources := Nil
)

lazy val examplesJVM = examples.jvm
Expand Down