Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak noncompilation tests and add MiMa exclusions #98

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,32 @@ 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",
Compile / smithy4sInternalDependenciesAsJars += (`smithy4s-preprocessors` / Compile / packageBin).value,
Compile / smithy4sSmithyLibrary := false,
Compile / scalafix / unmanagedSources := (Compile / sources).value,
scalafixOnCompile := true,
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core.*

// exclusions in this package should be safe since everything in there should be package private
val shadedPackage = "com.dwolla.config.smithy_shaded.com.amazonaws.kms"

Seq(
ProblemFilters.exclude[FinalMethodProblem](s"$shadedPackage.KMSOperation#Transformed.transform"),
ProblemFilters.exclude[FinalMethodProblem](s"$shadedPackage.KMSOperation#reified.transform"),
)
}
)
.enablePlugins(
Smithy4sCodegenPlugin,
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>"))
}
}