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"
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.8"
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.12.6"
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.13.0-M3"
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.13.0-M4"
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 := "0.9.0-RC1"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
addSbtPlugin(
2+
"org.lyranthe.sbt" % "partial-unification" % sys.props("plugin.version"))
3+
4+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.2")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> compile
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.lyranthe.sbt
2+
3+
import org.lyranthe.sbt.PartialUnification.Resolution
4+
import org.scalatest.{Assertion, FlatSpec, Matchers}
5+
import sbt._
6+
7+
class PartialUnificationSpec extends FlatSpec with Matchers {
8+
9+
val partialUnificationPlugin: ModuleID =
10+
"com.milessabin" % "si2712fix-plugin" % "1.2.0"
11+
12+
def pluginOrFlag(scalaVersion: String): PartialUnification.Resolution =
13+
PartialUnification.pluginOrFlag(scalaVersion, partialUnificationPlugin)
14+
15+
def shouldFail(scalaVersion: String): Assertion = {
16+
a[RuntimeException] shouldBe thrownBy(pluginOrFlag(scalaVersion))
17+
}
18+
19+
def shouldReturnPlugin(scalaVersion: String): Assertion = {
20+
pluginOrFlag(scalaVersion) shouldBe a[Resolution.Plugin]
21+
}
22+
23+
def shouldReturnFlag(scalaVersion: String): Assertion = {
24+
pluginOrFlag(scalaVersion) shouldBe a[Resolution.Flag]
25+
}
26+
27+
def shouldDoNothing(scalaVersion: String): Assertion = {
28+
pluginOrFlag(scalaVersion) shouldBe a[Resolution.NothingHappens.type]
29+
}
30+
31+
"Scala version" should "not match 2.10.0" in {
32+
shouldFail("2.10.0")
33+
}
34+
35+
it should "choose plugin 2.10.6" in {
36+
shouldReturnPlugin("2.10.6")
37+
}
38+
39+
it should "choose plugin for 2.10.7" in {
40+
shouldReturnPlugin("2.10.7")
41+
}
42+
43+
it should "not match 2.11.7" in {
44+
shouldFail("2.11.7")
45+
}
46+
47+
it should "choose plugin for 2.11.8" in {
48+
shouldReturnPlugin("2.11.8")
49+
}
50+
51+
it should "choose flag for 2.11.9" in {
52+
shouldReturnFlag("2.11.9")
53+
}
54+
55+
it should "choose flag for 2.12.0" in {
56+
shouldReturnFlag("2.12.0")
57+
}
58+
59+
it should "choose flag for 2.13.0-M1" in {
60+
shouldReturnFlag("2.13.0-M1")
61+
}
62+
63+
it should "choose flag for 2.13.0-M2" in {
64+
shouldReturnFlag("2.13.0-M2")
65+
}
66+
67+
it should "choose flag for 2.13.0-M3" in {
68+
shouldReturnFlag("2.13.0-M3")
69+
}
70+
71+
it should "do nothing for 2.13.0-M4" in {
72+
shouldDoNothing("2.13.0-M4")
73+
}
74+
75+
it should "do nothing for 2.13.0" in {
76+
shouldDoNothing("2.13.0")
77+
}
78+
79+
it should "do nothing for 2.13.1-M1" in {
80+
shouldDoNothing("2.13.1-M1")
81+
}
82+
83+
it should "do nothing for 3.0.0" in {
84+
shouldDoNothing("3.0.0")
85+
}
86+
}

0 commit comments

Comments
 (0)