Skip to content

Commit

Permalink
Merge pull request #2 from biandratti/feature/tests
Browse files Browse the repository at this point in the history
unit tests
  • Loading branch information
biandratti authored Dec 30, 2023
2 parents 9ca4a9e + b061db5 commit 564f371
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ jobs:
cd rust-module && cargo build --release
- name: Build Scala native binary
run: sbt nativeLink
- name: Runt Tests
run: |
export LD_LIBRARY_PATH=${PWD}/rust-module/target/release/:$LD_LIBRARY_PATH
sbt test
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ sbt scalaModule/run

#### Run binary:
```
sbt compile
./scala-module/target/scala-2.12/scalamodule-out
sbt nativeLink
./scala-module/target/scala-3.3.1/scalamodule-out
```

#### Run test:
```
sbt test
```
31 changes: 22 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
scalaVersion := "3.3.1"


// set to Debug for compilation details (Info is default)
logLevel := Level.Info

// import to add Scala Native options
import scala.scalanative.build._

Expand All @@ -14,18 +8,37 @@ nativeConfig ~= { c =>
.withGC(GC.immix) // commix
}

lazy val commonSettings = Seq(
// organization := "com.biandratti",
scalaVersion := "3.3.1",
logLevel := Level.Info /*,
scalacOptions ++= List(
"-Wunused"
)*/
)

lazy val root = (project in file("."))
.settings(commonSettings)
.aggregate(scalaModule)
.settings()

lazy val scalaModule = project
.in(file("scala-module"))
.enablePlugins(ScalaNativePlugin)
.settings(commonSettings)
.dependsOn(rustModule)
.aggregate(rustModule)
.settings(
nativeLinkingOptions := Seq(s"-L${baseDirectory.value.getParentFile}/rust-module/target/release/", "-lrust_code")
nativeLinkingOptions := Seq(
s"-L${baseDirectory.value.getParentFile}/rust-module/target/release/",
"-lrust_code"
),
libraryDependencies ++= Seq(
// "org.typelevel" %% "cats-effect" % "3.5.2",
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.scalameta" %% "munit-scalacheck" % "0.7.29" % Test
)
)

lazy val rustModule = project
.in(file("rust-module"))
.settings()
.settings(commonSettings)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package `com.biandratti`
package com.biandratti

object Main {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package `com.biandratti`
package com.biandratti

import scala.scalanative.unsafe._

Expand Down
10 changes: 10 additions & 0 deletions scala-module/src/test/scala/com/biandratti/RustInteropSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.biandratti

import munit.FunSuite

class RustInteropSpec extends FunSuite {

test("multiply_by_two called") {
assertEquals(RustInterop.multiply_by_two(5), 10)
}
}

0 comments on commit 564f371

Please sign in to comment.