Skip to content

Commit 4f0b070

Browse files
committed
Add clear separation between flags and classpath in tests
1 parent 1f3c305 commit 4f0b070

File tree

9 files changed

+66
-80
lines changed

9 files changed

+66
-80
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class ScalaSettings extends Settings.SettingGroup {
102102
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
103103
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
104104
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
105-
val YRunClasspath = PathSetting("-YRunClasspath", "Specify where to find user class files while executing run tests.", defaultClasspath)
106105

107106
/** Area-specific debug output */
108107
val Yexplainlowlevel = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

compiler/test/dotc/comptest.scala

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

3-
import dotty.tools.vulpix.ParallelTesting
3+
import dotty.tools.vulpix.{ParallelTesting, TestFlags}
44

55
import scala.concurrent.duration._
66

@@ -26,9 +26,6 @@ object comptest extends ParallelTesting {
2626
dotcDir + "tools/dotc/core/Types.scala",
2727
dotcDir + "tools/dotc/ast/Trees.scala"
2828
),
29-
Array(
30-
"-Ylog:frontend",
31-
"-Xprompt"
32-
)
29+
TestFlags("", Array("-Ylog:frontend", "-Xprompt"))
3330
)
3431
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import java.util.stream.{ Stream => JStream }
1010
import scala.collection.JavaConverters._
1111
import scala.util.matching.Regex
1212
import scala.concurrent.duration._
13-
14-
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
13+
import vulpix._
1514
import dotty.tools.io.JFile
1615

1716

