Skip to content

Commit 657c1fa

Browse files
authored
Merge pull request #8 from fiadliel/add_tests
Update some logic, adds tests
2 parents d0eff9b + 88cf48f commit 657c1fa

File tree

33 files changed

+199
-10
lines changed

33 files changed

+199
-10
lines changed

build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ publishMavenStyle := false
1515
bintrayPackageLabels := Seq("sbt", "si-2712", "partial-unification", "scala")
1616

1717
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
18+
19+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
20+
21+
scriptedLaunchOpts += "-Dplugin.version=" + version.value

project/build.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
sbt.version=0.13.16
2-
1+
sbt.version=1.1.6

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
22
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
3+
4+
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

src/main/scala/PartialUnification.scala

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,52 @@ object PartialUnification extends AutoPlugin {
88
override def trigger = allRequirements
99

1010
object autoImport {
11-
val partialUnificationModule = settingKey[ModuleID]("Module to add partial unification to scala 2.10/2.11")
11+
val partialUnificationModule = settingKey[ModuleID](
12+
"Module to add partial unification to scala 2.10/2.11")
1213
}
1314

1415
import autoImport._
1516

17+
def reportError(scalaVersion: String) = {
18+
sys.error(s"scala version $scalaVersion is not supported by this plugin.")
19+
}
20+
1621
def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Resolution = {
17-
val pluginDependency = Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
22+
val pluginDependency =
23+
Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
1824
val flag = Resolution.Flag("-Ypartial-unification")
1925
val VersionNumber((major +: minor +: patch +: _), tags, _) = scalaVersion
2026

2127
(major, minor, patch, tags) match {
2228
case (2, 10, p, _) if p >= 6 => pluginDependency
23-
case (2, 11, 8, _) => pluginDependency
29+
case (2, 10, _, _) => reportError(scalaVersion)
30+
31+
case (2, 11, 8, _) => pluginDependency
2432
case (2, 11, p, _) if p >= 9 => flag
33+
case (2, 11, _, _) => reportError(scalaVersion)
34+
2535
case (2, 12, _, _) => flag
26-
case (2, 13, _, milestone +: _) if milestone == "M1" || milestone == "M2" || milestone == "M3" => flag // ignoring the M4 snapshot
36+
37+
case (2, 13, 0, milestone +: _)
38+
if milestone == "M1" || milestone == "M2" || milestone == "M3" =>
39+
flag // ignoring the M4 snapshot
40+
2741
case _ => Resolution.NothingHappens
2842
}
2943
}
3044

3145
override val projectSettings = Seq(
3246
partialUnificationModule := "com.milessabin" % "si2712fix-plugin" % "1.2.0",
33-
3447
libraryDependencies ++= {
3548
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
3649
case Resolution.Plugin(id) => Seq(id)
37-
case _ => Seq.empty
50+
case _ => Seq.empty
3851
}
3952
},
40-
4153
scalacOptions ++= {
4254
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
4355
case Resolution.Flag(flag) => Seq(flag)
44-
case _ => Seq.empty
56+
case _ => Seq.empty
4557
}
4658
}
4759
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def foo[F[_], A](fa: F[A]): String =
3+
fa.toString
4+
5+
foo { x: Int =>
6+
x * 2
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scalaVersion := "2.10.7"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addSbtPlugin(
2+
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> compile
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def foo[F[_], A](fa: F[A]): String =
3+
fa.toString
4+
5+
foo { x: Int =>
6+
x * 2
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scalaVersion := "2.11.11"

0 commit comments

Comments
 (0)