Skip to content

Commit 634c370

Browse files
authored
Replace utest with ScalaTest (#183)
1 parent 379a010 commit 634c370

File tree

8 files changed

+60
-57
lines changed

8 files changed

+60
-57
lines changed

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ lazy val samples = nativeProject("samples")
106106
.in(file("tests/samples"))
107107
.settings(
108108
publish / skip := true,
109-
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.3" % Test,
110-
testFrameworks += new TestFramework("utest.runner.Framework"),
109+
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test,
111110
compileTask("bindgentests", baseDirectory)
112111
)
113112

tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumTests.scala renamed to tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumSpec.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.scalanative.bindgen.samples
22

3-
import utest._
3+
import org.scalatest.FunSpec
44
import scalanative.native._
55

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

12-
'check_BIG_NEG_A - {
12+
it("should handle large negative values") {
1313
assert(
1414
Enum.check_BIG_NEG_A(Enum.enum_bigNegativeValues.BIG_NEG_A) == c"OK")
1515
}

tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternTests.scala renamed to tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternSpec.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package org.scalanative.bindgen.samples
22

3-
import utest._
3+
import org.scalatest.FunSpec
44
import scalanative.native._
55

6-
object ExternTests extends TestSuite {
7-
val tests = Tests {
8-
'forty_two - {
6+
class ExternSpec extends FunSpec {
7+
describe("extern variable bindings") {
8+
it("should bind to C variable") {
99
assert(Extern.forty_two == 42)
10-
}
11-
12-
'mode - {
1310
assert(Extern.mode == Extern.enum_mode.USER)
1411
}
1512

16-
'semver - {
13+
it("should bind to C struct variable") {
1714
import Extern.implicits._
1815
assert(
1916
Extern.semver.major == 1 && Extern.semver.minor == 2 && Extern.semver.patch == 3)

tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionTest.scala renamed to tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionSpec.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
package org.scalanative.bindgen.samples
22

3-
import utest._
3+
import org.scalatest.FunSpec
44
import scalanative.native._
55

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

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

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

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

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

30-
'variadic_args - {
30+
it("should bind to function with variadic args") {
3131
Zone { implicit z =>
3232
val result =
3333
Function.variadic_args(0.2, toCString("0123"), 1, 10, 100, 1000)

tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructTests.scala renamed to tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructSpec.scala

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.scalanative.bindgen.samples
22

3-
import utest._
4-
import scala.scalanative.native._
3+
import org.scalatest.FunSpec
4+
import scalanative.native._
5+
56
import org.scalanative.bindgen.samples.Struct.implicits._
67

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

18-
'constructor - {
19+
it("should provide constructors") {
1920
Zone { implicit Zone =>
21+
val pointNoValue = Struct.struct_point()
22+
assert(pointNoValue.x == 0)
23+
assert(pointNoValue.y == 0)
24+
2025
val point = Struct.struct_point(1, 2)
2126
assert(point.x == 1)
2227
assert(point.y == 2)
2328
}
2429
}
2530

26-
'bigStructSize - {
27-
assert(Struct.getBigStructSize() == sizeof[Struct.struct_bigStruct])
28-
}
29-
30-
'getFieldsOfInnerStruct - {
31+
it("should provided field getters for inner structs") {
3132
Zone { implicit zone =>
3233
val points = Struct.struct_points()
3334
Struct.setPoints(points, 1, 2, 3, 4)
@@ -38,7 +39,7 @@ object StructTests extends TestSuite {
3839
}
3940
}
4041

41-
'setFieldsOfInnerStruct - {
42+
it("should provided field setters for inner structs") {
4243
Zone { implicit zone =>
4344
val points = Struct.struct_points()
4445
points.p1.x = 1
@@ -52,7 +53,7 @@ object StructTests extends TestSuite {
5253
}
5354
}
5455

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

74-
'getFieldOfBigStruct - {
75+
it("should match size of C memory layout for big structs") {
76+
assert(Struct.getBigStructSize() == sizeof[Struct.struct_bigStruct])
77+
}
78+
79+
it("should provide field getters for big structs") {
7580
Zone { implicit zone: Zone =>
7681
val structPtr = alloc[Struct.struct_bigStruct]
7782
for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) {
@@ -100,7 +105,7 @@ object StructTests extends TestSuite {
100105
}
101106
}
102107

103-
'setFieldOfBigStruct - {
108+
it("should provide field setters for big structs") {
104109
Zone { implicit zone: Zone =>
105110
val structPtr = alloc[Struct.struct_bigStruct]
106111
for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) {

tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionTests.scala renamed to tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionSpec.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package org.scalanative.bindgen.samples
22

3-
import utest._
3+
import org.scalatest.FunSpec
44
import scala.scalanative.native._
5+
56
import org.scalanative.bindgen.samples.Union.implicits._
67

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

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

@@ -56,7 +57,7 @@ object UnionTests extends TestSuite {
5657
}
5758
}
5859

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.scalanative.bindgen.samples
2+
3+
import org.scalatest.FunSpec
4+
import scala.scalanative.native._
5+
6+
class VarDefineSpec extends FunSpec {
7+
describe("variable #define bindings") {
8+
it("should have the value of the referenced variable") {
9+
assert(VarDefine.A == 23)
10+
assert(VarDefine.CONST_INT == 10)
11+
}
12+
}
13+
}

tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineTests.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)