Skip to content

Commit

Permalink
Remove workaround for munit broken compilation error checking on Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Apr 25, 2024
1 parent 8de258a commit e72e5c6
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import munit.internal.MacroCompatScala2

trait VersionCompat {

/* Directly used compileErrors from munit.
* For reasoning, see the Scala 3 version of the file.
*/
def compileErrorsFixed(code: String): String =
macro MacroCompatScala2.compileErrorsImpl

// TODO: I wish to remove these one day

def compileErrorsScala2(code: String): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {
test(
"""should be absent by default and not allow transforming "superset" of case class to "subset" of case objects"""
) {
compileErrorsFixed("""(colors2enums.Color.Black: colors2enums.Color).transformIntoPartial[colors1enums.Color]""")
compileErrors("""(colors2enums.Color.Black: colors2enums.Color).transformIntoPartial[colors1enums.Color]""")
.check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.colors2enums.Color to io.scalaland.chimney.fixtures.colors1enums.Color",
"io.scalaland.chimney.fixtures.colors1enums.Color",
Expand Down Expand Up @@ -396,7 +396,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {
}

test("not allow transformation of of sealed hierarchies when the transformation would be ambiguous") {
val error = compileErrorsFixed(
val error = compileErrors(
"""
(shapes1enums.Shape.Triangle(shapes1enums.Point(0, 0), shapes1enums.Point(2, 2), shapes1enums.Point(2, 0)): shapes1enums.Shape)
.transformIntoPartial[shapes5enums.Shape]
Expand Down Expand Up @@ -604,7 +604,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {

test("should be disabled by default") {

compileErrorsFixed("(Foo.bar: Foo).transformIntoPartial[Bar]").check(
compileErrors("(Foo.bar: Foo).transformIntoPartial[Bar]").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand All @@ -613,7 +613,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {
"Consult https://chimney.readthedocs.io for usage examples."
)

compileErrorsFixed("(Foo.bar: Foo).intoPartial[Bar].transform").check(
compileErrors("(Foo.bar: Foo).intoPartial[Bar].transform").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand All @@ -629,7 +629,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {
def namesMatch(fromName: String, toName: String): Boolean = fromName.equalsIgnoreCase(toName)
}

compileErrorsFixed(
compileErrors(
"""(Foo.bar: Foo).intoPartial[Bar].enableCustomSubtypeNameComparison(BadNameComparison).transform"""
)
.check(
Expand All @@ -639,7 +639,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {

test("should inform user when the matcher they provided results in ambiguities") {

compileErrorsFixed(
compileErrors(
"""
(Foo.bar: Foo)
.intoPartial[BarAmbiguous]
Expand Down Expand Up @@ -682,7 +682,7 @@ class PartialTransformerEnumSpec extends ChimneySpec {
@unused implicit val config = TransformerConfiguration.default
.enableCustomSubtypeNameComparison(TransformedNamesComparison.CaseInsensitiveEquality)

compileErrorsFixed("(Foo.bar: Foo).intoPartial[Bar].disableCustomSubtypeNameComparison.transform").check(
compileErrors("(Foo.bar: Foo).intoPartial[Bar].disableCustomSubtypeNameComparison.transform").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TotalTransformerEnumSpec extends ChimneySpec {
}

test("not allow transformation of of sealed hierarchies when the transformation would be ambiguous") {
val error = compileErrorsFixed(
val error = compileErrors(
"""
(shapes1enums.Shape.Triangle(shapes1enums.Point(0, 0), shapes1enums.Point(2, 2), shapes1enums.Point(2, 0)): shapes1enums.Shape)
.transformInto[shapes5enums.Shape]
Expand Down Expand Up @@ -151,7 +151,7 @@ class TotalTransformerEnumSpec extends ChimneySpec {
test(
"""should be absent by default and not allow transforming "superset" of case class to "subset" of case objects"""
) {
compileErrorsFixed("""(colors2enums.Color.Black: colors2enums.Color).transformInto[colors1enums.Color]""").check(
compileErrors("""(colors2enums.Color.Black: colors2enums.Color).transformInto[colors1enums.Color]""").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.colors2enums.Color to io.scalaland.chimney.fixtures.colors1enums.Color",
"io.scalaland.chimney.fixtures.colors1enums.Color",
"can't transform coproduct instance io.scalaland.chimney.fixtures.colors2enums.Color.Black to io.scalaland.chimney.fixtures.colors1enums.Color",
Expand Down Expand Up @@ -317,7 +317,7 @@ class TotalTransformerEnumSpec extends ChimneySpec {

test("should be disabled by default") {

compileErrorsFixed("(Foo.bar: Foo).transformInto[Bar]").check(
compileErrors("(Foo.bar: Foo).transformInto[Bar]").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand All @@ -326,7 +326,7 @@ class TotalTransformerEnumSpec extends ChimneySpec {
"Consult https://chimney.readthedocs.io for usage examples."
)

compileErrorsFixed("(Foo.bar: Foo).into[Bar].transform").check(
compileErrors("(Foo.bar: Foo).into[Bar].transform").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand All @@ -342,15 +342,15 @@ class TotalTransformerEnumSpec extends ChimneySpec {
def namesMatch(fromName: String, toName: String): Boolean = fromName.equalsIgnoreCase(toName)
}

compileErrorsFixed("""(Foo.bar: Foo).into[Bar].enableCustomSubtypeNameComparison(BadNameComparison).transform""")
compileErrors("""(Foo.bar: Foo).into[Bar].enableCustomSubtypeNameComparison(BadNameComparison).transform""")
.check(
"Invalid TransformerNamesComparison type - only (case) objects are allowed, and only the ones defined as top-level or in top-level objects, got: io.scalaland.chimney.TotalTransformerEnumSpec.BadNameComparison!!!"
)
}

test("should inform user when the matcher they provided results in ambiguities") {

compileErrorsFixed(
compileErrors(
"""
(Foo.bar: Foo)
.into[BarAmbiguous]
Expand Down Expand Up @@ -392,7 +392,7 @@ class TotalTransformerEnumSpec extends ChimneySpec {
@unused implicit val config = TransformerConfiguration.default
.enableCustomSubtypeNameComparison(TransformedNamesComparison.CaseInsensitiveEquality)

compileErrorsFixed("(Foo.bar: Foo).into[Bar].disableCustomSubtypeNameComparison.transform").check(
compileErrors("(Foo.bar: Foo).into[Bar].disableCustomSubtypeNameComparison.transform").check(
"Chimney can't derive transformation from io.scalaland.chimney.fixtures.renames.Foo to io.scalaland.chimney.fixtures.renames.Bar",
"io.scalaland.chimney.fixtures.renames.Bar",
"derivation from bar: io.scalaland.chimney.fixtures.renames.Foo.bar to io.scalaland.chimney.fixtures.renames.Bar is not supported in Chimney!",
Expand Down
20 changes: 0 additions & 20 deletions chimney/src/test/scala-3/io/scalaland/chimney/VersionCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@ package io.scalaland.chimney

trait VersionCompat {

/* Copy/Paste from munit, with transparent keyword added.
* Without the keyword some unexpected error reports would be collected
*/
transparent inline def compileErrorsFixed(inline code: String): String = {
val errors = scala.compiletime.testing.typeCheckErrors(code)
errors
.map { error =>
val indent = " " * (error.column - 1)
val trimMessage = error.message.linesIterator
.map { line =>
if line.matches(" +") then ""
else line
}
.mkString("\n")
val separator = if error.message.contains('\n') then "\n" else " "
s"error:$separator$trimMessage\n${error.lineContent}\n$indent^"
}
.mkString("\n")
}

// TODO: I wish to remove these one day :/

transparent inline def compileErrorsScala2(inline code: String): String = ""
Expand Down
12 changes: 6 additions & 6 deletions chimney/src/test/scala/io/scalaland/chimney/IssuesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class IssuesSpec extends ChimneySpec {

test("fix for `withFieldConst`") {

compileErrorsFixed(
compileErrors(
"""
Foo1("test")
.into[Foo2]
Expand All @@ -77,7 +77,7 @@ class IssuesSpec extends ChimneySpec {

test("fix for `withFieldComputed`") {

compileErrorsFixed(
compileErrors(
"""
Foo1("test")
.into[Foo2]
Expand Down Expand Up @@ -216,7 +216,7 @@ class IssuesSpec extends ChimneySpec {
case class BarNested(num: String)
@unused case class Bar(maybeString: scala.collection.immutable.Seq[String], nested: BarNested)

compileErrorsFixed("Foo(None, FooNested(None)).into[Bar].transform")
compileErrors("Foo(None, FooNested(None)).into[Bar].transform")
.check(
"derivation from foo.maybeString: scala.Option[scala.collection.immutable.Set[java.lang.String]] to scala.collection.immutable.Seq[java.lang.String] is not supported in Chimney!",
"derivation from foo.nested.num: scala.Option[scala.Int] to java.lang.String is not supported in Chimney!"
Expand Down Expand Up @@ -278,8 +278,8 @@ class IssuesSpec extends ChimneySpec {

// These two will fail to compile as target is case class, but source type is internal.Venue,
// thus it will try to access `def name` accessor without .enableMethodAccessors flag
compileErrorsFixed("event.venue.transformInto[dto.Venue]").arePresent()
compileErrorsFixed("(venue: internal.Venue).transformInto[dto.Venue]").arePresent()
compileErrors("event.venue.transformInto[dto.Venue]").arePresent()
compileErrors("(venue: internal.Venue).transformInto[dto.Venue]").arePresent()

// When .enableMethodAccessors turned on, both should work fine
event.venue.into[dto.Venue].enableMethodAccessors.transform ==> dto.Venue("Venue Name")
Expand Down Expand Up @@ -711,7 +711,7 @@ class IssuesSpec extends ChimneySpec {
case class Something(a: String, b: Int)
}

compileErrorsFixed(
compileErrors(
"""
Proto(isSomething = true, somethingDetail = Some(Proto.SomethingDetail("hello", 1)))
.intoPartial[Domain]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class PartialTransformerCustomConstructorSpec extends ChimneySpec {
test("""not allow transformation when passed value is not a function/method""") {
import products.{Foo, Bar}

compileErrorsFixed("""Foo(3, "pi", (3.14, 3.14)).intoPartial[Bar].withConstructor(Bar(4, (5.0, 5.0))).transform""")
compileErrors("""Foo(3, "pi", (3.14, 3.14)).intoPartial[Bar].withConstructor(Bar(4, (5.0, 5.0))).transform""")
.check(
"Expected function of any arity (scala.Function0, scala.Function1, scala.Function2, ...) that returns a value of ", // difference between Scala 2 and 3
", got io.scalaland.chimney.fixtures.products.Bar"
)

compileErrorsFixed(
compileErrors(
"""Foo(3, "pi", (3.14, 3.14)).intoPartial[Bar].withConstructorPartial(partial.Result.fromValue(Bar(4, (5.0, 5.0)))).transform"""
).check(
"Expected function of any arity (scala.Function0, scala.Function1, scala.Function2, ...) that returns a value of ", // difference between Scala 2 and 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class PartialTransformerDslSeparationSpec extends ChimneySpec {

test("should not enable inlined derivation") {
// format of missing method differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").intoPartial[Bar].transform""").arePresent()
compileErrors("""Foo("test").intoPartial[Bar].transform""").arePresent()
}

test("should not enable summoning declared instances") {
@unused implicit val transformer: PartialTransformer[Foo, Bar] =
PartialTransformer.define[Foo, Bar].withFieldConst(_.baz, "test2").buildTransformer

// format of missing method differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").transformIntoPartial[Bar]""").arePresent()
compileErrors("""Foo("test").transformIntoPartial[Bar]""").arePresent()
}
}

Expand All @@ -63,7 +63,7 @@ class PartialTransformerDslSeparationSpec extends ChimneySpec {

test("should not enable automatic derivation") {
// format of missing implicit differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").transformIntoPartial[Bar]""").arePresent()
compileErrors("""Foo("test").transformIntoPartial[Bar]""").arePresent()
}

test("should enable inlined derivation") {
Expand All @@ -75,7 +75,7 @@ class PartialTransformerDslSeparationSpec extends ChimneySpec {
Transformer.define[Foo, Bar].withFieldConst(_.baz, "test2").buildTransformer

// format of missing method differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").transformIntoPartial[Bar]""").arePresent()
compileErrors("""Foo("test").transformIntoPartial[Bar]""").arePresent()
}
}

Expand All @@ -87,12 +87,12 @@ class PartialTransformerDslSeparationSpec extends ChimneySpec {

test("should not enable automatic derivation") {
// format of missing implicit differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").transformIntoPartial[Bar]""").arePresent()
compileErrors("""Foo("test").transformIntoPartial[Bar]""").arePresent()
}

test("should not enable inlined derivation") {
// format of missing method differ between 2 and 3 and we cannot rely on it
compileErrorsFixed("""Foo("test").intoPartial[Bar].transform""").arePresent()
compileErrors("""Foo("test").intoPartial[Bar].transform""").arePresent()
}

test("should enable summoning declared instances") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,13 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec {
case class TargetWithOptionAndDefault(x: String, y: Possible[Int] = Possible.Present(42))

test("should be turned off by default and not allow compiling OptionalValue fields with missing source") {
compileErrorsFixed("""Source("foo").transformIntoPartial[TargetWithOption]""").check(
compileErrors("""Source("foo").transformIntoPartial[TargetWithOption]""").check(
"Chimney can't derive transformation from io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source to io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"y: io.scalaland.chimney.TotalTransformerIntegrationsSpec.Possible[scala.Int] - no accessor named y in source type io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source",
"Consult https://chimney.readthedocs.io for usage examples."
)
compileErrorsFixed("""Source("foo").intoPartial[TargetWithOption].transform""").check(
compileErrors("""Source("foo").intoPartial[TargetWithOption].transform""").check(
"Chimney can't derive transformation from io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source to io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"y: io.scalaland.chimney.TotalTransformerIntegrationsSpec.Possible[scala.Int] - no accessor named y in source type io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source",
Expand Down Expand Up @@ -765,7 +765,7 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec {
test("should disable globally enabled .enableOptionDefaultsToNone") {
@unused implicit val config = TransformerConfiguration.default.enableOptionDefaultsToNone

compileErrorsFixed("""Source("foo").intoPartial[TargetWithOption].disableOptionDefaultsToNone.transform""").check(
compileErrors("""Source("foo").intoPartial[TargetWithOption].disableOptionDefaultsToNone.transform""").check(
"Chimney can't derive transformation from io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source to io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"io.scalaland.chimney.PartialTransformerIntegrationsSpec.TargetWithOption",
"y: io.scalaland.chimney.TotalTransformerIntegrationsSpec.Possible[scala.Int] - no accessor named y in source type io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source",
Expand Down Expand Up @@ -799,7 +799,7 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec {
@unused case class Target(a: String)

test("should fail compilation if OptionalValue unwrapping is not provided when disabled") {
compileErrorsFixed(
compileErrors(
"""Source(Possible.Present("value")).intoPartial[Target].disablePartialUnwrapsOption.transform"""
).check(
"Chimney can't derive transformation from io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source to io.scalaland.chimney.PartialTransformerIntegrationsSpec.Target",
Expand All @@ -812,7 +812,7 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec {
locally {
@unused implicit val config = TransformerConfiguration.default.disablePartialUnwrapsOption

compileErrorsFixed("""Source(Possible.Present("value")).transformIntoPartial[Target]""").check(
compileErrors("""Source(Possible.Present("value")).transformIntoPartial[Target]""").check(
"Chimney can't derive transformation from io.scalaland.chimney.PartialTransformerIntegrationsSpec.Source to io.scalaland.chimney.PartialTransformerIntegrationsSpec.Target",
"java.lang.String",
"derivation from source.a: io.scalaland.chimney.TotalTransformerIntegrationsSpec.Possible[java.lang.String] to java.lang.String is not supported in Chimney!",
Expand Down

0 comments on commit e72e5c6

Please sign in to comment.