Skip to content

Commit d63b63f

Browse files
committed
Avoid hardcoded "2.10" in tests.
This allows us to cross build against 2.10.x and 2.11.x.
1 parent 232a0bb commit d63b63f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/test/scala/scala/async/TreeInterrogation.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TreeInterrogation {
1515
@Test
1616
def `a minimal set of vals are lifted to vars`() {
1717
val cm = reflect.runtime.currentMirror
18-
val tb = mkToolbox("-cp target/scala-2.10/classes")
18+
val tb = mkToolbox(s"-cp ${toolboxClasspath}")
1919
val tree = tb.parse(
2020
"""| import _root_.scala.async.AsyncId._
2121
| async {
@@ -52,7 +52,7 @@ class TreeInterrogation {
5252
&& !dd.symbol.asTerm.isAccessor && !dd.symbol.asTerm.isSetter => dd.name
5353
}
5454
}.flatten
55-
defDefs.map(_.decoded.trim).toSet mustBe (Set("foo$1", "apply", "resume$async", "<init>"))
55+
defDefs.map(_.decoded.trim).toSet mustBe (Set("foo$1", "apply", "resume", "<init>"))
5656
}
5757
}
5858

@@ -68,7 +68,7 @@ object TreeInterrogation extends App {
6868

6969
withDebug {
7070
val cm = reflect.runtime.currentMirror
71-
val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:flatten")
71+
val tb = mkToolbox("-cp ${toolboxClasspath} -Xprint:flatten")
7272
import scala.async.Async._
7373
val tree = tb.parse(
7474
""" import _root_.scala.async.AsyncId.{async, await}

src/test/scala/scala/async/package.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,22 @@ package object async {
4242
m.mkToolBox(options = compileOptions)
4343
}
4444

45-
def expectError(errorSnippet: String, compileOptions: String = "", baseCompileOptions: String = "-cp target/scala-2.10/classes")(code: String) {
45+
def scalaBinaryVersion: String = {
46+
val Pattern = """(\d+\.\d+)\..*""".r
47+
scala.util.Properties.versionNumberString match {
48+
case Pattern(v) => v
49+
case _ => ""
50+
}
51+
}
52+
53+
def toolboxClasspath = {
54+
val f = new java.io.File(s"target/scala-${scalaBinaryVersion}/classes")
55+
if (!f.exists) sys.error(s"output directory ${f.getAbsolutePath} does not exist.")
56+
f.getAbsolutePath
57+
}
58+
59+
def expectError(errorSnippet: String, compileOptions: String = "",
60+
baseCompileOptions: String = s"-cp ${toolboxClasspath}")(code: String) {
4661
intercept[ToolBoxError] {
4762
eval(code, compileOptions + " " + baseCompileOptions)
4863
}.getMessage mustContain errorSnippet

0 commit comments

Comments
 (0)