Skip to content

Commit fbac9c1

Browse files
Deterministically randomises test compilation order
The previous implementation would compile tests in different orders from machine to machine, depending on the order in which *.scala files are listed by the operating system.
1 parent 42c2a6f commit fbac9c1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-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: 9 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 }
@@ -1011,7 +1012,7 @@ trait ParallelTesting { self =>
10111012
* deep compilation, that is - it compiles all files and subdirectories
10121013
* contained within the directory `f`.
10131014
*/
1014-
def compileDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1015+
def compileDir(f: String, flags: Array[String], seed: Int = 42)(implicit outDirectory: String): CompilationTest = {
10151016
val callingMethod = getCallingMethod
10161017
val outDir = outDirectory + callingMethod + "/"
10171018
val sourceDir = new JFile(f)
@@ -1021,11 +1022,17 @@ trait ParallelTesting { self =>
10211022
if (f.isDirectory) f.listFiles.flatMap(flatten)
10221023
else Array(f)
10231024

1025+
val files = {
1026+
// Deterministically randomises compilation order
1027+
Random.setSeed(seed)
1028+
Random.shuffle(flatten(sourceDir).toList).toArray
1029+
}
1030+
10241031
// Directories in which to compile all containing files with `flags`:
10251032
val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
10261033
targetDir.mkdirs()
10271034

1028-
val target = JointCompilationSource(callingMethod, flatten(sourceDir), flags, targetDir)
1035+
val target = JointCompilationSource(callingMethod, files, flags, targetDir)
10291036
new CompilationTest(target)
10301037
}
10311038

0 commit comments

Comments
 (0)