Skip to content

Commit bfe4f05

Browse files
committed
Allow cross compilation tests with Scala 2 compiler
1 parent ce831a4 commit bfe4f05

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Cross version tests (`..._c2.13.12.scala`) are not supported for Scala 2 with Scala.js.
2+
i18884

compiler/test/dotty/tools/TestSources.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ object TestSources {
2727

2828
def runFromTastyBlacklistFile: String = "compiler/test/dotc/run-from-tasty.blacklist"
2929
def runTestPicklingBlacklistFile: String = "compiler/test/dotc/run-test-pickling.blacklist"
30+
def runScalaJSBlacklistFile: String = "compiler/test/dotc/run-scala-js.blacklist"
3031
def runTestRecheckExcludesFile: String = "compiler/test/dotc/run-test-recheck.excludes"
3132
def runLazyValsAllowlistFile: String = "compiler/test/dotc/run-lazy-vals-tests.allowlist"
3233

3334

3435
def runFromTastyBlacklisted: List[String] = loadList(runFromTastyBlacklistFile)
3536
def runTestPicklingBlacklisted: List[String] = loadList(runTestPicklingBlacklistFile)
37+
def runScalaJSBlacklistFileBlacklisted: List[String] = loadList(runScalaJSBlacklistFile)
3638
def runTestRecheckExcluded: List[String] = loadList(runTestRecheckExcludesFile)
3739
def runLazyValsAllowlist: List[String] = loadList(runLazyValsAllowlistFile)
3840

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,38 @@ trait ParallelTesting extends RunnerOrchestration { self =>
610610
.run()
611611
.mkString(JFile.pathSeparator)
612612

613-
val stdlibClasspath = artifactClasspath("org.scala-lang", "scala3-library_3")
614-
val scalacClasspath = artifactClasspath("org.scala-lang", "scala3-compiler_3")
615-
616613
val pageWidth = TestConfiguration.pageWidth - 20
617-
val flags1 = flags.copy(defaultClassPath = stdlibClasspath)
618-
.withClasspath(targetDir.getPath)
619-
.and("-d", targetDir.getPath)
620-
.and("-pagewidth", pageWidth.toString)
621614

622-
val scalacCommand = Array("java", "-cp", scalacClasspath, "dotty.tools.dotc.Main")
623-
val command = scalacCommand ++ flags1.all ++ files.map(_.getAbsolutePath)
615+
val fileArgs = files.map(_.getAbsolutePath)
616+
617+
def scala2Command(): Array[String] = {
618+
assert(!flags.options.contains("-scalajs"),
619+
"Compilation tests with Scala.js on Scala 2 are not supported.\nThis test can be blacklisted in compiler/test/dotc/*-scala-js.blacklist")
620+
val stdlibClasspath = artifactClasspath("org.scala-lang", "scala-library")
621+
val scalacClasspath = artifactClasspath("org.scala-lang", "scala-compiler")
622+
val flagsArgs = flags
623+
.copy(options = Array.empty, defaultClassPath = stdlibClasspath)
624+
.withClasspath(targetDir.getPath)
625+
.and("-d", targetDir.getPath)
626+
.all
627+
val scalacCommand = Array("java", "-cp", scalacClasspath, "scala.tools.nsc.Main")
628+
scalacCommand ++ flagsArgs ++ fileArgs
629+
}
630+
631+
def scala3Command(): Array[String] = {
632+
val stdlibClasspath = artifactClasspath("org.scala-lang", "scala3-library_3")
633+
val scalacClasspath = artifactClasspath("org.scala-lang", "scala3-compiler_3")
634+
val flagsArgs = flags
635+
.copy(defaultClassPath = stdlibClasspath)
636+
.withClasspath(targetDir.getPath)
637+
.and("-d", targetDir.getPath)
638+
.and("-pagewidth", pageWidth.toString)
639+
.all
640+
val scalacCommand = Array("java", "-cp", scalacClasspath, "dotty.tools.dotc.Main")
641+
scalacCommand ++ flagsArgs ++ fileArgs
642+
}
643+
644+
val command = if compiler.startsWith("2") then scala2Command() else scala3Command()
624645
val process = Runtime.getRuntime.exec(command)
625646

626647
val reporter = mkReporter

sjs-compiler-tests/test/scala/dotty/tools/dotc/ScalaJSCompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ScalaJSCompilationTests extends ParallelTesting {
5959
@Test def runScalaJS: Unit = {
6060
implicit val testGroup: TestGroup = TestGroup("runScalaJS")
6161
aggregateTests(
62-
compileFilesInDir("tests/run", scalaJSOptions),
62+
compileFilesInDir("tests/run", scalaJSOptions, FileFilter.exclude(TestSources.runScalaJSBlacklistFileBlacklisted)),
6363
).checkRuns()
6464
}
6565
}

0 commit comments

Comments
 (0)