Skip to content

Commit fa6054b

Browse files
committed
Make tests depend on environment variables for classpath jars
sbt adds the correct jars to classpath and the tests depend on `packageAll` which creates these. When using something else however, these together with `sbt-interfaces` do not get propagated from the build. To remedy this and make the testing a bit more flexible, we now take these from `sys.props` instead, see `tests/dotty/Jars.scala`. If the props aren't defined we fall back to the ones default to sbt.
1 parent e043954 commit fa6054b

File tree

7 files changed

+61
-25
lines changed

7 files changed

+61
-25
lines changed

compiler/test/dotc/tests.scala

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotc
22

3+
import dotty.Jars
34
import dotty.tools.dotc.CompilerTest
45
import org.junit.{Before, Test}
56

@@ -32,18 +33,28 @@ class tests extends CompilerTest {
3233
)
3334

3435
val classPath = {
35-
val paths = List(
36-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar",
37-
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar",
38-
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
39-
).map { p =>
36+
val paths = Jars.dottyTestDeps map { p =>
4037
val file = new JFile(p)
4138
assert(
4239
file.exists,
43-
s"""File "$p" couldn't be found. Run `packageAll` from build tool before testing"""
40+
s"""|File "$p" couldn't be found. Run `packageAll` from build tool before
41+
|testing.
42+
|
43+
|If running without sbt, test paths need to be setup environment variables:
44+
|
45+
| - DOTTY_LIBRARY
46+
| - DOTTY_COMPILER
47+
| - DOTTY_INTERFACES
48+
| - DOTTY_EXTRAS
49+
|
50+
|Where these all contain locations, except extras which is a comma
51+
|separated list of jars.
52+
|
53+
|When compiling with eclipse, you need the sbt-interfaces jar, but
54+
|it in extras."""
4455
)
4556
file.getAbsolutePath
46-
}.mkString(":")
57+
} mkString (":")
4758

4859
List("-classpath", paths)
4960
}
@@ -338,10 +349,16 @@ class tests extends CompilerTest {
338349
@Test def tasty_tests = compileDir(testsDir, "tasty", testPickling)
339350

340351
@Test def tasty_bootstrap = {
352+
val f = new JFile(getClass.getProtectionDomain.getCodeSource.getLocation.getPath)
353+
println(f)
354+
println(System.getProperty("java.class.path"))
355+
356+
341357
val opt = List("-priorityclasspath", defaultOutputDir, "-Ylog-classpath")
342358
// first compile dotty
343359
compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict"))(allowDeepSubtypes)
344360

361+
345362
compileDir(dottyDir, "tools", opt)
346363
compileDir(toolsDir, "dotc", opt)
347364
compileDir(dotcDir, "ast", opt)

compiler/test/dotty/Jars.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty
2+
3+
/** Jars used when compiling test, defaults to sbt locations */
4+
object Jars {
5+
val dottyLib: String = sys.env.get("DOTTY_LIB") getOrElse {
6+
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
7+
}
8+
9+
val dottyCompiler: String = sys.env.get("DOTTY_COMPILER") getOrElse {
10+
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar"
11+
}
12+
13+
val dottyInterfaces: String = sys.env.get("DOTTY_INTERFACE") getOrElse {
14+
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
15+
}
16+
17+
val dottyExtras: List[String] = sys.env.get("DOTTY_EXTRAS")
18+
.map(_.split(",").toList).getOrElse(Nil)
19+
20+
val dottyTestDeps: List[String] =
21+
dottyLib :: dottyCompiler :: dottyInterfaces :: dottyExtras
22+
}

compiler/test/dotty/tools/DottyTest.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ class DottyTest extends ContextEscapeDetection{
2323
import base.settings._
2424
val ctx = base.initialCtx.fresh
2525
ctx.setSetting(ctx.settings.encoding, "UTF8")
26-
ctx.setSetting(
27-
ctx.settings.classpath,
28-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
29-
)
26+
ctx.setSetting(ctx.settings.classpath, Jars.dottyLib)
3027
// when classpath is changed in ctx, we need to re-initialize to get the
3128
// correct classpath from PathResolver
3229
base.initialize()(ctx)

compiler/test/dotty/tools/ShowClassTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23

34
import dotc.core._
45
import dotc.core.Contexts._
@@ -18,8 +19,7 @@ class ShowClassTests extends DottyTest {
1819
ctx.setSetting(ctx.settings.encoding, "UTF8")
1920
ctx.setSetting(
2021
ctx.settings.classpath,
21-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" +
22-
":../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
22+
Jars.dottyLib + ":" + Jars.dottyInterfaces
2323
)
2424
base.initialize()(ctx)
2525
ctx

compiler/test/dotty/tools/dotc/EntryPointsTest.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23
package dotc
34

45
import org.junit.Test
@@ -20,9 +21,9 @@ class EntryPointsTest {
2021
private val sources =
2122
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
2223
private val dottyInterfaces =
23-
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
24+
new java.io.File(Jars.dottyInterfaces).getPath
2425
private val dottyLibrary =
25-
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath
26+
new java.io.File(Jars.dottyLib).getPath
2627
private val args =
2728
sources ++
2829
List("-d", "../out/") ++

compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty
2+
package tools.dotc
23

34
import org.junit.Test
45
import org.junit.Assert._
@@ -21,9 +22,9 @@ class InterfaceEntryPointTest {
2122
val sources =
2223
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
2324
val dottyInterfaces =
24-
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
25+
new java.io.File(Jars.dottyInterfaces).getPath
2526
val dottyLibrary =
26-
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath
27+
new java.io.File(Jars.dottyLib).getPath
2728

2829
val args =
2930
sources ++

compiler/test/dotty/tools/dotc/repl/TestREPL.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty
2+
package tools.dotc
23
package repl
34

45
import core.Contexts.Context
@@ -23,10 +24,7 @@ class TestREPL(script: String) extends REPL {
2324
override def context(ctx: Context) = {
2425
val fresh = ctx.fresh
2526
fresh.setSetting(ctx.settings.color, "never")
26-
fresh.setSetting(
27-
ctx.settings.classpath,
28-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
29-
)
27+
fresh.setSetting(ctx.settings.classpath, Jars.dottyLib)
3028
fresh.initialize()(fresh)
3129
fresh
3230
}

0 commit comments

Comments
 (0)