From d960bdc565539048434d0af48c8311bd1b817ef6 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Mon, 22 Apr 2024 17:10:04 -0700 Subject: [PATCH] surface (feature): Scala Native support (#3501) - Almost no change was required to support Scala Native - internal: Remove dependency to munit --- .../airframe/surface/AbstractTypeTest.scala | 6 ++-- .../airframe/surface/InnerClassTest.scala | 8 ++++-- .../surface/reflect/NamedParameterTest.scala | 7 +++-- .../surface/reflect/RuntimeSurfaceTest.scala | 4 +-- .../wvlet/airframe/surface/surface.scala | 1 - .../airframe/surface/AirSpecBridge.scala | 28 ------------------- .../airframe/surface/AliasSurfaceTest.scala | 3 +- .../wvlet/airframe/surface/CNameTest.scala | 16 ++++++----- .../wvlet/airframe/surface/EnumTest.scala | 10 ++++--- .../airframe/surface/MethodSurfaceTest.scala | 12 ++++---- .../wvlet/airframe/surface/ParamTest.scala | 12 ++++---- .../airframe/surface/QuoteParamTest.scala | 2 +- .../airframe/surface/RecordSurfaceTest.scala | 13 +++++---- .../surface/RecursiveHigherKindTypeTest.scala | 16 +++++------ .../surface/RecursiveMethodParamTest.scala | 3 +- .../surface/RecursiveSurfaceTest.scala | 14 +++++----- .../airframe/surface/RequiredParamTest.scala | 14 ++++++---- .../airframe/surface/SecretParamTest.scala | 8 ++++-- .../wvlet/airframe/surface/SurfaceSpec.scala | 5 ++-- .../wvlet/airframe/surface/SurfaceTest.scala | 12 ++++---- .../wvlet/airframe/surface/ZeroTest.scala | 2 +- build.sbt | 7 +++-- 22 files changed, 96 insertions(+), 107 deletions(-) delete mode 100644 airframe-surface/src/test/scala/wvlet/airframe/surface/AirSpecBridge.scala diff --git a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/AbstractTypeTest.scala b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/AbstractTypeTest.scala index a53ccd2e64..7861844765 100644 --- a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/AbstractTypeTest.scala +++ b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/AbstractTypeTest.scala @@ -1,6 +1,8 @@ package wvlet.airframe.surface -class AbstractTypeTest extends munit.FunSuite { +import wvlet.airspec.AirSpec + +class AbstractTypeTest extends AirSpec { trait Abst { def hello = "hello abst" @@ -14,6 +16,6 @@ class AbstractTypeTest extends munit.FunSuite { assert(s.objectFactory.isDefined) val a = s.objectFactory.get.newInstance(Seq.empty).asInstanceOf[Abst] - assertEquals(a.hello, "hello impl") + a.hello shouldBe "hello impl" } } diff --git a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/InnerClassTest.scala b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/InnerClassTest.scala index 015567066b..578c0a67f0 100644 --- a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/InnerClassTest.scala +++ b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/InnerClassTest.scala @@ -13,22 +13,24 @@ */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec + /** */ -class InnerClassTest extends munit.FunSuite { +class InnerClassTest extends AirSpec { case class A(id: Int, name: String) test("pass inner class context to Surface") { val s = Surface.of[A] val a = s.objectFactory.map { x => x.newInstance(Seq(1, "leo")) } - assertEquals(a, Some(A(1, "leo"))) + a shouldBe Some(A(1, "leo")) } test("find an inner class inside a code block") { new { val s = Surface.of[A] val a = s.objectFactory.map { x => x.newInstance(Seq(1, "leo")) } - assertEquals(a, Some(A(1, "leo"))) + a shouldBe Some(A(1, "leo")) } } } diff --git a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/NamedParameterTest.scala b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/NamedParameterTest.scala index 28dccd5f57..034a70acde 100644 --- a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/NamedParameterTest.scala +++ b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/NamedParameterTest.scala @@ -15,10 +15,11 @@ package wvlet.airframe.surface.reflect import scala.language.higherKinds import wvlet.airframe.surface.Surface +import wvlet.airspec.AirSpec /** */ -class NamedParameterTest extends munit.FunSuite { +class NamedParameterTest extends AirSpec { trait MyService[F[_]] { def hello: F[String] @@ -28,13 +29,13 @@ class NamedParameterTest extends munit.FunSuite { test("read F[_]") { val s = Surface.of[MyService[A]] - assertEquals(s.toString, "MyService[A]") + s.toString shouldBe "MyService[A]" val m = Surface.methodsOf[MyService[A]] assert(m.headOption.isDefined) val m1 = m.head // info(m1.returnType.getClass()) - assertEquals(m1.returnType.toString, "F[String]") + m1.returnType.toString shouldBe "F[String]" } } diff --git a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/RuntimeSurfaceTest.scala b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/RuntimeSurfaceTest.scala index e4d6838c0f..9c357fdd91 100644 --- a/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/RuntimeSurfaceTest.scala +++ b/airframe-surface/.jvm/src/test/scala/wvlet/airframe/surface/reflect/RuntimeSurfaceTest.scala @@ -61,11 +61,11 @@ class RuntimeSurfaceTest extends SurfaceSpec { test("resolve trait type") { val s = RuntimeSurface.of[TraitOnly] - assertEquals(s.isAlias, false) + s.isAlias shouldBe false assert(s.rawType == classOf[TraitOnly]) val m = Surface.methodsOf[TraitOnly].head - assertEquals(m.owner.isAlias, false) + m.owner.isAlias shouldBe false assert(m.owner.rawType == classOf[TraitOnly]) assert(m.findAnnotationOf[secret].isDefined) diff --git a/airframe-surface/.native/src/main/scala-3/wvlet/airframe/surface/surface.scala b/airframe-surface/.native/src/main/scala-3/wvlet/airframe/surface/surface.scala index 8964e12cbc..d2ae4089b0 100644 --- a/airframe-surface/.native/src/main/scala-3/wvlet/airframe/surface/surface.scala +++ b/airframe-surface/.native/src/main/scala-3/wvlet/airframe/surface/surface.scala @@ -17,7 +17,6 @@ import java.util.concurrent.ConcurrentHashMap import scala.collection.mutable import scala.jdk.CollectionConverters.* - val surfaceCache = new ConcurrentHashMap[String, Surface]().asScala val methodSurfaceCache = new ConcurrentHashMap[String, Seq[MethodSurface]]().asScala diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/AirSpecBridge.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/AirSpecBridge.scala deleted file mode 100644 index 38aa43e1c7..0000000000 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/AirSpecBridge.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package wvlet.airframe.surface - -/** - * Provide AirSpec-like helper - */ -trait AirSpecBridge extends munit.Assertions { - def isScalaJS: Boolean = AirSpecBridgeCompat.isScalaJS - def isScala3JVM: Boolean = AirSpecBridgeCompat.isScala3JVM - def pendingUntil(msg: String): Unit = { - assume(false, msg) - } - def pending(msg: String): Unit = { - assume(false, msg) - } -} diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/AliasSurfaceTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/AliasSurfaceTest.scala index e748cacfb9..1048cb54c0 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/AliasSurfaceTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/AliasSurfaceTest.scala @@ -14,10 +14,11 @@ package wvlet.airframe.surface import wvlet.log.LogSupport +import wvlet.airspec.AirSpec /** */ -class AliasSurfaceTest extends munit.FunSuite with LogSupport { +class AliasSurfaceTest extends AirSpec { case class Holder[A](v: A) type MyInt = Holder[Int] diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/CNameTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/CNameTest.scala index 1b5f8bc7fa..31b3064afc 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/CNameTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/CNameTest.scala @@ -13,7 +13,9 @@ */ package wvlet.airframe.surface -class CNameTest extends munit.FunSuite { +import wvlet.airspec.AirSpec + +class CNameTest extends AirSpec { test("convert to snakeCase") { assert(CName("AirframeSurface").snakeCase == "airframe_surface") assert(CName("airframe_surface").snakeCase == "airframe_surface") @@ -48,16 +50,16 @@ class CNameTest extends munit.FunSuite { test("null values") { val nullName = CName(null) - assertEquals(nullName.canonicalName, "") - assertEquals(nullName.naturalName, "") + nullName.canonicalName shouldBe "" + nullName.naturalName shouldBe "" } test("comparison") { val a = CName("Apple") val b = CName("Banana") - assertEquals(a.compareTo(b) < 0, true) - assertEquals(a, a) - assertNotEquals(a, b) - assertNotEquals(a.hashCode, b.hashCode) + a.compareTo(b) < 0 shouldBe true + a shouldBe a + a shouldNotBe b + a.hashCode shouldNotBe b.hashCode } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/EnumTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/EnumTest.scala index 51bbc23df3..9527fe6e39 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/EnumTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/EnumTest.scala @@ -13,6 +13,8 @@ */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec + /** */ object EnumTest { @@ -29,16 +31,16 @@ object EnumTest { } } -class EnumTest extends munit.FunSuite { +class EnumTest extends AirSpec { import EnumTest.* test("Find Surface.stringExtractor") { Surface.of[Color] match { case s: EnumSurface => val f = s.stringExtractor - assertEquals(f(classOf[Color], "Blue"), Some(Blue)) - assertEquals(f(classOf[Color], "Red"), Some(Red)) - assertEquals(f(classOf[Color], "White"), None) + f(classOf[Color], "Blue") shouldBe Some(Blue) + f(classOf[Color], "Red") shouldBe Some(Red) + f(classOf[Color], "White") shouldBe None case other => fail(s"EnumSurface should be used: ${other.getClass}") } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/MethodSurfaceTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/MethodSurfaceTest.scala index 293b270bfb..4a4b28e3e3 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/MethodSurfaceTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/MethodSurfaceTest.scala @@ -114,11 +114,11 @@ class MethodSurfaceTest extends SurfaceSpec { val v = h.getMethodArgDefaultValue(d) if (!isScalaJS) { // Scala.js doesn't support reading default method arguments - assertEquals(v, Some("hello")) + v shouldBe Some("hello") } val msg = m.call(d, "world") - assertEquals(msg, "world") + msg shouldBe "world" } test("find method default parameter in trait") { @@ -127,15 +127,15 @@ class MethodSurfaceTest extends SurfaceSpec { assert(m.args.headOption.isDefined) val h = m.args.head // FIXME: Fix StaticMethodParameter in CompileTimeSurfaceFactory for Scala 3 - if (!isScalaJS && !isScala3JVM) { - assertEquals(h.getDefaultValue, Some("default")) + if (!isScalaJS && !isScalaNative && !(isScala3 && isScalaJVM)) { + h.getDefaultValue shouldBe Some("default") val d = new E { override def hello(v: String = "yay"): String = v } val v = h.getMethodArgDefaultValue(d) // Scala.js doesn't support reading default method arguments - assertEquals(v, Some("yay")) + v shouldBe Some("yay") } } @@ -145,7 +145,7 @@ class MethodSurfaceTest extends SurfaceSpec { case Some(m) if m.args.size == 1 => val arg = m.args(0) val p1 = arg.surface.typeArgs(1) - assertEquals(p1.fullName, "scala.Any") + p1.fullName shouldBe "scala.Any" case _ => fail("F.mapInput method not found") } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/ParamTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/ParamTest.scala index 8de00f36c3..d62019e57d 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/ParamTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/ParamTest.scala @@ -41,7 +41,7 @@ class ParamTest extends SurfaceSpec { val s = Surface.of[ParamTest.B] val p1 = s.params(0) val v = ParamTest.B(1, 2, 3) - assertEquals(p1.get(v), 1) + p1.get(v) shouldBe 1 } test("access params through alias") { @@ -49,8 +49,8 @@ class ParamTest extends SurfaceSpec { val p1 = s.params(0) val p2 = s.params(1) val v: ParamTest.A1 = ParamTest.A(10, 20) - assertEquals(p1.get(v), 10) - assertEquals(p2.get(v), 20) + p1.get(v) shouldBe 10 + p2.get(v) shouldBe 20 } test("private field access") { @@ -62,8 +62,8 @@ class ParamTest extends SurfaceSpec { val p2 = s.params(1) val p3 = s.params(2) val v = ParamTest.B(1, 2, 3) - assertEquals(p1.get(v), 1) - assertEquals(p2.get(v), 2) - assertEquals(p3.get(v), 3) + p1.get(v) shouldBe 1 + p2.get(v) shouldBe 2 + p3.get(v) shouldBe 3 } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/QuoteParamTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/QuoteParamTest.scala index 447ed29653..fea3c3da98 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/QuoteParamTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/QuoteParamTest.scala @@ -24,6 +24,6 @@ class QuoteParamTest extends SurfaceSpec { val s = Surface.of[QP] val obj = QP("A") val p = s.params.head - assertEquals(p.get(obj), obj.`system-+=type`) + p.get(obj) shouldBe obj.`system-+=type` } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecordSurfaceTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecordSurfaceTest.scala index 037ba0df16..8068db2dbe 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecordSurfaceTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecordSurfaceTest.scala @@ -12,8 +12,9 @@ * limitations under the License. */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec -class RecordSurfaceTest extends munit.FunSuite { +class RecordSurfaceTest extends AirSpec { test("build custom surface") { val p1 = RecordParameter(0, "p1", Primitive.Int) val p2 = RecordParameter(1, "p2", Primitive.String) @@ -24,10 +25,10 @@ class RecordSurfaceTest extends munit.FunSuite { .addParam(p2) .addParam(p3) - assertEquals(s.typeArgs, Seq.empty) - assertEquals(s.params.length, 3) - assertEquals(s.params(0), p1) - assertEquals(s.params(1), p2) - assertEquals(s.params(2), p3) + s.typeArgs shouldBe Seq.empty + s.params.length shouldBe 3 + s.params(0) shouldBe p1 + s.params(1) shouldBe p2 + s.params(2) shouldBe p3 } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveHigherKindTypeTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveHigherKindTypeTest.scala index 94947041c9..229bf55b24 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveHigherKindTypeTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveHigherKindTypeTest.scala @@ -38,13 +38,13 @@ class RecursiveHigherKindTypeTest extends SurfaceSpec { test("support recursive higher kind types") { val s = Surface.of[Holder[BySkinny]] - assertEquals(s.name, "Holder[BySkinny]") - assertEquals(s.isAlias, false) - assertEquals(s.isPrimitive, false) - assertEquals(s.isOption, false) - assertEquals(s.dealias.toString, "Holder[BySkinny]") - - assertEquals(s.typeArgs(0).name, "BySkinny") - assertEquals(s.typeArgs(0).dealias.name, "MyTask[A]") + s.name shouldBe "Holder[BySkinny]" + s.isAlias shouldBe false + s.isPrimitive shouldBe false + s.isOption shouldBe false + s.dealias.toString shouldBe "Holder[BySkinny]" + + s.typeArgs(0).name shouldBe "BySkinny" + s.typeArgs(0).dealias.name shouldBe "MyTask[A]" } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveMethodParamTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveMethodParamTest.scala index 205f085ffe..ef3907f305 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveMethodParamTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveMethodParamTest.scala @@ -12,6 +12,7 @@ * limitations under the License. */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec object RecursiveMethodParamTest { case class Node(parent: Option[Node]) @@ -21,7 +22,7 @@ object RecursiveMethodParamTest { } } -class RecursiveMethodParamTest extends munit.FunSuite { +class RecursiveMethodParamTest extends AirSpec { import RecursiveMethodParamTest.* // .... diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveSurfaceTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveSurfaceTest.scala index e8ccac3cc5..b7eeab2e90 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveSurfaceTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/RecursiveSurfaceTest.scala @@ -52,16 +52,16 @@ class RecursiveSurfaceTest extends SurfaceSpec { test("support generic recursive type") { val c: Surface = Surface.of[TypedCons[String]] debug(s"TypeCons[String] ${c.getClass}") - assertEquals(c.toString, "TypedCons[String]") + c.toString shouldBe "TypedCons[String]" - assertEquals(c.params.length, 2) - assertEquals(c.params(0).surface, Primitive.Int) + c.params.length shouldBe 2 + c.params(0).surface shouldBe Primitive.Int val lazyC: Surface = c.params(1).surface debug(s"lazyC surface: ${lazyC.getClass}...") - assertEquals(lazyC.toString, "TypedCons[String]") - assertEquals(lazyC.params.length, 2) - assertEquals(lazyC.isPrimitive, false) - assertEquals(lazyC.isOption, false) + lazyC.toString shouldBe "TypedCons[String]" + lazyC.params.length shouldBe 2 + lazyC.isPrimitive shouldBe false + lazyC.isOption shouldBe false } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/RequiredParamTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/RequiredParamTest.scala index 9f6a8dcb7a..61ffb46fcf 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/RequiredParamTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/RequiredParamTest.scala @@ -13,28 +13,30 @@ */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec + case class ModelWithRequiredParam(@required id: String, name: String) { def method(a: String, @required b: Int): Unit = {} } /** */ -class RequiredParamTest extends munit.FunSuite { +class RequiredParamTest extends AirSpec { test("find required annotation") { val s = Surface.of[ModelWithRequiredParam] val p_id = s.params(0) val p_name = s.params(1) - assertEquals(p_id.isRequired, true) - assertEquals(p_name.isRequired, false) + p_id.isRequired shouldBe true + p_name.isRequired shouldBe false } test("find required method param annotation") { val ms = Surface.methodsOf[ModelWithRequiredParam] val m = ms.find(_.name == "method").get - assertEquals(m.args(0).isRequired, false) - assertEquals(m.args(1).isRequired, true) + m.args(0).isRequired shouldBe false + m.args(1).isRequired shouldBe true } case class LocalA(@required id: String, name: String) @@ -42,6 +44,6 @@ class RequiredParamTest extends munit.FunSuite { test("find required annotation from local classes") { val s = Surface.of[LocalA] val p_id = s.params.find(_.name == "id").get - assertEquals(p_id.isRequired, true) + p_id.isRequired shouldBe true } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/SecretParamTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/SecretParamTest.scala index 5c81912d67..ba74c05963 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/SecretParamTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/SecretParamTest.scala @@ -13,9 +13,11 @@ */ package wvlet.airframe.surface +import wvlet.airspec.AirSpec + /** */ -class SecretParamTest extends munit.FunSuite { +class SecretParamTest extends AirSpec { case class WithSecretParam( user: String, @@ -27,7 +29,7 @@ class SecretParamTest extends munit.FunSuite { val p_user = s.params(0) val p_password = s.params(1) - assertEquals(p_user.isSecret, false) - assertEquals(p_password.isSecret, true) + p_user.isSecret shouldBe false + p_password.isSecret shouldBe true } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceSpec.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceSpec.scala index 474ff4f144..90eb8847a1 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceSpec.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceSpec.scala @@ -17,12 +17,13 @@ package wvlet.airframe.surface import wvlet.log.LogSupport import scala.language.implicitConversions +import wvlet.airspec.AirSpec -trait SurfaceSpec extends munit.FunSuite with LogSupport with AirSpecBridge { +trait SurfaceSpec extends AirSpec { protected def check(body: => Surface, expectedName: String): Surface = { val surface = body debug(s"[${surface.getClass.getSimpleName}] $surface, ${surface.fullName}") - assertEquals(surface.toString, expectedName) + surface.toString shouldBe expectedName surface } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceTest.scala index 7cdd553a87..f1343b7784 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/SurfaceTest.scala @@ -78,7 +78,7 @@ class SurfaceTest extends SurfaceSpec { } test("find primitive Surfaces") { - assertEquals(Primitive(classOf[Int]), Primitive.Int) + Primitive(classOf[Int]) shouldBe Primitive.Int } test("resolve surface from class") { @@ -188,9 +188,9 @@ class SurfaceTest extends SurfaceSpec { } test("resolve generic abstract type") { - assertEquals(Surface.of[D[_]].typeArgs, Seq(ExistentialType)) + Surface.of[D[_]].typeArgs shouldBe Seq(ExistentialType) val d = check(Surface.of[D[_]], "D[_]") - assertEquals(d.typeArgs.length, 1) + d.typeArgs.length shouldBe 1 check(Surface.of[Map[_, _]], "Map[_,_]") } @@ -237,7 +237,7 @@ class SurfaceTest extends SurfaceSpec { val s = Surface.of[F] assert(s.objectFactory.isDefined) val f = s.objectFactory.map(_.newInstance(Seq(100))) - assertEquals(f, Some(F(100))) + f shouldBe Some(F(100)) } test("bigint") { @@ -247,7 +247,7 @@ class SurfaceTest extends SurfaceSpec { test("resolve types args of Map[String, Any]") { val s = Surface.of[Map[String, Any]] - assertEquals(s.typeArgs(0).fullName, "java.lang.String") - assertEquals(s.typeArgs(1).fullName, "scala.Any") + s.typeArgs(0).fullName shouldBe "java.lang.String" + s.typeArgs(1).fullName shouldBe "scala.Any" } } diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/ZeroTest.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/ZeroTest.scala index b662f0bdeb..948119bfe6 100644 --- a/airframe-surface/src/test/scala/wvlet/airframe/surface/ZeroTest.scala +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/ZeroTest.scala @@ -29,7 +29,7 @@ class ZeroTest extends SurfaceSpec { case s: ArraySurface => pendingUntil("array comparison") case _ => - assertEquals(z, v) + z shouldBe v } z } diff --git a/build.sbt b/build.sbt index f06e7b3336..3f7c51637d 100644 --- a/build.sbt +++ b/build.sbt @@ -265,7 +265,8 @@ lazy val jsProjects: Seq[ProjectReference] = Seq( ) lazy val nativeProjects: Seq[ProjectReference] = Seq( - log.native + log.native, + surface.native ) // Integration test projects @@ -477,7 +478,7 @@ val surfaceDependencies = { scalaVersion: String => } lazy val surface = - crossProject(JVMPlatform, JSPlatform) + crossProject(JVMPlatform, JSPlatform, NativePlatform) .crossType(CrossType.Pure) .in(file("airframe-surface")) .settings(buildSettings) @@ -485,7 +486,6 @@ lazy val surface = name := "airframe-surface", description := "A library for extracting object structure surface", // TODO: This is a temporary solution. Use AirSpec after Scala 3 support of Surface is completed - libraryDependencies += "org.scalameta" %%% "munit" % "0.7.29" % Test, libraryDependencies ++= surfaceDependencies(scalaVersion.value) ) .jvmSettings( @@ -493,6 +493,7 @@ lazy val surface = libraryDependencies += "javax.annotation" % "javax.annotation-api" % JAVAX_ANNOTATION_API_VERSION % Test ) .jsSettings(jsBuildSettings) + .nativeSettings(nativeBuildSettings) .dependsOn(log) lazy val canvas =