Skip to content

Commit

Permalink
Replace utest with ScalaTest (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas authored Aug 31, 2018
1 parent 379a010 commit 634c370
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 57 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ lazy val samples = nativeProject("samples")
.in(file("tests/samples"))
.settings(
publish / skip := true,
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.3" % Test,
testFrameworks += new TestFramework("utest.runner.Framework"),
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test,
compileTask("bindgentests", baseDirectory)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.scalanative.bindgen.samples

import utest._
import org.scalatest.FunSpec
import scalanative.native._

object EnumTests extends TestSuite {
val tests = Tests {
'get_WEDNESDAY - {
class EnumSpec extends FunSpec {
describe("enum bindings") {
it("should bind to C enum values") {
assert(Enum.get_WEDNESDAY() == Enum.enum_days.WEDNESDAY)
}

'check_BIG_NEG_A - {
it("should handle large negative values") {
assert(
Enum.check_BIG_NEG_A(Enum.enum_bigNegativeValues.BIG_NEG_A) == c"OK")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.scalanative.bindgen.samples

import utest._
import org.scalatest.FunSpec
import scalanative.native._

object ExternTests extends TestSuite {
val tests = Tests {
'forty_two - {
class ExternSpec extends FunSpec {
describe("extern variable bindings") {
it("should bind to C variable") {
assert(Extern.forty_two == 42)
}

'mode - {
assert(Extern.mode == Extern.enum_mode.USER)
}

'semver - {
it("should bind to C struct variable") {
import Extern.implicits._
assert(
Extern.semver.major == 1 && Extern.semver.minor == 2 && Extern.semver.patch == 3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package org.scalanative.bindgen.samples

import utest._
import org.scalatest.FunSpec
import scalanative.native._

object FunctionTests extends TestSuite {
val tests = Tests {
'no_args - {
class FunctionSpec extends FunSpec {
describe("function bindings") {
it("should bind to function with no args") {
assert(Function.no_args() == 42)
}

'void_arg - {
it("should bind to function with void args") {
assert(Function.void_arg() == 1.5)
}

'one_arg - {
it("should bind to function with one arg") {
assert(Function.one_arg(42) == '*')
}

'two_args - {
it("should bind to function with two arg") {
val result = Function.two_args(3.14.toFloat, 1024)
val string = fromCString(result.cast[CString])
assert(string == "3.14 1024")
}

'anonymous_args - {
it("should bind to function with anonymous args") {
assert(Function.anonymous_args(1.5.toFloat, 42) == 43.5)
}

'variadic_args - {
it("should bind to function with variadic args") {
Zone { implicit z =>
val result =
Function.variadic_args(0.2, toCString("0123"), 1, 10, 100, 1000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.scalanative.bindgen.samples

import utest._
import scala.scalanative.native._
import org.scalatest.FunSpec
import scalanative.native._

import org.scalanative.bindgen.samples.Struct.implicits._

object StructTests extends TestSuite {
val tests = Tests {
'point - {
class StructSpec extends FunSpec {
describe("struct bindings") {
it("should provide field getters and setters") {
val point = Struct.createPoint()
assert(point.x == 10)
assert(point.y == 20)
Expand All @@ -15,19 +16,19 @@ object StructTests extends TestSuite {
assert(point.x == 11)
}

'constructor - {
it("should provide constructors") {
Zone { implicit Zone =>
val pointNoValue = Struct.struct_point()
assert(pointNoValue.x == 0)
assert(pointNoValue.y == 0)

val point = Struct.struct_point(1, 2)
assert(point.x == 1)
assert(point.y == 2)
}
}

'bigStructSize - {
assert(Struct.getBigStructSize() == sizeof[Struct.struct_bigStruct])
}

'getFieldsOfInnerStruct - {
it("should provided field getters for inner structs") {
Zone { implicit zone =>
val points = Struct.struct_points()
Struct.setPoints(points, 1, 2, 3, 4)
Expand All @@ -38,7 +39,7 @@ object StructTests extends TestSuite {
}
}

'setFieldsOfInnerStruct - {
it("should provided field setters for inner structs") {
Zone { implicit zone =>
val points = Struct.struct_points()
points.p1.x = 1
Expand All @@ -52,7 +53,7 @@ object StructTests extends TestSuite {
}
}

'innerAnonymousStruct - {
it("should support anonymous structs") {
type struct_anonymousStruct = CStruct2[CChar, CInt]
Zone { implicit zone =>
val anonymousStruct: Ptr[struct_anonymousStruct] =
Expand All @@ -71,7 +72,11 @@ object StructTests extends TestSuite {
}
}

'getFieldOfBigStruct - {
it("should match size of C memory layout for big structs") {
assert(Struct.getBigStructSize() == sizeof[Struct.struct_bigStruct])
}

it("should provide field getters for big structs") {
Zone { implicit zone: Zone =>
val structPtr = alloc[Struct.struct_bigStruct]
for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) {
Expand Down Expand Up @@ -100,7 +105,7 @@ object StructTests extends TestSuite {
}
}

'setFieldOfBigStruct - {
it("should provide field setters for big structs") {
Zone { implicit zone: Zone =>
val structPtr = alloc[Struct.struct_bigStruct]
for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.scalanative.bindgen.samples

import utest._
import org.scalatest.FunSpec
import scala.scalanative.native._

import org.scalanative.bindgen.samples.Union.implicits._

object UnionTests extends TestSuite {
val tests = Tests {
'sizeof - {
class UnionSpec extends FunSpec {
describe("union bindings") {
it("should match size of C memory layout") {
assert(Union.union_get_sizeof() == sizeof[Union.union_values])
}

'get - {
it("should provide field getters") {
Zone { implicit zone =>
val unionPtr = alloc[Union.union_values]

Expand Down Expand Up @@ -56,7 +57,7 @@ object UnionTests extends TestSuite {
}
}

'set - {
it("should provide field setters") {
Zone { implicit zone =>
val unionPtr = alloc[Union.union_values]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.scalanative.bindgen.samples

import org.scalatest.FunSpec
import scala.scalanative.native._

class VarDefineSpec extends FunSpec {
describe("variable #define bindings") {
it("should have the value of the referenced variable") {
assert(VarDefine.A == 23)
assert(VarDefine.CONST_INT == 10)
}
}
}

This file was deleted.

0 comments on commit 634c370

Please sign in to comment.