@@ -41,7 +40,7 @@ class CompilationTests extends ParallelTesting {
4140
compileDir("../compiler/src/dotty/tools/dotc/typer", defaultOptions) +
4241
compileDir("../compiler/src/dotty/tools/dotc/util", defaultOptions) +
4342
compileDir("../compiler/src/dotty/tools/io", defaultOptions) +
44-
compileDir("../compiler/src/dotty/tools/dotc/core", noCheckOptions ++ classPath) +
43+
compileDir("../compiler/src/dotty/tools/dotc/core", TestFlags(classPath, noCheckOptions)) +
4544
compileFile("../tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
4645
compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
4746
compileFile("../tests/pos-special/t8146a.scala", allowDeepSubtypes) +
@@ -223,14 +222,13 @@ class CompilationTests extends ParallelTesting {
223222
* version of Dotty
224223
*/
225224
@Test def tastyBootstrap: Unit = {
226-
val opt = Array(
227-
"-classpath",
225+
val opt = TestFlags(
228226
// compile with bootstrapped library on cp:
229227
defaultOutputDir + "lib/src/:" +
230228
// as well as bootstrapped compiler:
231229
defaultOutputDir + "dotty1/dotty/:" +
232230
Jars.dottyInterfaces,
233-
"-Ycheck-reentrant"
231+
Array("-Ycheck-reentrant")
234232
)
235233

236234
def lib =

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.nio.file.{Files, Path, Paths}
77

88
import org.junit.{AfterClass, Test}
99
import org.junit.Assert._
10-
import vulpix.{ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration}
10+
import vulpix._
1111

1212
import scala.concurrent.duration._
1313
import scala.collection.JavaConverters._
@@ -38,17 +38,17 @@ class LinkOptimiseTests extends ParallelTesting {
3838
}.keepOutput.checkCompile()
3939

4040
// Setup class paths
41-
def mkLinkClassPath(libPath: String) =
42-
mkClassPath(libPath :: Jars.dottyTestDeps) ++ mkClassPath(Jars.dottyTestDeps, "-YRunClasspath")
43-
val strawmanClassPath = mkLinkClassPath(defaultOutputDir + "strawmanLibrary/main/")
44-
val customLibClassPath = mkLinkClassPath(defaultOutputDir + "linkCustomLib/custom-lib")
41+
def mkLinkClassFlags(libPath: String) =
42+
TestFlags(mkClassPath(libPath :: Jars.dottyTestDeps), mkClassPath(Jars.dottyTestDeps), basicDefaultOptions :+ "-Xlink-optimise")
43+
val strawmanClassPath = mkLinkClassFlags(defaultOutputDir + "strawmanLibrary/main/")
44+
val customLibClassFlags = mkLinkClassFlags(defaultOutputDir + "linkCustomLib/custom-lib")
4545

4646
// Link tests
4747
val linkDir = "../tests/link"
4848
val linkStramanDir = linkDir + "/strawman"
4949
val linkCustomLibDir = linkDir + "/on-custom-lib"
50-
def linkStrawmanTest = compileFilesInDir(linkStramanDir, basicLinkOptimise ++ strawmanClassPath)
51-
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, basicLinkOptimise ++ customLibClassPath)
50+
def linkStrawmanTest = compileFilesInDir(linkStramanDir, strawmanClassPath)
51+
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, customLibClassFlags)
5252

5353
def classFileChecks(sourceDir: String, testName: String) = {
5454
val checkExt = ".classcheck"

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package dotty
22
package tools
33
package dotc
44

5-
import org.junit.{ Test, AfterClass }
6-
7-
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
5+
import org.junit.{AfterClass, Test}
6+
import vulpix._
87

98
import scala.concurrent.duration._
109

@@ -22,8 +21,8 @@ class MissingCoreLibTests extends ParallelTesting {
2221

2322
@Test def missingDottyLib: Unit = {
2423
val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib
25-
val options = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
26-
compileFile("../tests/neg/nolib/Foo.scala", options).checkExpectedErrors()
24+
val options = noCheckOptions ++ checkOptions ++ yCheckOptions
25+
compileFile("../tests/neg/nolib/Foo.scala", TestFlags(classPath, options)).checkExpectedErrors()
2726
}
2827

2928
}

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import vulpix.TestConfiguration
1414
class PatmatExhaustivityTest {
1515
val testsDir = "../tests/patmat"
1616
// stop-after: patmatexhaust-huge.scala crash compiler
17-
val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat") ++ TestConfiguration.classPath
17+
val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat", "-classpath", TestConfiguration.classPath)
1818

1919
private def compileFile(file: File) = {
2020
val stringBuffer = new StringWriter()

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

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
5050
private sealed trait TestSource { self =>
5151
def name: String
5252
def outDir: JFile
53-
def flags: Array[String]
54-
55-
def classPath: String =
56-
outDir.getAbsolutePath +
57-
flags
58-
.dropWhile(_ != "-classpath")
59-
.drop(1)
60-
.headOption
61-
.map(":" + _)
62-
.getOrElse("")
53+
def flags: TestFlags
6354

64-
def runClassPath = {
65-
flags
66-
.dropWhile(_ != "-YRunClasspath")
67-
.drop(1)
68-
.headOption
69-
.map(outDir.getAbsolutePath + ":" + _)
70-
.getOrElse(classPath)
71-
}
55+
def runClassPath: String = outDir.getAbsolutePath + ":" + flags.runClassPath
7256

7357
def title: String = self match {
7458
case self: JointCompilationSource =>
@@ -82,11 +66,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
8266
/** Adds the flags specified in `newFlags0` if they do not already exist */
8367
def withFlags(newFlags0: String*) = {
8468
val newFlags = newFlags0.toArray
85-
if (!flags.containsSlice(newFlags)) self match {
69+
if (!flags.options.containsSlice(newFlags)) self match {
8670
case self: JointCompilationSource =>
87-
self.copy(flags = flags ++ newFlags)
71+
self.copy(flags = flags.and(newFlags:_*))
8872
case self: SeparateCompilationSource =>
89-
self.copy(flags = flags ++ newFlags)
73+
self.copy(flags = flags.and(newFlags:_*))
9074
}
9175
else self
9276
}
@@ -103,7 +87,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10387
|the test can be reproduced by running:""".stripMargin
10488
)
10589
sb.append("\n\n./bin/dotc ")
106-
flags.foreach { arg =>
90+
flags.all.foreach { arg =>
10791
if (lineLen > maxLen) {
10892
sb.append(" \\\n ")
10993
lineLen = 4
@@ -147,7 +131,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
147131
private final case class JointCompilationSource(
148132
name: String,
149133
files: Array[JFile],
150-
flags: Array[String],
134+
flags: TestFlags,
151135
outDir: JFile
152136
) extends TestSource {
153137
def sourceFiles: Array[JFile] = files.filter(isSourceFile)
@@ -161,7 +145,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
161145
private final case class SeparateCompilationSource(
162146
name: String,
163147
dir: JFile,
164-
flags: Array[String],
148+
flags: TestFlags,
165149
outDir: JFile
166150
) extends TestSource {
167151

@@ -342,9 +326,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
342326
}
343327
}
344328

345-
protected def compile(files0: Array[JFile], flags0: Array[String], suppressErrors: Boolean, targetDir: JFile): TestReporter = {
329+
protected def compile(files0: Array[JFile], flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
346330

347-
val flags = flags0 ++ Array("-d", targetDir.getAbsolutePath)
331+
val flags = flags0 and ("-d", targetDir.getAbsolutePath)
348332

349333
def flattenFiles(f: JFile): Array[JFile] =
350334
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
@@ -367,7 +351,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
367351
"-encoding", "UTF-8",
368352
"-classpath",
369353
s".:${Jars.scalaLibrary}:${targetDir.getAbsolutePath}"
370-
) ++ flags.takeRight(2) ++ fs
354+
) ++ flags.all.takeRight(2) ++ fs
371355

372356
val process = Runtime.getRuntime.exec(fullArgs)
373357
val output = Source.fromInputStream(process.getErrorStream).mkString
@@ -395,7 +379,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
395379
}
396380
}
397381

398-
val allArgs = addOutDir(flags)
382+
val allArgs = addOutDir(flags.all)
399383

400384
// Compile with a try to catch any StackTrace generated by the compiler:
401385
try {
@@ -1073,7 +1057,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10731057
}
10741058

10751059
/** Compiles a single file from the string path `f` using the supplied flags */
1076-
def compileFile(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1060+
def compileFile(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = {
10771061
val callingMethod = getCallingMethod()
10781062
val sourceFile = new JFile(f)
10791063
val parent = sourceFile.getParentFile
@@ -1103,7 +1087,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11031087
* By default, files are compiled in alphabetical order. An optional seed
11041088
* can be used for randomization.
11051089
*/
1106-
def compileDir(f: String, flags: Array[String], randomOrder: Option[Int] = None)(implicit outDirectory: String): CompilationTest = {
1090+
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None)(implicit outDirectory: String): CompilationTest = {
11071091
val callingMethod = getCallingMethod()
11081092
val outDir = outDirectory + callingMethod + "/"
11091093
val sourceDir = new JFile(f)
@@ -1132,7 +1116,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11321116
* `testName` since files can be in separate directories and or be otherwise
11331117
* dissociated
11341118
*/
1135-
def compileList(testName: String, files: List[String], flags: Array[String], callingMethod: String = getCallingMethod())(implicit outDirectory: String): CompilationTest = {
1119+
def compileList(testName: String, files: List[String], flags: TestFlags, callingMethod: String = getCallingMethod())(implicit outDirectory: String): CompilationTest = {
11361120
val outDir = outDirectory + callingMethod + "/" + testName + "/"
11371121

11381122
// Directories in which to compile all containing files with `flags`:
@@ -1163,7 +1147,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11631147
* - Directories can have an associated check-file, where the check file has
11641148
* the same name as the directory (with the file extension `.check`)
11651149
*/
1166-
def compileFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1150+
def compileFilesInDir(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = {
11671151
val callingMethod = getCallingMethod()
11681152
val outDir = outDirectory + callingMethod + "/"
11691153
val sourceDir = new JFile(f)
@@ -1183,7 +1167,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11831167
* sub-directories and as such, does **not** perform separate compilation
11841168
* tests.
11851169
*/
1186-
def compileShallowFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1170+
def compileShallowFilesInDir(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = {
11871171
val callingMethod = getCallingMethod()
11881172
val outDir = outDirectory + callingMethod + "/"
11891173
val sourceDir = new JFile(f)

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ package vulpix
55
object TestConfiguration {
66
implicit val defaultOutputDir: String = "../out/"
77

8-
implicit class RichStringArray(val xs: Array[String]) extends AnyVal {
9-
def and(args: String*): Array[String] = {
10-
val argsArr: Array[String] = args.toArray
11-
xs ++ argsArr
12-
}
13-
}
14-
158
val noCheckOptions = Array(
169
"-pagewidth", "120",
1710
"-color:never"
@@ -25,8 +18,8 @@ object TestConfiguration {
2518

2619
val classPath = mkClassPath(Jars.dottyTestDeps)
2720

28-
def mkClassPath(classPaths: List[String], classPathFlag: String = "-classpath"): Array[String] = {
29-
val paths = classPaths map { p =>
21+
def mkClassPath(classPaths: List[String]): String = {
22+
classPaths map { p =>
3023
val file = new java.io.File(p)
3124
assert(
3225
file.exists,
@@ -47,26 +40,23 @@ object TestConfiguration {
4740
|it in extras."""
4841
)
4942
file.getAbsolutePath
50-
} mkString (":")
51-
52-
Array(classPathFlag, paths)
43+
} mkString(":")
5344
}
5445

5546
val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,erasure,mixin,getClass,restoreScopes,labelDef")
5647

57-
val basicDefaultOptions = noCheckOptions ++ checkOptions ++ yCheckOptions
58-
val defaultUnoptimised = basicDefaultOptions ++ classPath
59-
val defaultOptimised = defaultUnoptimised :+ "-optimise"
48+
val basicDefaultOptions = checkOptions ++ noCheckOptions ++ yCheckOptions
49+
val defaultUnoptimised = TestFlags(classPath, basicDefaultOptions)
50+
val defaultOptimised = defaultUnoptimised and "-optimise"
6051
val defaultOptions = defaultUnoptimised
61-
val allowDeepSubtypes = defaultOptions diff Array("-Yno-deep-subtypes")
62-
val allowDoubleBindings = defaultOptions diff Array("-Yno-double-bindings")
63-
val picklingOptions = defaultUnoptimised ++ Array(
52+
val allowDeepSubtypes = defaultOptions without "-Yno-deep-subtypes"
53+
val allowDoubleBindings = defaultOptions without "-Yno-double-bindings"
54+
val picklingOptions = defaultUnoptimised and (
6455
"-Xprint-types",
6556
"-Ytest-pickler",
6657
"-Yprintpos"
6758
)
68-
val scala2Mode = defaultOptions ++ Array("-language:Scala2")
69-
val explicitUTF8 = defaultOptions ++ Array("-encoding", "UTF8")
70-
val explicitUTF16 = defaultOptions ++ Array("-encoding", "UTF16")
71-
val basicLinkOptimise = basicDefaultOptions ++ Array("-Xlink-optimise")
59+
val scala2Mode = defaultOptions and "-language:Scala2"
60+
val explicitUTF8 = defaultOptions and ("-encoding", "UTF8")
61+
val explicitUTF16 = defaultOptions and ("-encoding", "UTF16")
7262
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dotty.tools.vulpix
2+
3+
final case class TestFlags(
4+
defaultClassPath: String,
5+
runClassPath: String, // class path that is used when running `run` tests (not compiling)
6+
options: Array[String]) {
7+
8+
def and(flags: String*): TestFlags =
9+
TestFlags(defaultClassPath, runClassPath, options ++ flags)
10+
11+
def without(flags: String*): TestFlags =
12+
TestFlags(defaultClassPath, runClassPath, options diff flags)
13+
14+
def all: Array[String] = Array("-classpath", defaultClassPath) ++ options
15+
}
16+
17+
object TestFlags {
18+
def apply(classPath: String, flags: Array[String]): TestFlags = TestFlags(classPath, classPath, flags)
19+
}

0 commit comments

Comments
 (0)