Skip to content

Commit 2a7edab

Browse files
authored
Merge pull request #5600 from dotty-staging/test-cleanup
Cleanup tests
2 parents 3185338 + affdaf2 commit 2a7edab

File tree

5 files changed

+59
-61
lines changed

5 files changed

+59
-61
lines changed

compiler/test/dotc/scala-collections.blacklist

-5
This file was deleted.
+43-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
package dotty.tools
22

33
import java.io.File
4+
import java.nio.file._
45

5-
import scala.io.Source
6+
import scala.collection.JavaConverters._
67

78
object TestSources {
89

910
// Std Lib
10-
11-
private final val stdLibPath = "tests/scala2-library/src/library/"
12-
13-
private def blacklistFile: String = "compiler/test/dotc/scala-collections.blacklist"
14-
15-
def stdLibWhitelisted: List[String] = all.diff(stdLibBlacklisted)
16-
def stdLibBlacklisted: List[String] = loadList(blacklistFile).map(stdLibPath + _)
17-
18-
private def all: List[String] = {
19-
def collectAllFilesInDir(dir: File, acc: List[String]): List[String] = {
20-
val files = dir.listFiles()
21-
val acc2 = files.foldLeft(acc)((acc1, file) => if (file.isFile && file.getPath.endsWith(".scala")) file.getPath :: acc1 else acc1)
22-
files.foldLeft(acc2)((acc3, file) => if (file.isDirectory) collectAllFilesInDir(file, acc3) else acc3)
23-
}
24-
collectAllFilesInDir(new File(stdLibPath), Nil).sorted
11+
def stdLibSources: List[String] = {
12+
val blacklisted = List(
13+
"volatile.scala", // see #5610
14+
)
15+
sources(Paths.get("tests/scala2-library/src/library/"), excludedFiles = blacklisted)
2516
}
2617

2718
// pos tests lists
@@ -50,11 +41,41 @@ object TestSources {
5041

5142
// load lists
5243

53-
private def loadList(path: String): List[String] = Source.fromFile(path, "UTF8").getLines()
54-
.map(_.trim) // allow identation
55-
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
56-
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
57-
.filter(_.nonEmpty)
58-
.toList
44+
private def loadList(path: String): List[String] = {
45+
val list = Files.readAllLines(Paths.get(path))
46+
.iterator()
47+
.asScala
48+
.map(_.trim) // allow indentation
49+
.filterNot(_.startsWith("#")) // allow comment lines prefixed by #
50+
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
51+
.filter(_.nonEmpty)
52+
.toList
53+
54+
assert(list.nonEmpty)
55+
list
56+
}
57+
58+
/** Retrieve sources from a directory */
59+
def sources(path: Path, excludedFiles: List[String] = Nil, shallow: Boolean = false): List[String] = {
60+
def fileFilter(path: Path) = {
61+
val fileName = path.getFileName.toString
62+
(fileName.endsWith(".scala") || fileName.endsWith(".java")) && !excludedFiles.contains(fileName)
63+
}
5964

65+
assert(Files.isDirectory(path))
66+
val files = if (shallow) Files.list(path) else Files.walk(path)
67+
try {
68+
val sources = files
69+
.filter(fileFilter)
70+
.sorted // make compilation order deterministic
71+
.iterator()
72+
.asScala
73+
.map(_.toString)
74+
.toList
75+
76+
assert(sources.nonEmpty)
77+
sources
78+
}
79+
finally files.close()
80+
}
6081
}

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

+14-29
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import java.util.stream.{ Stream => JStream }
1212
import scala.collection.JavaConverters._
1313
import scala.util.matching.Regex
1414
import scala.concurrent.duration._
15+
import TestSources.sources
1516
import vulpix._
16-
import dotty.tools.io.JFile
1717

1818
class CompilationTests extends ParallelTesting {
1919
import ParallelTesting._
@@ -34,12 +34,12 @@ class CompilationTests extends ParallelTesting {
3434
// @Test // enable to test compileStdLib separately with detailed stats
3535
def compileStdLibOnly: Unit = {
3636
implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
37-
compileList("compileStdLib", TestSources.stdLibWhitelisted, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
37+
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
3838
}.checkCompile()
3939

4040
@Test def pos: Unit = {
4141
implicit val testGroup: TestGroup = TestGroup("compilePos")
42-
compileList("compileStdLib", TestSources.stdLibWhitelisted, scala2Mode.and("-migration", "-Yno-inline")) +
42+
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline")) +
4343
compileFile("tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
4444
compileFile("tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
4545
compileFile("tests/pos-special/utf8encoded.scala", explicitUTF8) +
@@ -232,17 +232,16 @@ class CompilationTests extends ParallelTesting {
232232
)
233233

234234
val libraryDirs = List(Paths.get("library/src"), Paths.get("library/src-bootstrapped"))
235-
val librarySources = libraryDirs.flatMap(d => sources(Files.walk(d)))
235+
val librarySources = libraryDirs.flatMap(sources(_))
236236

237237
val lib =
238238
compileList("src", librarySources,
239239
defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))(libGroup)
240240

241-
val compilerDir = Paths.get("compiler/src")
242-
val compilerSources = sources(Files.walk(compilerDir))
241+
val compilerSources = sources(Paths.get("compiler/src"))
243242

244243
val scalaJSIRDir = Paths.get("compiler/target/scala-2.12/src_managed/main/scalajs-ir-src/org/scalajs/ir")
245-
val scalaJSIRSources = sources(Files.list(scalaJSIRDir))
244+
val scalaJSIRSources = sources(scalaJSIRDir, shallow = true)
246245

247246
val dotty1 = compileList("dotty", compilerSources ++ scalaJSIRSources, opt)(dotty1Group)
248247
val dotty2 = compileList("dotty", compilerSources ++ scalaJSIRSources, opt)(dotty2Group)
@@ -267,9 +266,10 @@ class CompilationTests extends ParallelTesting {
267266
}.keepOutput :: Nil
268267
}.map(_.checkCompile())
269268

270-
assert(new java.io.File(s"out/$dotty1Group/dotty/").exists)
271-
assert(new java.io.File(s"out/$dotty2Group/dotty/").exists)
272-
assert(new java.io.File(s"out/$libGroup/src/").exists)
269+
def assertExists(path: String) = assertTrue(Files.exists(Paths.get(path)))
270+
assertExists(s"out/$dotty1Group/dotty/")
271+
assertExists(s"out/$dotty2Group/dotty/")
272+
assertExists(s"out/$libGroup/src/")
273273
compileList("idempotency", List("tests/idempotency/BootstrapChecker.scala", "tests/idempotency/IdempotencyCheck.scala"), defaultOptions).checkRuns()
274274

275275
tests.foreach(_.delete())
@@ -282,17 +282,13 @@ class CompilationTests extends ParallelTesting {
282282
// 2. copy `pluginFile` to destination
283283
def compileFilesInDir(dir: String): CompilationTest = {
284284
val outDir = defaultOutputDir + "testPlugins/"
285-
val sourceDir = new JFile(dir)
286-
287-
val dirs = sourceDir.listFiles.foldLeft(List.empty[JFile]) { case (dirs, f) =>
288-
if (f.isDirectory) f :: dirs else dirs
289-
}
285+
val sourceDir = new java.io.File(dir)
290286

287+
val dirs = sourceDir.listFiles.toList.filter(_.isDirectory)
291288
val targets = dirs.map { dir =>
292289
val compileDir = createOutputDirsForDir(dir, sourceDir, outDir)
293-
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
294-
Files.copy(dir.toPath.resolve(pluginFile), compileDir.toPath.resolve(pluginFile), REPLACE_EXISTING)
295-
val flags = TestFlags(withCompilerClasspath, noCheckOptions) and ("-Xplugin:" + compileDir.getAbsolutePath)
290+
Files.copy(dir.toPath.resolve(pluginFile), compileDir.toPath.resolve(pluginFile), StandardCopyOption.REPLACE_EXISTING)
291+
val flags = TestFlags(withCompilerClasspath, noCheckOptions).and("-Xplugin:" + compileDir.getAbsolutePath)
296292
SeparateCompilationSource("testPlugins", dir, flags, compileDir)
297293
}
298294

@@ -306,15 +302,4 @@ class CompilationTests extends ParallelTesting {
306302
object CompilationTests {
307303
implicit val summaryReport: SummaryReporting = new SummaryReport
308304
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
309-
310-
def sources(paths: JStream[Path], excludedFiles: List[String] = Nil): List[String] = {
311-
val sources = paths.iterator().asScala
312-
.filter(path =>
313-
(path.toString.endsWith(".scala") || path.toString.endsWith(".java"))
314-
&& !excludedFiles.contains(path.getFileName.toString))
315-
.map(_.toString).toList
316-
317-
paths.close()
318-
sources
319-
}
320305
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class IdempotencyTests extends ParallelTesting {
3131
implicit val testGroup: TestGroup = TestGroup("idempotency")
3232
val opt = defaultOptions
3333

34-
def sourcesFrom(dir: Path) = CompilationTests.sources(Files.walk(dir))
35-
36-
3734
val posIdempotency = {
3835
compileFilesInDir("tests/pos", opt)(TestGroup("idempotency/posIdempotency1")) +
3936
compileFilesInDir("tests/pos", opt)(TestGroup("idempotency/posIdempotency2"))
@@ -43,7 +40,7 @@ class IdempotencyTests extends ParallelTesting {
4340
(for {
4441
testDir <- new JFile("tests/order-idempotency").listFiles() if testDir.isDirectory
4542
} yield {
46-
val sources = sourcesFrom(testDir.toPath)
43+
val sources = TestSources.sources(testDir.toPath)
4744
compileList(testDir.getName, sources, opt)(TestGroup("idempotency/orderIdempotency1")) +
4845
compileList(testDir.getName, sources.reverse, opt)(TestGroup("idempotency/orderIdempotency2"))
4946
}).reduce(_ + _)

doc-tool/test/dotty/tools/dottydoc/WhitelistedStdLib.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ class TestWhitelistedCollections extends DottyDocTest with CheckFromSource {
3232

3333
object TestWhitelistedCollections {
3434
val files: List[String] =
35-
TestSources.stdLibWhitelisted
35+
TestSources.stdLibSources
3636
.filterNot(_.endsWith("package.scala"))
3737
}

0 commit comments

Comments
 (0)