NaseemMahasneh
NaseemMahasneh

Reputation: 495

How to run Scala test in Scala native application?

I have hello world scala native app and wanted to run small scala test to this app I use the usual test command but it's throw an exception :

NativeMain.scala

object NativeMain {
  val p = new Person("xxxx")

  def main(args: Array[String]): Unit = {
    println("Hello world")
  }
}
class Person(var name: String)
}

NativeTest.scala

import org.scalatest.{FlatSpec, Matchers}

class NativeTest extends FlatSpec with Matchers {

  "name" should "the name is set correctly in constructor" in {
    assert(NativeMain.p.name == "xxxx")
  }
}

I run test command in the sbt shell and got this error

[IJ]> test
[info] Compiling 1 Scala source to /home/****/Documents/ScalaNativeFresh/target/scala-2.11/classes...
[info] Compiling 1 Scala source to /home/****/Documents/ScalaNativeFresh/target/scala-2.11/test-classes...
[info] Compiling 1 Scala source to /home/****/Documents/ScalaNativeFresh/target/scala-2.11/test-classes...
[info] Linking (28516 ms)
[error] cannot link: @java.lang.Thread::getStackTrace_scala.scalanative.runtime.ObjectArray
[error] unable to link
[error] (nativetest:nativeLink) unable to link
[error] Total time: 117 s, completed Apr 2, 2019 3:04:24 PM

Any help or suggestions thank you :) ?

Upvotes: 4

Views: 326

Answers (1)

Mario Galic
Mario Galic

Reputation: 48410

There is an open issue to add Add support for Scala Native #1112 and according to cheeseng:

3.1.0-SNAP6 and 3.2.0-SNAP10 are the only 2 versions (as of the time of writing) that supports scala-native

Try importing scalatest_native0.3_2.11 like so

libraryDependencies += "org.scalatest" % "scalatest_native0.3_2.11" % "3.2.0-SNAP10"

scalatest-native-example is a working example showing how to use scalatest with scala-native.

Upvotes: 2

Related Questions