@@ -15,6 +15,7 @@ import scala.util.control.NonFatal
15
15
import scala .util .Try
16
16
import scala .collection .mutable
17
17
import scala .util .matching .Regex
18
+ import scala .util .Random
18
19
19
20
import core .Contexts ._
20
21
import reporting .{ Reporter , TestReporter }
@@ -1010,8 +1011,11 @@ trait ParallelTesting { self =>
1010
1011
/** Compiles a directory `f` using the supplied `flags`. This method does
1011
1012
* deep compilation, that is - it compiles all files and subdirectories
1012
1013
* contained within the directory `f`.
1014
+ *
1015
+ * By default, files are compiled in alphabetical order. An optional seed
1016
+ * can be used for randomization.
1013
1017
*/
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 = {
1015
1019
val callingMethod = getCallingMethod
1016
1020
val outDir = outDirectory + callingMethod + " /"
1017
1021
val sourceDir = new JFile (f)
@@ -1021,11 +1025,18 @@ trait ParallelTesting { self =>
1021
1025
if (f.isDirectory) f.listFiles.flatMap(flatten)
1022
1026
else Array (f)
1023
1027
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
+
1024
1035
// Directories in which to compile all containing files with `flags`:
1025
1036
val targetDir = new JFile (outDir + " /" + sourceDir.getName + " /" )
1026
1037
targetDir.mkdirs()
1027
1038
1028
- val target = JointCompilationSource (callingMethod, flatten(sourceDir) , flags, targetDir)
1039
+ val target = JointCompilationSource (callingMethod, randomized , flags, targetDir)
1029
1040
new CompilationTest (target)
1030
1041
}
1031
1042
0 commit comments