This question asks how to get an html report with sbt and ScalaTest. The answers reference Scala test 2.0 and do not appear to work for me with ScalaTest 3.0
I declare ScalaTest by
lazy val scalaTest = Seq("org.scalatest" %% "scalatest" % "3.0.8" % "test",
"org.scalactic" %% "scalactic" % "3.0.8",
"org.scalamock" %% "scalamock" % "4.4.0" % Test)
and then use it by
ThisBuild / Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports")
and
lazy val foo = (project in file("foo")).
settings(libraryDependencies ++= scalaTest)
This fails with
[error] java.lang.NoClassDefFoundError: org/pegdown/PegDownProcessor
[error] at org.scalatest.tools.HtmlReporter.<init>(HtmlReporter.scala:117)
[error] at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:192)
[error] at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:239)
[error] at org.scalatest.tools.ReporterFactory.$anonfun$createReportersFromConfigurations$1(ReporterFactory.scala:248)
[error] at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
[error] at scala.collection.Iterator.foreach(Iterator.scala:941)
[error] at scala.collection.Iterator.foreach$(Iterator.scala:941)
[error] at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
[error] at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error] at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error] at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:42)
...
The question suggests using "test->*" for the test declaration. Trying
lazy val scalaTest = Seq("org.scalatest" %% "scalatest" % "3.0.8" % "test->*" excludeAll (
ExclusionRule(organization="org.junit", name="junit")),
"org.scalamock" %% "scalamock" % "4.4.0" % Test
)
instead fails with
[info] Compiling 1 Scala source to /projects/foo/target/scala-2.12/test-classes ...
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:17:73: Symbol 'type org.scalactic.TripleEquals' is missing from the classpath.
[error] This symbol is required by 'trait org.scalatest.Assertions'.
[error] Make sure that type TripleEquals is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Assertions.class' was compiled against an incompatible version of org.scalactic.
[error] class InfoGainTest extends FlatSpec with Matchers with LoneElement with LazyLogging {
[error] ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:17:42: Symbol 'type org.scalactic.Tolerance' is missing from the classpath.
[error] This symbol is required by 'trait org.scalatest.Matchers'.
[error] Make sure that type Tolerance is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Matchers.class' was compiled against an incompatible version of org.scalactic.
[error] class InfoGainTest extends FlatSpec with Matchers with LoneElement with LazyLogging {
[error] ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:22:54: Symbol 'term org.scalactic.source' is missing from the classpath.
[error] This symbol is required by 'value org.scalatest.Matchers.pos'.
[error] Make sure that term source is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Matchers.class' was compiled against an incompatible version of org.scalactic.
[error] def printGain(gainByProbe: Map[Probe, Double]) = logger.info("Info gain: {}",
[error] ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:27:17: value should is not a member of String
followed by errors that look like the implicit conversions for FlatSpec are not present and are probably follow-on errors from the above.
Is there a way to do this with ScalaTest 3.0?
Try adding pegdown dependency like so
libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0" % Test
Note in ScalaTest 3.1.x pegdown is replaced with flexmark-java as per resolve #1201 replace pegdown with flexmark-java #1229
Related
I've the following Spark Scala code that references 3rd party libraries,
package com.protegrity.spark
import org.apache.spark.sql.api.java.UDF2
import com.protegrity.spark.udf.ptyProtectStr
import com.protegrity.spark.udf.ptyProtectInt
class ptyProtectStr extends UDF2[String, String, String] {
def call(input: String, dataElement: String): String = {
return ptyProtectStr(input, dataElement);
}
}
class ptyUnprotectStr extends UDF2[String, String, String] {
def call(input: String, dataElement: String): String = {
return ptyUnprotectStr(input, dataElement);
}
}
class ptyProtectInt extends UDF2[Integer, String, Integer] {
def call(input: Integer, dataElement: String): Integer = {
return ptyProtectInt(input, dataElement);
}
}
class ptyUnprotectInt extends UDF2[Integer, String, Integer] {
def call(input: Integer, dataElement: String): Integer = {
return ptyUnprotectInt(input, dataElement);
}
}
I want to create JAR file using SBT. My build.sbt looks like the following,
name := "Protegrity UDF"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"com.protegrity.spark" % "udf" % "2.3.2" % "provided",
"org.apache.spark" %% "spark-core" % "2.3.2" % "provided",
"org.apache.spark" %% "spark-sql" % "2.3.2" % "provided"
)
As you see, I trying to create a thin JAR file using "provided" option as my Spark environment already contains those libraries.
In spite of using "provided", sbt is trying to download from maven and throwing below error,
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading com.protegrity.spark:udf:2.3.2
[error] Not found
[error] Not found
[error] not found: C:\Users\user1\.ivy2\local\com.protegrity.spark\udf\2.3.2\ivys\ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/protegrity/spark/udf/2.3.2/udf-2.3.2.pom
[error] at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:249)
[error] at lmcoursier.CoursierDependencyResolution.$anonfun$update$35(CoursierDependencyResolution.scala:218)
[error] at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:218)
[error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:52)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:102)
[error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:69)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$20(LibraryManagement.scala:115)
[error] at scala.util.control.Exception$Catch.apply(Exception.scala:228)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:115)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:96)
[error] at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:150)
[error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:129)
[error] at sbt.Classpaths$.$anonfun$updateTask0$5(Defaults.scala:2950)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[error] at sbt.Execute.work(Execute.scala:290)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error] at java.lang.Thread.run(Unknown Source)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.protegrity.spark:udf:2.3.2
[error] Not found
[error] Not found
[error] not found: C:\Users\user1\.ivy2\local\com.protegrity.spark\udf\2.3.2\ivys\ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/protegrity/spark/udf/2.3.2/udf-2.3.2.pom
What change in build.sbt should I make to skip the maven download for "com.protegrity.spark"? Interestingly, I don't face this issue for "org.apache.spark" on the same build
Assuming that you have the JAR file available (but not through Maven or another artifact repository) wherever you're compiling the code, just place the JAR in (by default) the lib directory within your project (the path can be changed with the unmanagedBase setting in build.sbt if you need to do that for some reason).
Note that this will result in the unmanaged JAR being included in an assembly JAR. If you want to build a "slightly less fat" JAR that excludes the unmanaged JAR, you'll have to filter it out. One way to accomplish this is with
assemblyExcludedJars in assembly := {
val cp = (fullClasspath in assembly).value
cp.filter(_.data.getName == "name-of-unmanaged.jar")
}
If you don't have the JAR (or perhaps something very close to the JAR) handy, how exactly do you expect the compiler to typecheck your calls into the JAR?
I have multiple subprojects in my sbt, one being a server (base upon playframework) the other being the clientside (scala.js) and the third one being the communication between the two in form of protobuf (scalapb).
Now, this is my build.sbt:
lazy val generalSettings = Seq(
organization := "tld.awesomeness",
version := "0.0.1",
scalaVersion := "2.12.1"
)
val CrossDependencies = new
{
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1" % "test"
val scalactic = "org.scalactic" %% "scalactic" % "3.0.1"
val scalaTags = "com.lihaoyi" %% "scalatags" % "0.6.2"
}
lazy val proto = (project in file("modules/proto"))
.settings(generalSettings: _*)
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
),
// If you need scalapb/scalapb.proto or anything from google/protobuf/*.proto
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
)
)
lazy val play = (project in file("modules/play"))
.enablePlugins(PlayScala)
.settings(generalSettings: _*)
.settings(
name := "play",
libraryDependencies ++= Seq(
CrossDependencies.scalaTest,
CrossDependencies.scalactic,
CrossDependencies.scalaTags,
"com.typesafe.play" %% "play-json" % "2.6.0-M1"),
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
)
.aggregate(slick)
.dependsOn(slick)
.aggregate(flyway)
.dependsOn(flyway)
.aggregate(proto)
.dependsOn(proto)
lazy val client = (project in file("modules/client"))
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies += CrossDependencies.scalaTags,
persistLauncher := true
)
.aggregate(proto)
.dependsOn(proto)
// Loads the jvm project at sbt startup
onLoad in Global := (Command.process("project play", _: State)) compose (onLoad in Global).value
fork in run := true
and this is the plugins.sbt:
// Scala.JS
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.0.2")
// Play
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0-SNAPSHOT")
// Proto
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.3" exclude ("com.trueaccord.scalapb", "protoc-bridge_2.10"))
libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin-shaded" % "0.5.47"
This is one proto file:
syntax = "proto3";
package tld.awesomeness.proto;
message Test {
int32 id = 1;
string email = 2;
}
After compilation I get Test.class
Now in the client I try to:
private def doSend(ws: WebSocket): Unit =
{
val msg = Test().withId(1337)
val a: ArrayBuffer = new ArrayBuffer(msg.toByteArray.length)
msg.toByteArray
ws.send(a)
}
(The websocket itself worked all just fine when I sent strings through it!)
Now I get this huge stacktrace:
[info] Fast optimizing /home/sorona/awesomeness/modules/client/target/scala-2.12/client-fastopt.js
[error] Referring to non-existent class tld.awesomeness.proto.Test.Test$
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent class tld.awesomeness.proto.Test.Test
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.toByteArray()[scala.Byte
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.withId(scala.Int)tld.awesomeness.proto.Test.Test
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test$.apply$default$2()java.lang.String
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test$.apply$default$1()scala.Int
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.<init>(scala.Int,java.lang.String)
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
java.lang.RuntimeException: There were linking errors
at scala.sys.package$.error(package.scala:27)
at org.scalajs.core.tools.linker.frontend.BaseLinker.linkInternal(BaseLinker.scala:133)
at org.scalajs.core.tools.linker.frontend.BaseLinker.linkInternal(BaseLinker.scala:86)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend$$anonfun$4.apply(LinkerFrontend.scala:54)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend$$anonfun$4.apply(LinkerFrontend.scala:54)
at org.scalajs.core.tools.logging.Logger$class.time(Logger.scala:28)
at org.scalajs.sbtplugin.Loggers$SbtLoggerWrapper.time(Loggers.scala:7)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend.link(LinkerFrontend.scala:53)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply$mcV$sp(Linker.scala:50)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply(Linker.scala:49)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply(Linker.scala:49)
at org.scalajs.core.tools.linker.Linker.guard(Linker.scala:67)
at org.scalajs.core.tools.linker.Linker.link(Linker.scala:49)
at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
at org.scalajs.core.tools.linker.ClearableLinker.linkerOp(ClearableLinker.scala:62)
at org.scalajs.core.tools.linker.ClearableLinker.link(ClearableLinker.scala:51)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:251)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:239)
at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:267)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:263)
at sbt.Difference.apply(Tracked.scala:224)
at sbt.Difference.apply(Tracked.scala:206)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:263)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:262)
at sbt.Difference.apply(Tracked.scala:224)
at sbt.Difference.apply(Tracked.scala:200)
at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:262)
at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:260)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:256)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:237)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (client/compile:fastOptJS) There were linking errors
My ide finds everything but obviously I am doing something wrong. I already had a look at https://github.com/thesamet/scalapbjs-test but to no avail.
Problem appears with that line val msg = Test().withId(1337)
edit: after comment I changed build.sbt:
lazy val proto = (crossProject in file("modules/proto"))
.settings(generalSettings: _*)
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)).
jvmSettings(
libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
).
jsSettings(
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
),
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
)
lazy val protoJs = proto.js
lazy val protoJVM = proto.jvm
lazy val play = (project in file("modules/play"))
.enablePlugins(PlayScala)
.settings(generalSettings: _*)
.settings(
name := "play",
libraryDependencies ++= Seq(
CrossDependencies.scalaTest,
CrossDependencies.scalactic,
CrossDependencies.scalaTags,
"com.typesafe.play" %% "play-json" % "2.6.0-M1"),
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
)
.aggregate(slick)
.dependsOn(slick)
.aggregate(flyway)
.dependsOn(flyway)
.aggregate(protoJVM)
.dependsOn(protoJVM)
lazy val client = (project in file("modules/client"))
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies += CrossDependencies.scalaTags,
persistLauncher := true
)
.aggregate(protoJs)
.dependsOn(protoJs)
now now neither play nor client can resolve the proto-class :(
(Also I am aware of the redundant PB.targets in Compile..., I just thought that sharing might not work there, so I added it to both distinct settings again)
With pure CrossProject you need to specify the actual path ScalaPB should look for proto files (the value it guesses is wrong). Here is a minimal example:
lazy val proto = (crossProject.crossType(CrossType.Pure) in file("proto"))
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
),
// The trick is in this line:
PB.protoSources in Compile := Seq(file("proto/src/main/protobuf")),
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
)
)
I attempted to test the ping-pong example (from activator's minimal-akka-scala-seed) using both scalatest, and specs2 (I wrote the specs2 tests myself; see below).
The scalatest always passes. However, the specs2 tests do not pass all the time (i.e. if I rerun the same tests several times). When it fails, it has the following output:
[info] PingPongActorSpecs2
[info]
[info] A Ping actor in specs2 should should
[error] ! send back a ping on a pong
[error] assertion failed: expected PingMessage(ping), found PongMessage(pong) (TestKit.scala:339)
[error] akka.testkit.TestKitBase$class.expectMsg_internal(TestKit.scala:339)
[error] akka.testkit.TestKitBase$class.expectMsg(TestKit.scala:315)
[error] akka.testkit.TestKit.expectMsg(TestKit.scala:718)
[error] com.example.PingPongActorSpecs2$$anonfun$1$$anonfun$apply$1$$anon$1$$anonfun$2.apply(PingPongActor2Spec.scala:27)
[error] com.example.PingPongActorSpecs2$$anonfun$1$$anonfun$apply$1$$anon$1$$anonfun$2.apply(PingPongActor2Spec.scala:25)
[error] akka.testkit.TestKitBase$class.within(TestKit.scala:296)
[error] akka.testkit.TestKit.within(TestKit.scala:718)
[error] akka.testkit.TestKitBase$class.within(TestKit.scala:310)
[error] akka.testkit.TestKit.within(TestKit.scala:718)
[error] com.example.PingPongActorSpecs2$$anonfun$1$$anonfun$apply$1$$anon$1.<init>(PingPongActor2Spec.scala:25)
[error] com.example.PingPongActorSpecs2$$anonfun$1$$anonfun$apply$1.apply(PingPongActor2Spec.scala:23)
[error] com.example.PingPongActorSpecs2$$anonfun$1$$anonfun$apply$1.apply(PingPongActor2Spec.scala:23)
[info]
[info] A Pong actor in specs2 should should
[error] ! send back a pong on a ping
[error] assertion failed: expected PongMessage(pong), found PingMessage(ping) (TestKit.scala:339)
[error] akka.testkit.TestKitBase$class.expectMsg_internal(TestKit.scala:339)
[error] akka.testkit.TestKitBase$class.expectMsg(TestKit.scala:315)
[error] akka.testkit.TestKit.expectMsg(TestKit.scala:718)
[error] com.example.PingPongActorSpecs2$$anonfun$3$$anonfun$apply$2$$anon$2$$anonfun$4.apply(PingPongActor2Spec.scala:37)
[error] com.example.PingPongActorSpecs2$$anonfun$3$$anonfun$apply$2$$anon$2$$anonfun$4.apply(PingPongActor2Spec.scala:35)
[error] akka.testkit.TestKitBase$class.within(TestKit.scala:296)
[error] akka.testkit.TestKit.within(TestKit.scala:718)
[error] akka.testkit.TestKitBase$class.within(TestKit.scala:310)
[error] akka.testkit.TestKit.within(TestKit.scala:718)
[error] com.example.PingPongActorSpecs2$$anonfun$3$$anonfun$apply$2$$anon$2.<init>(PingPongActor2Spec.scala:35)
[error] com.example.PingPongActorSpecs2$$anonfun$3$$anonfun$apply$2.apply(PingPongActor2Spec.scala:33)
[error] com.example.PingPongActorSpecs2$$anonfun$3$$anonfun$apply$2.apply(PingPongActor2Spec.scala:33)
[info]
[info]
[info] Total for specification PingPongActorSpecs2
[info] Finished in 19 ms
[info] 3 examples, 0 failure, 2 errors
The specs2 tests I implemented are as follows (very similar to the scalatest in the test folder of the minimal-akka-scala-seed):
package com.example
import org.specs2.mutable.SpecificationLike
import org.specs2.specification.AfterAll
import akka.actor.{ Actor, ActorSystem, Props }
import akka.testkit.{ TestKit, ImplicitSender }
class PingPongActorSpecs2(_system: ActorSystem) extends TestKit(_system)
with ImplicitSender
with SpecificationLike
with AfterAll {
import scala.concurrent.duration._
def this() = this(ActorSystem("MySpec"))
override def afterAll {
TestKit.shutdownActorSystem(system)
}
lazy val waitTime = 1 seconds
"A Ping actor in specs2 should" >> {
"send back a ping on a pong" >> {
val pingActor = system.actorOf(PingActor.props)
within (waitTime) {
pingActor ! PongActor.PongMessage("pong")
expectMsg(PingActor.PingMessage("ping"))
true
}
}
}
"A Pong actor in specs2 should" >> {
"send back a pong on a ping" >> {
val pongActor = system.actorOf(PongActor.props)
within (waitTime) {
pongActor ! PingActor.PingMessage("ping")
expectMsg(PongActor.PongMessage("pong"))
true
}
}
}
}
My library dependencies are as follows:
scalaVersion := "2.11.6"
lazy val akkaVersion = "2.3.13"
lazy val scalaTestVersion = "2.2.4"
lazy val specs2Version = "3.6"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.specs2" %% "specs2-core" % specs2Version
)
Does anyone know where I am screwing up in my specs2 tests?
Specs2 specifications execute examples concurrently so it is possible that your 2 examples interact with each other. You can either create one system per example (expensive) or use the sequential argument to have your tests being executed sequentially:
class PingPongActorSpecs2(_system: ActorSystem) extends TestKit(_system)
with ImplicitSender
with SpecificationLike
with AfterAll {
import scala.concurrent.duration._
sequential
...
}
src/main/scala/Testing.scala
package common
object Add1Method {
def main(args: Array[String]) = 100+2
}
project/build.sbt
name := "Foo"
version := "1.0"
scalaVersion := "2.10.2"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += "Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases"
src/test/scala/Test.scala
package test
import common.Testing
import org.scalatest._
class Test extends FlatSpec with Matchers {
"running main" should "return 102" in {
val result = Add1Method.main(Array("asdf"))
assert(result == 102)
}
}
But, when I run test from SBT, the following 4 compile-time errors:
[error] Test.scala:4: object scalatest is not a member of package org
[error] import org.scalatest._
[error] ^
[error] Test.scala:6: not found: type FlatSpec
[error] class Test extends FlatSpec with Matchers {
[error] ^
[error] Test.scala:6: not found: type Matchers
[error] class Test extends FlatSpec with Matchers {
[error] ^
[error] Test.scala:8: value should is not a member of String
[error] "running main" should "return 102" in {
[error] ^
[error] four errors found
Note that I tried the suggested answer in SBT not finding scalatest for scala 2.10.1 without success.
The ScalaTest example uses the same imports - http://www.scalatest.org/quick_start.
I think the problem is that your build.sbt is in the wrong place. It should not be in project/ but in the root directory, next to the src directory.
See Directories in the sbt documentation for more info.
Here's a simple specification reproducing the issue:
package ro.igstan.learning
import org.specs2.matcher.ThrownExpectations
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
class LearningSpecs2 extends Specification {
trait Logger {
def error(a: String, b: String)
}
trait mocks extends Mockito with Scope with ThrownExpectations {
val mockedLogger = mock[Logger]
}
"mocking" should {
// passes
"be able to verify arguments passed to mocks" in new mocks {
mockedLogger.error("message", "foo")
got {
one(mockedLogger).error("message", "foo")
}
}
// fails
"be able to *partially* verify arguments passed to mocks" in new mocks {
mockedLogger.error("message", "foo")
got {
one(mockedLogger).error(any, ===("foo"))
}
}
}
}
This is the output:
[info] mocking should
[info] + be able to verify arguments passed to mocks
[error] ! Fragment evaluation error
[error] ThrowableException: org/hamcrest/TypeSafeMatcher (FutureTask.java:303)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] org/hamcrest/TypeSafeMatcher
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] org.hamcrest.TypeSafeMatcher
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
And here are the library versions as reported by the SBT dependency graph plugin:
[info] default:learning_2.9.1:1.0.0
[info] +-junit:junit:4.7
[info] +-org.mockito:mockito-all:1.9.0
[info] +-org.scala-lang:scala-library:2.9.1
[info] +-org.specs2:specs2_2.9.1:1.11
[info] +-org.specs2:specs2-scalaz-core_2.9.1:6.0.1
[info] +-org.scala-lang:scala-library:2.9.1
Any idea what's going on?
Fixed. I had to explicitly specify the Hamcrest version:
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "1.11" ,
"org.mockito" % "mockito-all" % "1.9.0",
"org.hamcrest" % "hamcrest-all" % "1.3", // <- this was missing
"junit" % "junit" % "4.7"
)