Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :) ?

like image 698
NaseemMahasneh Avatar asked Oct 20 '25 22:10

NaseemMahasneh


1 Answers

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.

like image 166
Mario Galic Avatar answered Oct 23 '25 01:10

Mario Galic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!