Skip to content

Commit 4d76265

Browse files
authored
Merge pull request #2193 from dotty-staging/deterministic-tests
Deterministically randomises test compilation order
2 parents 49a18da + 8a83bb1 commit 4d76265

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ object Trees {
788788
def complete(implicit ctx: Context): T
789789
}
790790

791-
// ----- Generic Tree Instances, inherited from `tpt` and `untpd`.
791+
// ----- Generic Tree Instances, inherited from `tpt` and `untpd`.
792792

793793
abstract class Instance[T >: Untyped <: Type] extends DotClass { inst =>
794794

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ object Types {
17931793
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
17941794
fixDenot(TermRef.withSig(prefix, name, sig), prefix)
17951795

1796-
override def shadowed(implicit ctx: Context): NamedType =
1796+
override def shadowed(implicit ctx: Context): NamedType =
17971797
fixDenot(TermRef.withSig(prefix, name.shadowedName, sig), prefix)
17981798

17991799
override def equals(that: Any) = that match {

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import scala.util.control.NonFatal
1515
import scala.util.Try
1616
import scala.collection.mutable
1717
import scala.util.matching.Regex
18+
import scala.util.Random
1819

1920
import core.Contexts._
2021
import reporting.{ Reporter, TestReporter }
@@ -1010,8 +1011,11 @@ trait ParallelTesting { self =>
10101011
/** Compiles a directory `f` using the supplied `flags`. This method does
10111012
* deep compilation, that is - it compiles all files and subdirectories
10121013
* contained within the directory `f`.
1014+
*
1015+
* By default, files are compiled in alphabetical order. An optional seed
1016+
* can be used for randomization.
10131017
*/
1014-
def compileDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1018+
def compileDir(f: String, flags: Array[String], randomOrder: Option[Int] = None)(implicit outDirectory: String): CompilationTest = {
10151019
val callingMethod = getCallingMethod
10161020
val outDir = outDirectory + callingMethod + "/"
10171021
val sourceDir = new JFile(f)
@@ -1021,11 +1025,18 @@ trait ParallelTesting { self =>
10211025
if (f.isDirectory) f.listFiles.flatMap(flatten)
10221026
else Array(f)
10231027

1028+
// Sort files either alphabetically or randomly using the provided seed:
1029+
val sortedFiles = flatten(sourceDir).sorted
1030+
val randomized = randomOrder match {
1031+
case None => sortedFiles
1032+
case Some(seed) => new Random(seed).shuffle(sortedFiles.toList).toArray
1033+
}
1034+
10241035
// Directories in which to compile all containing files with `flags`:
10251036
val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
10261037
targetDir.mkdirs()
10271038

1028-
val target = JointCompilationSource(callingMethod, flatten(sourceDir), flags, targetDir)
1039+
val target = JointCompilationSource(callingMethod, randomized, flags, targetDir)
10291040
new CompilationTest(target)
10301041
}
10311042

0 commit comments

Comments
 (0)