@@ -15,6 +15,7 @@ import scala.util.control.NonFatal
1515import scala .util .Try
1616import scala .collection .mutable
1717import scala .util .matching .Regex
18+ import scala .util .Random
1819
1920import core .Contexts ._
2021import 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