Skip to content

Commit 018ae3d

Browse files
committed
Cleanup tests
- Remove std lib blacklist - Factor out some code
1 parent 9b0c729 commit 018ae3d

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
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 = "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)
11+
def stdLibSources: List[String] = {
12+
val blacklisted = List(
13+
"StructuralCallSite.java" // See #4739
14+
)
15+
sources(Paths.get("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 identation
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 = Files.walk(path, if (shallow) 1 else Int.MaxValue)
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

+16-30
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

1919
class CompilationTests extends 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) +
@@ -218,14 +218,14 @@ class CompilationTests extends ParallelTesting {
218218
)
219219

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

223223
val lib =
224224
compileList("src", librarySources,
225225
defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))(libGroup)
226226

227227
val compilerDir = Paths.get("compiler/src")
228-
val compilerSources = sources(Files.walk(compilerDir))
228+
val compilerSources = sources(compilerDir)
229229

230230
val backendDir = Paths.get("scala-backend/src/compiler/scala/tools/nsc/backend")
231231
val backendJvmDir = Paths.get("scala-backend/src/compiler/scala/tools/nsc/backend/jvm")
@@ -238,11 +238,11 @@ class CompilationTests extends ParallelTesting {
238238
List("BCodeICodeCommon.scala", "GenASM.scala", "GenBCode.scala", "ScalacBackendInterface.scala", "BackendStats.scala", "BCodeAsmEncode.scala")
239239

240240
val backendSources =
241-
sources(Files.list(backendDir), excludedFiles = backendExcluded)
241+
sources(backendDir, excludedFiles = backendExcluded, shallow = true)
242242
val backendJvmSources =
243-
sources(Files.list(backendJvmDir), excludedFiles = backendJvmExcluded)
243+
sources(backendJvmDir, excludedFiles = backendJvmExcluded, shallow = true)
244244
val scalaJSIRSources =
245-
sources(Files.list(scalaJSIRDir))
245+
sources(scalaJSIRDir, shallow = true)
246246

247247
val dotty1 = compileList("dotty", compilerSources ++ backendSources ++ backendJvmSources ++ scalaJSIRSources, opt)(dotty1Group)
248248
val dotty2 = compileList("dotty", compilerSources ++ backendSources ++ backendJvmSources ++ scalaJSIRSources, opt)(dotty2Group)
@@ -267,9 +267,10 @@ class CompilationTests extends ParallelTesting {
267267
}.keepOutput :: Nil
268268
}.map(_.checkCompile())
269269

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)
270+
def assertExists(path: String) = assertTrue(Files.exists(Paths.get(path)))
271+
assertExists(s"out/$dotty1Group/dotty/")
272+
assertExists(s"out/$dotty2Group/dotty/")
273+
assertExists(s"out/$libGroup/src/")
273274
compileList("idempotency", List("tests/idempotency/BootstrapChecker.scala", "tests/idempotency/IdempotencyCheck.scala"), defaultOptions).checkRuns()
274275

275276
tests.foreach(_.delete())
@@ -282,17 +283,13 @@ class CompilationTests extends ParallelTesting {
282283
// 2. copy `pluginFile` to destination
283284
def compileFilesInDir(dir: String): CompilationTest = {
284285
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-
}
286+
val sourceDir = new java.io.File(dir)
290287

288+
val dirs = sourceDir.listFiles.toList.filter(_.isDirectory)
291289
val targets = dirs.map { dir =>
292290
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)
291+
Files.copy(dir.toPath.resolve(pluginFile), compileDir.toPath.resolve(pluginFile), StandardCopyOption.REPLACE_EXISTING)
292+
val flags = TestFlags(withCompilerClasspath, noCheckOptions).and("-Xplugin:" + compileDir.getAbsolutePath)
296293
SeparateCompilationSource("testPlugins", dir, flags, compileDir)
297294
}
298295

@@ -306,15 +303,4 @@ class CompilationTests extends ParallelTesting {
306303
object CompilationTests {
307304
implicit val summaryReport: SummaryReporting = new SummaryReport
308305
@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-
}
320306
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class IdempotencyTests extends ParallelTesting {
3030
implicit val testGroup: TestGroup = TestGroup("idempotency")
3131
val opt = defaultOptions
3232

33-
def sourcesFrom(dir: Path) = CompilationTests.sources(Files.walk(dir))
34-
35-
val strawmanSources = sourcesFrom(Paths.get("collection-strawman/collections/src/main"))
33+
val strawmanSources = TestSources.sources(Paths.get("collection-strawman/collections/src/main"))
3634
val strawmanSourcesSorted = strawmanSources.sorted
3735
val strawmanSourcesRevSorted = strawmanSourcesSorted.reverse
3836

@@ -45,7 +43,7 @@ class IdempotencyTests extends ParallelTesting {
4543
(for {
4644
testDir <- new JFile("tests/order-idempotency").listFiles() if testDir.isDirectory
4745
} yield {
48-
val sources = sourcesFrom(testDir.toPath)
46+
val sources = TestSources.sources(testDir.toPath)
4947
compileList(testDir.getName, sources, opt)(TestGroup("idempotency/orderIdempotency1")) +
5048
compileList(testDir.getName, sources.reverse, opt)(TestGroup("idempotency/orderIdempotency2"))
5149
}).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)