-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define & document binary compatibility strategy
- Loading branch information
Showing
5 changed files
with
214 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
scalafix-cli/src/main/scala/scalafix/internal/util/Compatibility.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package scalafix.internal.util | ||
|
||
sealed trait Compatibility | ||
|
||
object Compatibility { | ||
|
||
case object Compatible extends Compatibility | ||
case object Unknown extends Compatibility | ||
case object Incompatible extends Compatibility | ||
|
||
private val Snapshot = """.*-SNAPSHOT""".r | ||
private val PVP = """^([0-9]+)\.([0-9]+)\.([0-9]+)""".r // A.B.C | ||
|
||
def pvp(builtAgainst: String, runWith: String): Compatibility = { | ||
(builtAgainst, runWith) match { | ||
case (Snapshot(), _) => Unknown | ||
case (_, Snapshot()) => Unknown | ||
case (PVP(buildA, _, _), PVP(runA, _, _)) if buildA.toInt > runA.toInt => | ||
Incompatible | ||
case (PVP(buildA, _, _), PVP(runA, _, _)) if buildA.toInt < runA.toInt => | ||
Unknown | ||
// --- A match given the cases above | ||
case (PVP(_, buildB, _), PVP(_, runB, _)) if buildB.toInt > runB.toInt => | ||
Incompatible | ||
case (PVP(_, buildB, _), PVP(_, runB, _)) if buildB.toInt < runB.toInt => | ||
Unknown | ||
// --- A.B match given the cases above | ||
case (PVP(_, _, buildC), PVP(_, _, runC)) if buildC.toInt > runC.toInt => | ||
Incompatible | ||
case _ => Compatible | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
scalafix-tests/unit/src/test/scala/scalafix/tests/cli/CompatibilitySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package scalafix.tests.cli | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
import scalafix.internal.util.Compatibility | ||
import scalafix.internal.util.Compatibility._ | ||
|
||
class CompatibilitySuite extends AnyFunSuite { | ||
|
||
test("PVP compatible if full match") { | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.9.34", | ||
runWith = "0.9.34" | ||
) == Compatible | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "1.2.3", | ||
runWith = "1.2.3" | ||
) == Compatible | ||
) | ||
} | ||
|
||
// to avoid struggles when testing nightlies | ||
test("PVP unknown if run or build is a snapshot") { | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.9.34+52-a83785c4-SNAPSHOT", | ||
runWith = "1.2.3" | ||
) == Unknown | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.9.34", | ||
runWith = "1.2.3+1-bfe5ccd4-SNAPSHOT" | ||
) == Unknown | ||
) | ||
} | ||
|
||
// no binary breaking change in 0.9.x, 0.10.x, ... | ||
test("PVP compatible if run is greater by minor") { | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.10.0", | ||
runWith = "0.10.20" | ||
) == Compatible | ||
) | ||
} | ||
|
||
// might be false positive/negative tree matches (AST updates) | ||
test("PVP unknown if run is greater by major") { | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.9.38", | ||
runWith = "0.10.2" | ||
) == Unknown | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.9.38", | ||
runWith = "1.0.0" | ||
) == Unknown | ||
) | ||
} | ||
|
||
// build might reference classes unknown to run | ||
test("PVP incompatible if build is greater") { | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "2.0.0", | ||
runWith = "1.1.1" | ||
) == Incompatible | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "1.4.7", | ||
runWith = "1.4.6" | ||
) == Incompatible | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "1.4.7", | ||
runWith = "1.2.8" | ||
) == Incompatible | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.10.8", | ||
runWith = "0.9.16" | ||
) == Incompatible | ||
) | ||
assert( | ||
Compatibility.pvp( | ||
builtAgainst = "0.10.17", | ||
runWith = "0.10.4" | ||
) == Incompatible | ||
) | ||
} | ||
} |