Skip to content

Commit

Permalink
Fix implicit error message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Sep 27, 2024
1 parent 7616aed commit 9d459fc
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions core/src/main/scala-3/cats/derived/DerivedEmpty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ object DerivedEmpty:
given product[A: ProductInstancesOf[Empty]]: DerivedEmpty[A] =
Empty(ProductInstances.construct([a] => (A: Empty[a]) => A.empty))

@nowarn("id=E197")
inline given coproduct[A: CoproductGeneric]: DerivedEmpty[A] =
Empty(CoproductGeneric.withOnly[DerivedEmpty.Or, A]([a <: A] => (A: DerivedEmpty.Or[a]) => A.unify.empty))
1 change: 1 addition & 0 deletions core/src/main/scala-3/cats/derived/DerivedEmptyK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object DerivedEmptyK:
given product[F[_]: ProductInstancesOf[EmptyK]]: DerivedEmptyK[F] = new EmptyK[F]:
def empty[A]: F[A] = ProductInstances.construct([f[_]] => (F: EmptyK[f]) => F.empty[A])

@nowarn("id=E197")
inline given coproduct[F[_]: CoproductGeneric]: DerivedEmptyK[F] =
CoproductGeneric.withOnly[DerivedEmptyK.Or, EmptyK[F]]:
[f[x] <: F[x]] => (F: DerivedEmptyK.Or[f]) => F.unify.asInstanceOf[EmptyK[F]]
10 changes: 5 additions & 5 deletions core/src/test/scala-3/cats/derived/EmptySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class EmptySuite extends KittensSuite:
locally:
import auto.empty.given
validate("auto.empty")
testNoInstance("Empty", "IList[Int]")
testNoInstance("Empty", "Snoc[Int]")
testNoInstance("Empty", "Rgb")
testNoGiven("Empty[IList[Int]]", "alleycats.Empty")
testNoGiven("Empty[Snoc[Int]]", "alleycats.Empty")
testNoGiven("Empty[Rgb]", "alleycats.Empty")

locally:
import semiInstances.given
Expand All @@ -58,8 +58,8 @@ class EmptySuite extends KittensSuite:
testNoInstance("strict.semiauto.empty", "Rgb")
testNoInstance("strict.semiauto.empty", "Top")
test("No strict.semiauto.empty for IList[Int] or Snoc[Int]"):
assertNoInstance(compileErrors("given Empty[IList[Int]] = strict.semiauto.empty"))
assertNoInstance(compileErrors("given Empty[Snoc[Int]] = strict.semiauto.empty"))
testNoGiven("given Empty[IList[Int]] = strict.semiauto.empty", "alleycats.Empty")
testNoGiven("given Empty[Snoc[Int]] = strict.semiauto.empty", "alleycats.Empty")

locally:
import derivedInstances.*
Expand Down
11 changes: 6 additions & 5 deletions core/src/test/scala-3/cats/derived/KittensSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ object KittensSuite:
given [A <: Product](using mirror: Mirror.ProductOf[A], via: Cogen[mirror.MirroredElemTypes]): Cogen[A] =
via.contramap(Tuple.fromProductTyped)

def assertNoInstance(errors: String): Unit =
val message = "No given instance of type"
assert(errors.contains(message), s"$errors did not contain $message")
inline def testNoInstance(inline tc: String, inline target: String): Unit =
val tcName = tc.drop(tc.lastIndexOf('.') + 1).capitalize
testNoGiven(tc + "[" + target + "]", s"Could not derive $tcName for")

inline def testNoInstance(inline tc: String, target: String): Unit =
test(s"No $tc for $target")(assertNoInstance(compileErrors(tc + "[" + target + "]")))
inline def testNoGiven(inline code: String, message: String): Unit =
val errors = compileErrors(code)
test(s"No given $code")(assert(errors.contains(message), s"$errors did not contain $message"))
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cats.derived

import cats.{Eq, NonEmptyTraverse, Traverse}
import cats.{NonEmptyTraverse, Traverse}
import cats.data.{NonEmptyList, OneAnd}
import cats.derived.Derived.<<<
import cats.laws.discipline.*
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala-3/cats/derived/PureSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class PureSuite extends KittensSuite:
locally:
import auto.pure.given
validate("auto.pure")
testNoInstance("Pure", "IList")
testNoInstance("Pure", "Snoc")
testNoGiven("Pure[IList]", "No given instance of type alleycats.Pure")
testNoGiven("Pure[Snoc]", "No given instance of type alleycats.Pure")

locally:
import semiInstances.given
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala-3/cats/derived/SemigroupSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cats.derived

import cats.{Eq, Semigroup}
import cats.Semigroup
import cats.kernel.laws.discipline.*
import org.scalacheck.Arbitrary

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala-3/cats/derived/TraverseSuite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats.derived

import cats.derived.Derived.<<<
import cats.{Eq, Traverse}
import cats.Traverse
import cats.laws.discipline.*
import shapeless3.deriving.Const

Expand Down

0 comments on commit 9d459fc

Please sign in to comment.