From 2943b54f2721e94c163c100cea328ca528b08eaa Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 19 Jun 2021 15:25:52 +0000 Subject: [PATCH] Start migrating tests --- .../main/scala/algebra/laws/BaseLaws.scala | 2 + .../scala/algebra/laws/CheckSupport.scala | 1 + .../scala/algebra/laws/DeMorganLaws.scala | 7 ++-- .../main/scala/algebra/laws/GroupLaws.scala | 2 + .../scala/algebra/laws/IsSerializable.scala | 41 ------------------- .../main/scala/algebra/laws/LatticeLaws.scala | 2 + .../main/scala/algebra/laws/LogicLaws.scala | 6 ++- .../main/scala/algebra/laws/OrderLaws.scala | 2 + .../main/scala/algebra/laws/RingLaws.scala | 3 ++ .../src/main/scala/algebra/laws/Rules.scala | 10 ++--- build.sbt | 12 +++++- 11 files changed, 33 insertions(+), 55 deletions(-) delete mode 100644 algebra-laws/shared/src/main/scala/algebra/laws/IsSerializable.scala diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/BaseLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/BaseLaws.scala index 59920b9663..11b2c89a3a 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/BaseLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/BaseLaws.scala @@ -6,6 +6,7 @@ import org.typelevel.discipline.Laws import org.scalacheck.{Arbitrary, Prop} +@deprecated("No replacement", since = "2.7.0") object BaseLaws { def apply[A: Eq: Arbitrary]: BaseLaws[A] = new BaseLaws[A] { def Equ = Eq[A] @@ -13,6 +14,7 @@ object BaseLaws { } } +@deprecated("No replacement", since = "2.7.0") trait BaseLaws[A] extends Laws { implicit def Equ: Eq[A] diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/CheckSupport.scala b/algebra-laws/shared/src/main/scala/algebra/laws/CheckSupport.scala index 7024334f54..6f95634f97 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/CheckSupport.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/CheckSupport.scala @@ -8,4 +8,5 @@ package algebra.laws * (Since algebra-instances has no dependencies, its types can't * define Arbitrary instances in companions.) */ +@deprecated("No replacement", since = "2.7.0") object CheckSupport {} diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/DeMorganLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/DeMorganLaws.scala index f99d86ff2b..cd75fd8092 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/DeMorganLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/DeMorganLaws.scala @@ -6,6 +6,7 @@ import org.scalacheck.{Arbitrary, Prop} import org.scalacheck.Prop._ import org.typelevel.discipline.Laws +@deprecated("Laws moved to LogicLaws", since = "2.7.0") object DeMorganLaws { def apply[A: Eq: Arbitrary: LatticeLaws] = new DeMorganLaws[A] { def Equ = Eq[A] @@ -13,10 +14,8 @@ object DeMorganLaws { def LL = implicitly[LatticeLaws[A]] } } -/* TODO: - * This is separated for LogicLaws for binary compatibility reasons. - * Merge with LogicLaws when possible. - */ + +@deprecated("Laws moved to LogicLaws", since = "2.7.0") trait DeMorganLaws[A] extends Laws { implicit def Equ: Eq[A] diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/GroupLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/GroupLaws.scala index 65c2fb8d7d..14fac2e575 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/GroupLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/GroupLaws.scala @@ -8,6 +8,7 @@ import org.typelevel.discipline.Laws import org.scalacheck.{Arbitrary, Prop} import org.scalacheck.Prop._ +@deprecated("Provided by cats.kernel.laws", since = "2.7.0") object GroupLaws { def apply[A: Eq: Arbitrary]: GroupLaws[A] = new GroupLaws[A] { def Equ = Eq[A] @@ -15,6 +16,7 @@ object GroupLaws { } } +@deprecated("Provided by cats.kernel.laws", since = "2.7.0") trait GroupLaws[A] extends Laws { implicit def Equ: Eq[A] diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/IsSerializable.scala b/algebra-laws/shared/src/main/scala/algebra/laws/IsSerializable.scala deleted file mode 100644 index 58e48b5a8f..0000000000 --- a/algebra-laws/shared/src/main/scala/algebra/laws/IsSerializable.scala +++ /dev/null @@ -1,41 +0,0 @@ -package algebra.laws - -import algebra.laws.platform.Platform -import org.scalacheck.Prop -import org.scalacheck.Prop._ -import scala.util.control.NonFatal -import scala.util.DynamicVariable - -/** - * Object with a dynamic variable that allows users to skip the - * serialization tests for certain instances. - */ -private[laws] object IsSerializable { - val runTests = new DynamicVariable[Boolean](true) - def apply(): Boolean = Platform.isJvm && runTests.value - - def testSerialization[M](m: M): Prop.Result = - if (Platform.isJvm) { - import java.io._ - val baos = new ByteArrayOutputStream() - val oos = new ObjectOutputStream(baos) - var ois: ObjectInputStream = null // scalastyle:ignore null - try { - oos.writeObject(m) - oos.close() - val bais = new ByteArrayInputStream(baos.toByteArray()) - ois = new ObjectInputStream(bais) - ois.readObject() // just ensure we can read it back - ois.close() - Result(status = Proof) - } catch { - case NonFatal(t) => - Result(status = Exception(t)) - } finally { - oos.close() - if (ois != null) ois.close() // scalastyle:ignore null - } - } else { - Result(status = Proof) - } -} diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/LatticeLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/LatticeLaws.scala index fe790ba647..76212e1733 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/LatticeLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/LatticeLaws.scala @@ -5,6 +5,7 @@ import algebra.lattice._ import org.scalacheck.{Arbitrary, Prop} import org.scalacheck.Prop._ +import scala.annotation.nowarn object LatticeLaws { def apply[A: Eq: Arbitrary] = new LatticeLaws[A] { @@ -13,6 +14,7 @@ object LatticeLaws { } } +@nowarn("msg=deprecated") trait LatticeLaws[A] extends GroupLaws[A] { implicit def Equ: Eq[A] diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/LogicLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/LogicLaws.scala index cfb5c5cadd..7b42fe3ff7 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/LogicLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/LogicLaws.scala @@ -5,6 +5,7 @@ import algebra.lattice.{Bool, GenBool, Heyting} import org.scalacheck.{Arbitrary, Prop} import org.scalacheck.Prop._ +import scala.annotation.nowarn object LogicLaws { def apply[A: Eq: Arbitrary] = new LogicLaws[A] { @@ -13,7 +14,10 @@ object LogicLaws { } } -trait LogicLaws[A] extends LatticeLaws[A] { +@nowarn("msg=deprecated") +trait LogicLaws[A] extends LatticeLaws[A] with DeMorganLaws[A] { + + final def LL: LatticeLaws[A] = this def heyting(implicit A: Heyting[A]) = new LogicProperties( name = "heyting", diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/OrderLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/OrderLaws.scala index ad86191c4c..d9db4cda92 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/OrderLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/OrderLaws.scala @@ -9,6 +9,7 @@ import org.scalacheck.Prop._ import cats.kernel.instances.all._ +@deprecated("Provided by cats.kernel.laws", since = "2.7.0") object OrderLaws { def apply[A: Eq: Arbitrary: Cogen]: OrderLaws[A] = new OrderLaws[A] { @@ -18,6 +19,7 @@ object OrderLaws { } } +@deprecated("Provided by cats.kernel.laws", since = "2.7.0") trait OrderLaws[A] extends Laws { implicit def Equ: Eq[A] diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/RingLaws.scala b/algebra-laws/shared/src/main/scala/algebra/laws/RingLaws.scala index 635f72cee2..22df657e10 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/RingLaws.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/RingLaws.scala @@ -10,6 +10,7 @@ import org.typelevel.discipline.Predicate import org.scalacheck.{Arbitrary, Prop} import org.scalacheck.Arbitrary._ import org.scalacheck.Prop._ +import scala.annotation.nowarn object RingLaws { def apply[A: Eq: Arbitrary: AdditiveMonoid]: RingLaws[A] = @@ -20,6 +21,7 @@ object RingLaws { def withPred[A](pred0: Predicate[A])(implicit eqv: Eq[A], arb: Arbitrary[A]): RingLaws[A] = new RingLaws[A] { def Arb = arb def pred = pred0 + @nowarn("msg=deprecated") val nonZeroLaws = new GroupLaws[A] { def Arb = Arbitrary(arbitrary[A](arb).filter(pred)) def Equ = eqv @@ -27,6 +29,7 @@ object RingLaws { } } +@nowarn("msg=deprecated") trait RingLaws[A] extends GroupLaws[A] { self => // must be a val (stable identifier) diff --git a/algebra-laws/shared/src/main/scala/algebra/laws/Rules.scala b/algebra-laws/shared/src/main/scala/algebra/laws/Rules.scala index 4bfdf56d45..32a62bbc9e 100644 --- a/algebra-laws/shared/src/main/scala/algebra/laws/Rules.scala +++ b/algebra-laws/shared/src/main/scala/algebra/laws/Rules.scala @@ -4,6 +4,7 @@ import cats.kernel._ import org.scalacheck.Prop._ import org.scalacheck.{Arbitrary, Prop} import cats.kernel.instances.boolean._ +import cats.kernel.laws.discipline.SerializableTests object Rules { @@ -92,12 +93,7 @@ object Rules { (m(a(x, y), z) ?== a(m(x, z), m(y, z))) } - // ugly platform-specific code follows - + @deprecated("Provided by cats.kernel.laws", since = "2.7.0") def serializable[M](m: M): (String, Prop) = - "serializable" -> (if (IsSerializable()) { - Prop(_ => Result(status = Proof)) - } else { - Prop(_ => IsSerializable.testSerialization(m)) - }) + SerializableTests.serializable[M](m).props.head } diff --git a/build.sbt b/build.sbt index dcb93da1dc..7c5085249c 100644 --- a/build.sbt +++ b/build.sbt @@ -504,6 +504,10 @@ def mimaSettings(moduleName: String, includeCats1: Boolean = true) = exclude[MissingClassProblem]("cats.syntax.EqOps$"), exclude[MissingClassProblem]("cats.syntax.EqOps$mcF$sp"), exclude[MissingClassProblem]("cats.syntax.EqOps$mcI$sp") + ) ++ // https://github.com/typelevel/cats/pull/3918 + Seq( + exclude[MissingClassProblem]("algebra.laws.IsSerializable"), + exclude[MissingClassProblem]("algebra.laws.IsSerializable$") ) } ) @@ -705,8 +709,12 @@ lazy val algebraLaws = crossProject(JSPlatform, JVMPlatform, NativePlatform) .settings(testingDependencies) .settings(Test / scalacOptions := (Test / scalacOptions).value.filter(_ != "-Xfatal-warnings")) .jsSettings(commonJsSettings) - .jvmSettings(commonJvmSettings) - .dependsOn(kernel, algebra) + .jvmSettings( + commonJvmSettings ++ mimaSettings("algebra-laws") ++ Seq( + mimaPreviousArtifacts := Set("org.typelevel" %% "algebra-laws" % "2.2.3") + ) + ) + .dependsOn(kernelLaws, algebra) .nativeSettings(commonNativeSettings) lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)