Skip to content

Commit 15436b3

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

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
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: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,31 @@ 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")
613+
val useScala2 = compiler.startsWith("2")
615614

616-
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)
615+
val stdlibClasspath =
616+
val moduleName = if useScala2 then "scala-library" else "scala3-library_3"
617+
artifactClasspath("org.scala-lang", moduleName)
618+
val scalacClasspath =
619+
val moduleName = if useScala2 then "scala-compiler" else "scala3-compiler_3"
620+
artifactClasspath("org.scala-lang", moduleName)
621621

622-
val scalacCommand = Array("java", "-cp", scalacClasspath, "dotty.tools.dotc.Main")
623-
val command = scalacCommand ++ flags1.all ++ files.map(_.getAbsolutePath)
622+
val pageWidth = TestConfiguration.pageWidth - 20
623+
val testArgs =
624+
if useScala2 then
625+
// We disregard all flags for simplicity to avoid passing unsupported flags to Scala 2.
626+
// TODO: support Scala.js with Scala 2 compiler
627+
flags.classpath ++ Array("-d", targetDir.getPath)
628+
else
629+
flags.copy(defaultClassPath = stdlibClasspath)
630+
.withClasspath(targetDir.getPath)
631+
.and("-d", targetDir.getPath)
632+
.and("-pagewidth", pageWidth.toString)
633+
.all
634+
635+
val main = if useScala2 then "scala.tools.nsc.Main" else "dotty.tools.dotc.Main"
636+
val scalacCommand = Array("java", "-cp", scalacClasspath, main)
637+
val command = scalacCommand ++ testArgs ++ files.map(_.getAbsolutePath)
624638
val process = Runtime.getRuntime.exec(command)
625639

626640
val reporter = mkReporter

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import scala.language.unsafeNulls
44

55
import java.io.{File => JFile}
66

7+
import dotty.tools.io.File.pathSeparator
8+
79
final case class TestFlags(
810
defaultClassPath: String,
911
runClassPath: String, // class path that is used when running `run` tests (not compiling)
@@ -25,7 +27,9 @@ final case class TestFlags(
2527
def withJavacOnlyOptions(flags: String*): TestFlags =
2628
TestFlags(defaultClassPath, runClassPath, options, javacOptions ++ flags)
2729

28-
def all: Array[String] = Array("-classpath", defaultClassPath) ++ options
30+
def all: Array[String] = classpath ++ options
31+
32+
def classpath: Array[String] = Array("-classpath", s"$defaultClassPath$pathSeparator$runClassPath")
2933

3034
def withoutLanguageFeatures: TestFlags = copy(options = withoutLanguageFeaturesOptions)
3135

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)