Skip to content

Commit

Permalink
Merge pull request #8 from fiadliel/add_tests
Browse files Browse the repository at this point in the history
Update some logic, adds tests
  • Loading branch information
fiadliel authored Jul 11, 2018
2 parents d0eff9b + 88cf48f commit 657c1fa
Show file tree
Hide file tree
Showing 33 changed files with 199 additions and 10 deletions.
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ publishMavenStyle := false
bintrayPackageLabels := Seq("sbt", "si-2712", "partial-unification", "scala")

licenses += ("MIT", url("http://opensource.org/licenses/MIT"))

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"

scriptedLaunchOpts += "-Dplugin.version=" + version.value
3 changes: 1 addition & 2 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sbt.version=0.13.16

sbt.version=1.1.6
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
28 changes: 20 additions & 8 deletions src/main/scala/PartialUnification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,52 @@ object PartialUnification extends AutoPlugin {
override def trigger = allRequirements

object autoImport {
val partialUnificationModule = settingKey[ModuleID]("Module to add partial unification to scala 2.10/2.11")
val partialUnificationModule = settingKey[ModuleID](
"Module to add partial unification to scala 2.10/2.11")
}

import autoImport._

def reportError(scalaVersion: String) = {
sys.error(s"scala version $scalaVersion is not supported by this plugin.")
}

def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Resolution = {
val pluginDependency = Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
val pluginDependency =
Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
val flag = Resolution.Flag("-Ypartial-unification")
val VersionNumber((major +: minor +: patch +: _), tags, _) = scalaVersion

(major, minor, patch, tags) match {
case (2, 10, p, _) if p >= 6 => pluginDependency
case (2, 11, 8, _) => pluginDependency
case (2, 10, _, _) => reportError(scalaVersion)

case (2, 11, 8, _) => pluginDependency
case (2, 11, p, _) if p >= 9 => flag
case (2, 11, _, _) => reportError(scalaVersion)

case (2, 12, _, _) => flag
case (2, 13, _, milestone +: _) if milestone == "M1" || milestone == "M2" || milestone == "M3" => flag // ignoring the M4 snapshot

case (2, 13, 0, milestone +: _)
if milestone == "M1" || milestone == "M2" || milestone == "M3" =>
flag // ignoring the M4 snapshot

case _ => Resolution.NothingHappens
}
}

override val projectSettings = Seq(
partialUnificationModule := "com.milessabin" % "si2712fix-plugin" % "1.2.0",

libraryDependencies ++= {
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
case Resolution.Plugin(id) => Seq(id)
case _ => Seq.empty
case _ => Seq.empty
}
},

scalacOptions ++= {
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
case Resolution.Flag(flag) => Seq(flag)
case _ => Seq.empty
case _ => Seq.empty
}
}
)
Expand Down
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_10_7/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_10_7/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.10.7"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_10_7/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_11_11/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_11_11/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.11.11"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_11_11/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_11_8/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_11_8/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.11.8"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_11_8/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_12_6/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_12_6/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.12.6"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_12_6/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M3/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M3/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.13.0-M3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M3/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M4/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M4/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "2.13.0-M4"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/2_13_0_M4/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
def foo[F[_], A](fa: F[A]): String =
fa.toString

foo { x: Int =>
x * 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := "0.9.0-RC1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
addSbtPlugin(
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.2")
1 change: 1 addition & 0 deletions src/sbt-test/sbt-partial-unification/dotty_0_9_0_RC1/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
86 changes: 86 additions & 0 deletions src/test/scala/PartialUnificationSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.lyranthe.sbt

import org.lyranthe.sbt.PartialUnification.Resolution
import org.scalatest.{Assertion, FlatSpec, Matchers}
import sbt._

class PartialUnificationSpec extends FlatSpec with Matchers {

val partialUnificationPlugin: ModuleID =
"com.milessabin" % "si2712fix-plugin" % "1.2.0"

def pluginOrFlag(scalaVersion: String): PartialUnification.Resolution =
PartialUnification.pluginOrFlag(scalaVersion, partialUnificationPlugin)

def shouldFail(scalaVersion: String): Assertion = {
a[RuntimeException] shouldBe thrownBy(pluginOrFlag(scalaVersion))
}

def shouldReturnPlugin(scalaVersion: String): Assertion = {
pluginOrFlag(scalaVersion) shouldBe a[Resolution.Plugin]
}

def shouldReturnFlag(scalaVersion: String): Assertion = {
pluginOrFlag(scalaVersion) shouldBe a[Resolution.Flag]
}

def shouldDoNothing(scalaVersion: String): Assertion = {
pluginOrFlag(scalaVersion) shouldBe a[Resolution.NothingHappens.type]
}

"Scala version" should "not match 2.10.0" in {
shouldFail("2.10.0")
}

it should "choose plugin 2.10.6" in {
shouldReturnPlugin("2.10.6")
}

it should "choose plugin for 2.10.7" in {
shouldReturnPlugin("2.10.7")
}

it should "not match 2.11.7" in {
shouldFail("2.11.7")
}

it should "choose plugin for 2.11.8" in {
shouldReturnPlugin("2.11.8")
}

it should "choose flag for 2.11.9" in {
shouldReturnFlag("2.11.9")
}

it should "choose flag for 2.12.0" in {
shouldReturnFlag("2.12.0")
}

it should "choose flag for 2.13.0-M1" in {
shouldReturnFlag("2.13.0-M1")
}

it should "choose flag for 2.13.0-M2" in {
shouldReturnFlag("2.13.0-M2")
}

it should "choose flag for 2.13.0-M3" in {
shouldReturnFlag("2.13.0-M3")
}

it should "do nothing for 2.13.0-M4" in {
shouldDoNothing("2.13.0-M4")
}

it should "do nothing for 2.13.0" in {
shouldDoNothing("2.13.0")
}

it should "do nothing for 2.13.1-M1" in {
shouldDoNothing("2.13.1-M1")
}

it should "do nothing for 3.0.0" in {
shouldDoNothing("3.0.0")
}
}

0 comments on commit 657c1fa

Please sign in to comment.