Skip to content

Commit

Permalink
Adding tests for binary compat that can't be tested by Mima (#2509)
Browse files Browse the repository at this point in the history
* wip adding mima exception tests

* uncomment bc breaking code

* binary compat test working

* fix 2.13 build

* fix typo

* keep fixing typo
  • Loading branch information
kailuowang authored Sep 26, 2018
1 parent 8c891ee commit cc8919f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
21 changes: 21 additions & 0 deletions binCompatTest/src/main/scala/catsBC/MimaExceptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package catsBC
import cats.implicits._
import cats._, data._, cats.arrow._

object MimaExceptions {
import cats.implicits._

def isBinaryCompatible = (
Monad[OptionT[List, ?]],
cats.data.OptionT.catsDataTraverseForOptionT[List],
cats.data.Kleisli.catsDataCommutativeArrowForKleisliId,
cats.data.OptionT.catsDataMonoidKForOptionT[List],
cats.data.OptionT.catsDataMonoidForOptionT[List, Int],
cats.data.Kleisli.catsDataMonadForKleisliId[Int],
cats.data.Kleisli.catsDataCommutativeArrowForKleisli[Option],
cats.data.Kleisli.catsDataCommutativeFlatMapForKleisli[Option, Int],
cats.data.IRWST.catsDataStrongForIRWST[List, Int, Int, Int],
cats.data.OptionT.catsDataMonadErrorMonadForOptionT[List]
)

}
9 changes: 9 additions & 0 deletions binCompatTest/src/test/scala/catsBC/MimaExceptionsTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package catsBC

import org.scalatest.FunSuite

class MimaExceptionsTest extends FunSuite {
test("is binary compatible") {
MimaExceptions.isBinaryCompatible
}
}
57 changes: 43 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ lazy val docSettings = Seq(
includeFilter in Jekyll := (includeFilter in makeSite).value
)

def mimaSettings(moduleName: String) = {
def mimaPrevious(moduleName: String, scalaVer: String, ver: String): List[ModuleID] = {
import sbtrelease.Version

def semverBinCompatVersions(major: Int, minor: Int, patch: Int): Set[(Int, Int, Int)] = {
def semverBinCompatVersions(major: Int, minor: Int, patch: Int): List[(Int, Int, Int)] = {
val majorVersions: List[Int] = List(major)
val minorVersions : List[Int] =
if (major >= 1) Range(0, minor).inclusive.toList
Expand All @@ -234,30 +234,37 @@ def mimaSettings(moduleName: String) = {
min <- minorVersions
pat <- patchVersions(min)
} yield (maj, min, pat)
versions.toSet
versions.toList
}

def mimaVersions(version: String): Set[String] = {
Version(version) match {
val mimaVersions: List[String] = {
Version(ver) match {
case Some(Version(major, Seq(minor, patch), _)) =>
semverBinCompatVersions(major.toInt, minor.toInt, patch.toInt)
.map{case (maj, min, pat) => s"${maj}.${min}.${pat}"}
case _ =>
Set.empty[String]
List.empty[String]
}
}
// Safety Net For Exclusions
lazy val excludedVersions: Set[String] = Set()
lazy val excludedVersions: List[String] = List()

// Safety Net for Inclusions
lazy val extraVersions: Set[String] = Set()
lazy val extraVersions: List[String] = List()


if(priorTo2_13(scalaVer)) {
(mimaVersions ++ extraVersions)
.filterNot(excludedVersions.contains(_))
.map(v => "org.typelevel" %% moduleName % v)
} else List()

}

def mimaSettings(moduleName: String) = {

Seq(
mimaPreviousArtifacts := { if(priorTo2_13(scalaVersion.value)) {
(mimaVersions(version.value) ++ extraVersions)
.filterNot(excludedVersions.contains(_))
.map(v => "org.typelevel" %% moduleName % v)
} else Set() },
mimaPreviousArtifacts := mimaPrevious(moduleName, scalaVersion.value, version.value).toSet,

mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
Expand All @@ -278,6 +285,7 @@ def mimaSettings(moduleName: String) = {
)
}


lazy val docs = project
.enablePlugins(MicrositesPlugin)
.enablePlugins(ScalaUnidocPlugin)
Expand Down Expand Up @@ -495,6 +503,25 @@ lazy val bench = project.dependsOn(macrosJVM, coreJVM, freeJVM, lawsJVM)
))
.enablePlugins(JmhPlugin)


lazy val binCompatTest = project
.disablePlugins(CoursierPlugin)
.settings(noPublishSettings)
.settings(
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7"),
libraryDependencies ++= List(
{
if (priorTo2_13(scalaVersion.value))
mimaPrevious("cats-core", scalaVersion.value, version.value).last % Provided
else //We are not testing BC on Scala 2.13 yet.
"org.typelevel" %% "cats-core" % version.value % Provided
},
"org.typelevel" %% "cats-core" % version.value % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value) % Test
)
)


// cats-js is JS-only
lazy val js = project
.dependsOn(macrosJS, coreJS, testsJS % "test-internal -> test")
Expand Down Expand Up @@ -612,7 +639,9 @@ addCommandAlias("buildAlleycatsJVM", ";alleycatsCoreJVM/test;alleycatsLawsJVM/te

addCommandAlias("buildJVM", ";buildKernelJVM;buildCoreJVM;buildTestsJVM;buildFreeJVM;buildAlleycatsJVM")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;bench/test;mimaReportBinaryIssues;makeMicrosite")
addCommandAlias("validateBC", ";catsJVM/publishLocal;binCompatTest/test;mimaReportBinaryIssues")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;bench/test;validateBC;makeMicrosite")

addCommandAlias("validateJS", ";catsJS/compile;testsJS/test;js/test")

Expand Down

0 comments on commit cc8919f

Please sign in to comment.