Skip to content

Commit

Permalink
Update Scala 2 ShadedGeneratedSmithySpec to avoid using MUnit's macros
Browse files Browse the repository at this point in the history
The MUnit `compileErrors` macro seems to follow a different compilation
cadence than other code, meaning the tests are more likely to
erroneously fail. This seems to work better.
  • Loading branch information
bpholt committed Oct 10, 2024
1 parent 3c0950e commit cbca3be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
8 changes: 8 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ lazy val `secure-config` = (project in file("."))
"org.http4s" %% "http4s-ember-client" % "0.23.28" % Test,
)
},
libraryDependencies ++= {
(scalaBinaryVersion.value) match {
case "2.13" =>
Seq("org.scala-lang" % "scala-compiler" % scalaVersion.value % Test)
case _ =>
Nil
}
},
smithy4sAwsSpecs ++= Seq(AWS.kms),
scalacOptions += "-Wconf:src=src_managed/.*:s",
Compile / smithy4sModelTransformers += "com.dwolla.config.smithy.ShadeNamespace",
Expand Down
29 changes: 19 additions & 10 deletions src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package bincompat

import cats.syntax.all.*
import munit.*

import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe.*
import scala.tools.reflect.ToolBox

class ShadedGeneratedSmithySpec extends FunSuite {
private val toolbox = currentMirror.mkToolBox()

private def typecheck(input: String): Either[Throwable, Tree] =
for {
parsed <- Either.catchNonFatal(toolbox.parse(input))
typechecked <- Either.catchNonFatal(toolbox.typecheck(parsed))
} yield typechecked

test("we don't have access to the generated KMS objects in their original package") {
assertNoDiff(compileErrors("""com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")"""),
"""error: object amazonaws is not a member of package com
|com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")
| ^
|""".stripMargin)
val typedchecked = typecheck("""com.amazonaws.kms.KMS.id""")

assertEquals(typedchecked.leftMap(_.getMessage), Left("reflective typecheck has failed: object id is not a member of package com.amazonaws.kms.KMS"))
}

test("we don't have access to the generated KMS objects in the shaded package") {
assertNoDiff(compileErrors("""assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))"""),
"""error: value KMS in package kms cannot be accessed as a member of object com.dwolla.config.smithy_shaded.com.amazonaws.kms.package from class ShadedGeneratedSmithySpec in package bincompat
|assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))
| ^
|""".stripMargin)
val typedchecked = typecheck("""com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id""")

assertEquals(typedchecked.leftMap(_.getMessage), Left("reflective typecheck has failed: value KMS in package kms cannot be accessed as a member of object com.dwolla.config.smithy_shaded.com.amazonaws.kms.package from package <root>"))
}
}

0 comments on commit cbca3be

Please sign in to comment.