Skip to content

Commit 8d87b56

Browse files
committed
Add file filter abstraction for ParallelTesting
1 parent a4f63ef commit 8d87b56

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class FromTastyTests extends ParallelTesting {
2727

2828
implicit val testGroup: TestGroup = TestGroup("posTestFromTasty")
2929
compileTastyInDir("tests/pos", defaultOptions,
30-
blacklist = FromTastySources.posFromTastyBlacklisted.toSet,
31-
decompilationBlacklist = FromTastySources.posDecompilationBlacklisted.toSet,
32-
recompilationWhitelist = FromTastySources.posRecompilationWhitelist.toSet
30+
fromTastyFilter = FileFilter.exclude(FromTastySources.posFromTastyBlacklisted),
31+
decompilationFilter = FileFilter.exclude(FromTastySources.posDecompilationBlacklisted),
32+
recompilationFilter = FileFilter.include(FromTastySources.posRecompilationWhitelist)
3333
).checkCompile()
3434
}
3535

@@ -41,9 +41,9 @@ class FromTastyTests extends ParallelTesting {
4141

4242
implicit val testGroup: TestGroup = TestGroup("runTestFromTasty")
4343
compileTastyInDir("tests/run", defaultOptions,
44-
blacklist = FromTastySources.runFromTastyBlacklisted.toSet,
45-
decompilationBlacklist = FromTastySources.runDecompilationBlacklisted.toSet,
46-
recompilationWhitelist = FromTastySources.runRecompilationWhitelist.toSet
44+
fromTastyFilter = FileFilter.exclude(FromTastySources.runFromTastyBlacklisted),
45+
decompilationFilter = FileFilter.exclude(FromTastySources.runDecompilationBlacklisted),
46+
recompilationFilter = FileFilter.include(FromTastySources.runRecompilationWhitelist)
4747
).checkRuns()
4848
}
4949
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.vulpix
2+
3+
sealed trait FileFilter {
4+
def accept(file: String): Boolean
5+
}
6+
7+
object FileFilter {
8+
9+
def exclude(files: List[String]): FileFilter = new FileFilter {
10+
private[this] val blackList = files.toSet
11+
def accept(file: String): Boolean = !blackList.contains(file)
12+
}
13+
14+
def include(files: List[String]): FileFilter = new FileFilter {
15+
private[this] val whiteList = files.toSet
16+
def accept(file: String): Boolean = whiteList.contains(file)
17+
}
18+
19+
object NoFilter extends FileFilter {
20+
def accept(file: String) = true
21+
}
22+
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11251125
}
11261126

11271127
/** Separates directories from files and returns them as `(dirs, files)` */
1128-
private def compilationTargets(sourceDir: JFile, blacklisted: String => Boolean = _ => false): (List[JFile], List[JFile]) =
1128+
private def compilationTargets(sourceDir: JFile, fileFilter: FileFilter = FileFilter.NoFilter): (List[JFile], List[JFile]) =
11291129
sourceDir.listFiles.foldLeft((List.empty[JFile], List.empty[JFile])) { case ((dirs, files), f) =>
1130-
if (blacklisted(f.getName)) (dirs, files)
1130+
if (!fileFilter.accept(f.getName)) (dirs, files)
11311131
else if (f.isDirectory) (f :: dirs, files)
11321132
else if (isSourceFile(f)) (dirs, f :: files)
11331133
else (dirs, files)
@@ -1225,12 +1225,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
12251225
* - Directories can have an associated check-file, where the check file has
12261226
* the same name as the directory (with the file extension `.check`)
12271227
*/
1228-
def compileFilesInDir(f: String, flags: TestFlags, blacklisted: String => Boolean = _ => false)(implicit testGroup: TestGroup): CompilationTest = {
1228+
def compileFilesInDir(f: String, flags: TestFlags, fileFilter: FileFilter = FileFilter.NoFilter)(implicit testGroup: TestGroup): CompilationTest = {
12291229
val outDir = defaultOutputDir + testGroup + "/"
12301230
val sourceDir = new JFile(f)
12311231
checkRequirements(f, sourceDir, outDir)
12321232

1233-
val (dirs, files) = compilationTargets(sourceDir, blacklisted)
1233+
val (dirs, files) = compilationTargets(sourceDir, fileFilter)
12341234

12351235
val targets =
12361236
files.map(f => JointCompilationSource(testGroup.name, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
@@ -1260,14 +1260,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
12601260
* Tests in the first part of the tuple must be executed before the second.
12611261
* Both testsRequires explicit delete().
12621262
*/
1263-
def compileTastyInDir(f: String, flags0: TestFlags, blacklist: Set[String], decompilationBlacklist: Set[String], recompilationWhitelist: Set[String])(
1263+
def compileTastyInDir(f: String, flags0: TestFlags, fromTastyFilter: FileFilter, decompilationFilter: FileFilter, recompilationFilter: FileFilter)(
12641264
implicit testGroup: TestGroup): TastyCompilationTest = {
12651265
val outDir = defaultOutputDir + testGroup + "/"
12661266
val flags = flags0 and "-Yretain-trees"
12671267
val sourceDir = new JFile(f)
12681268
checkRequirements(f, sourceDir, outDir)
12691269

1270-
val (dirs, files) = compilationTargets(sourceDir, blacklist)
1270+
val (dirs, files) = compilationTargets(sourceDir, fromTastyFilter)
12711271

12721272
val filteredFiles = testFilter match {
12731273
case Some(str) => files.filter(_.getAbsolutePath.contains(str))
@@ -1282,35 +1282,32 @@ trait ParallelTesting extends RunnerOrchestration { self =>
12821282

12831283
val targets2 =
12841284
filteredFiles
1285-
.filter(f => !decompilationBlacklist(f.getName))
1285+
.filter(f => decompilationFilter.accept(f.getName))
12861286
.map { f =>
12871287
val classpath = createOutputDirsForFile(f, sourceDir, outDir)
12881288
JointCompilationSource(testGroup.name, Array(f), flags.withClasspath(classpath.getPath), classpath, decompilation = true)
12891289
}
12901290

12911291
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
1292-
val generateClassFiles = compileFilesInDir(f, flags0, blacklist)
1292+
val generateClassFiles = compileFilesInDir(f, flags0, fromTastyFilter)
12931293

12941294
val decompilationDir = outDir + sourceDir.getName + "_decompiled"
12951295

12961296
if (targets2.isEmpty)
12971297
new JFile(decompilationDir).mkdirs()
12981298

1299-
val recompilationBlacklisted =
1300-
(f: String) => !recompilationWhitelist(f)
1301-
13021299
new TastyCompilationTest(
13031300
generateClassFiles.keepOutput,
13041301
new CompilationTest(targets).keepOutput,
13051302
new CompilationTest(targets2).keepOutput,
1306-
recompilationBlacklisted,
1303+
recompilationFilter,
13071304
decompilationDir,
13081305
shouldDelete = true
13091306
)
13101307
}
13111308

13121309
class TastyCompilationTest(step1: CompilationTest, step2: CompilationTest, step3: CompilationTest,
1313-
recompilationBlacklisted: String => Boolean, decompilationDir: String, shouldDelete: Boolean)(implicit testGroup: TestGroup) {
1310+
recompilationBlacklisted: FileFilter, decompilationDir: String, shouldDelete: Boolean)(implicit testGroup: TestGroup) {
13141311

13151312
def keepOutput: TastyCompilationTest =
13161313
new TastyCompilationTest(step1, step2, step3, recompilationBlacklisted, decompilationDir, shouldDelete)

0 commit comments

Comments
 (0)