Skip to content

Commit 0969aa8

Browse files
committed
Simplify classpath shenanigans
1 parent bd12473 commit 0969aa8

File tree

7 files changed

+27
-69
lines changed

7 files changed

+27
-69
lines changed

compiler/test/dotty/Properties.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ object Properties {
6363
/** dotty-compiler jar */
6464
def dottyCompiler: String = sys.props("dotty.tests.classes.dottyCompiler")
6565

66-
/** dotty-repl jar */
67-
def dottyRepl: String = sys.props("dotty.tests.classes.dottyRepl")
68-
6966
/** dotty-staging jar */
7067
def dottyStaging: String = sys.props("dotty.tests.classes.dottyStaging")
7168

@@ -96,15 +93,6 @@ object Properties {
9693
/** jline-reader jar */
9794
def jlineReader: String = sys.props("dotty.tests.classes.jlineReader")
9895

99-
/** pprint jar */
100-
def pprint: String = sys.props("dotty.tests.classes.pprint")
101-
102-
/** fansi jar */
103-
def fansi: String = sys.props("dotty.tests.classes.fansi")
104-
105-
/** fansi jar */
106-
def sourcecode: String = sys.props("dotty.tests.classes.sourcecode")
107-
10896
/** scalajs-javalib jar */
10997
def scalaJSJavalib: String = sys.props("dotty.tests.classes.scalaJSJavalib")
11098

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object TestConfiguration {
3131

3232
val basicClasspath = mkClasspath(List(Properties.scalaLibrary))
3333

34-
val withCompilerClasspath = mkClasspath(List(
34+
lazy val withCompilerClasspath = mkClasspath(List(
3535
Properties.scalaLibrary,
3636
Properties.scalaAsm,
3737
Properties.compilerInterface,
@@ -52,19 +52,6 @@ object TestConfiguration {
5252
Properties.scalaJSLibrary,
5353
))
5454

55-
lazy val replClassPath =
56-
withCompilerClasspath + File.pathSeparator + mkClasspath(List(
57-
Properties.dottyRepl,
58-
Properties.jlineTerminal,
59-
Properties.jlineReader,
60-
Properties.fansi,
61-
Properties.pprint,
62-
Properties.sourcecode
63-
))
64-
65-
lazy val replWithStagingClasspath =
66-
replClassPath + File.pathSeparator + mkClasspath(List(Properties.dottyStaging))
67-
6855
def mkClasspath(classpaths: List[String]): String =
6956
classpaths.map({ p =>
7057
val file = new java.io.File(p)
@@ -80,10 +67,8 @@ object TestConfiguration {
8067
val noYcheckOptions = TestFlags(basicClasspath, noYcheckCommonOptions)
8168
val bestEffortBaselineOptions = TestFlags(basicClasspath, noCheckOptions)
8269
val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions)
83-
val withCompilerOptions =
70+
lazy val withCompilerOptions =
8471
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
85-
lazy val withReplOptions =
86-
defaultOptions.withRunClasspath(replClassPath)
8772
lazy val withStagingOptions =
8873
defaultOptions.withClasspath(withStagingClasspath).withRunClasspath(withStagingClasspath)
8974
lazy val withTastyInspectorOptions =
@@ -98,7 +83,7 @@ object TestConfiguration {
9883
"-Yprint-pos",
9984
"-Yprint-pos-syms"
10085
)
101-
val picklingWithCompilerOptions =
86+
lazy val picklingWithCompilerOptions =
10287
picklingOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
10388

10489
val explicitNullsOptions = defaultOptions `and` "-Yexplicit-nulls"

project/Build.scala

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,35 +1027,8 @@ object Build {
10271027
),
10281028
// Configure to use the non-bootstrapped compiler
10291029
bootstrappedScalaInstanceSettings,
1030-
Test / javaOptions ++= {
1031-
val log = streams.value.log
1032-
val managedSrcDir = {
1033-
// Populate the directory
1034-
(Compile / managedSources).value
1035-
1036-
(Compile / sourceManaged).value
1037-
}
1038-
val externalDeps = (ThisProject / Runtime / externalDependencyClasspath).value
1039-
Seq(
1040-
s"-Ddotty.tests.dottyCompilerManagedSources=${managedSrcDir}",
1041-
s"-Ddotty.tests.classes.dottyInterfaces=${(`scala3-interfaces` / Compile / packageBin).value}",
1042-
s"-Ddotty.tests.classes.dottyCompiler=${(`scala3-compiler-bootstrapped` / Compile / packageBin).value}",
1043-
s"-Ddotty.tests.classes.dottyRepl=${(ThisProject / Compile / packageBin).value}",
1044-
s"-Ddotty.tests.classes.tastyCore=${(`tasty-core-bootstrapped` / Compile / packageBin).value}",
1045-
s"-Ddotty.tests.classes.compilerInterface=${findArtifactPath(externalDeps, "compiler-interface")}",
1046-
s"-Ddotty.tests.classes.scalaLibrary=${(`scala-library-bootstrapped` / Compile / packageBin).value}",
1047-
s"-Ddotty.tests.classes.scalaJSScalalib=${(`scala-library-sjs` / Compile / packageBin).value}",
1048-
s"-Ddotty.tests.classes.scalaAsm=${findArtifactPath(externalDeps, "scala-asm")}",
1049-
s"-Ddotty.tests.classes.jlineTerminal=${findArtifactPath(externalDeps, "jline-terminal")}",
1050-
s"-Ddotty.tests.classes.jlineReader=${findArtifactPath(externalDeps, "jline-reader")}",
1051-
s"-Ddotty.tests.classes.dottyStaging=${(LocalProject("scala3-staging") / Compile / packageBin).value}",
1052-
s"-Ddotty.tests.classes.dottyTastyInspector=${(LocalProject("scala3-tasty-inspector") / Compile / packageBin).value}",
1053-
s"-Ddotty.tests.classes.pprint=${findArtifactPath(externalDeps, "pprint_3")}",
1054-
s"-Ddotty.tests.classes.fansi=${findArtifactPath(externalDeps, "fansi_3")}",
1055-
s"-Ddotty.tests.classes.sourcecode=${findArtifactPath(externalDeps, "sourcecode_3")}",
1056-
s"-Ddotty.tools.dotc.semanticdb.test=${(ThisBuild / baseDirectory).value/"tests"/"semanticdb"}",
1057-
)
1058-
},
1030+
// Needed for the JSR223 tests which are "run" tests
1031+
Test / javaOptions += s"-Ddotty.tests.classes.scalaLibrary=${(`scala-library-bootstrapped` / Compile / packageBin).value}",
10591032
run / fork := true,
10601033
excludeDependencies += "org.scala-lang" %% "scala3-library",
10611034
excludeDependencies += "org.scala-lang" % "scala-library",

repl/test/dotty/tools/repl/JSR223Tests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ final class JSR223Tests:
1414

1515
@Test def filetests: Unit =
1616
given TestGroup = TestGroup("runWithCompiler")
17-
compileFilesInDir("test-resources/jsr223", TestConfiguration.withReplOptions)
17+
// We want this test to run with the REPL inside the classpath so it can access the script engine,
18+
// and by default Vulpix only gives a restricted class path, so pass the full one
19+
compileFilesInDir("test-resources/jsr223", TestConfiguration.defaultOptions.withRunClasspath(System.getProperty("java.class.path")))
1820
.checkRuns()
1921
end filetests
2022

repl/test/dotty/tools/repl/ReplTest.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
123123
}
124124

125125
object ReplTest:
126-
val commonOptions = Array("-color:never", "-pagewidth", "80", "-Ydebug")
127-
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.replClassPath)
128-
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.replWithStagingClasspath)
126+
// Because we test REPL features like completion,
127+
// we don't want other test stuff to get in the way,
128+
// e.g., "Pred" should complete to "Predef" and not "PredefTest" just because some dependency has a test named like that
129+
private val classpath =
130+
System.getProperty("java.class.path")
131+
.split(JFile.pathSeparator)
132+
.filter(!_.contains("test-classes"))
133+
.mkString(JFile.pathSeparator)
134+
135+
def createOptions(extraClasspath: String*): Array[String] =
136+
Array("-color:never", "-pagewidth", "80", "-Ydebug",
137+
"-classpath", classpath + JFile.pathSeparator + extraClasspath.mkString(JFile.pathSeparator))
138+
139+
val defaultOptions: Array[String] = createOptions()

repl/test/dotty/tools/repl/ShadowingTests.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import vulpix.{TestConfiguration, TestFlags}
2525
* and running scripted REPL tests with them on the claspath.
2626
*/
2727
object ShadowingTests:
28-
def classpath = TestConfiguration.replClassPath + File.pathSeparator + shadowDir
29-
def options = ReplTest.commonOptions ++ Array("-classpath", classpath)
28+
// The directory on the classpath containing artifacts to be shadowed
29+
private var dir: Path = null
30+
3031
def shadowDir = dir.toAbsolutePath.toString
32+
def options = ReplTest.createOptions(shadowDir)
3133

3234
def createSubDir(name: String): Path =
3335
val subdir = dir.resolve(name)
@@ -36,9 +38,6 @@ object ShadowingTests:
3638
assert(Files.isDirectory(subdir), s"failed to create shadowed subdirectory $subdir")
3739
subdir
3840

39-
// The directory on the classpath containing artifacts to be shadowed
40-
private var dir: Path = null
41-
4241
@BeforeClass def setupDir: Unit =
4342
dir = Files.createTempDirectory("repl-shadow")
4443

staging/test/scala/quoted/staging/repl/StagingScriptedReplTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.junit.Test
88
import org.junit.experimental.categories.Category
99

1010
/** Runs all tests contained in `staging/test-resources/repl-staging` */
11-
class StagingScriptedReplTests extends ReplTest(ReplTest.withStagingOptions) {
11+
class StagingScriptedReplTests extends ReplTest {
1212

1313
@Category(Array(classOf[BootstrappedOnlyTests]))
1414
@Test def replStagingTests = scripts("/repl-staging").foreach(testFile)

0 commit comments

Comments
 (0)