Skip to content

Cleanup tests #5600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions compiler/test/dotc/scala-collections.blacklist

This file was deleted.

65 changes: 43 additions & 22 deletions compiler/test/dotty/tools/TestSources.scala
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package dotty.tools

import java.io.File
import java.nio.file._

import scala.io.Source
import scala.collection.JavaConverters._

object TestSources {

// Std Lib

private final val stdLibPath = "tests/scala2-library/src/library/"

private def blacklistFile: String = "compiler/test/dotc/scala-collections.blacklist"

def stdLibWhitelisted: List[String] = all.diff(stdLibBlacklisted)
def stdLibBlacklisted: List[String] = loadList(blacklistFile).map(stdLibPath + _)

private def all: List[String] = {
def collectAllFilesInDir(dir: File, acc: List[String]): List[String] = {
val files = dir.listFiles()
val acc2 = files.foldLeft(acc)((acc1, file) => if (file.isFile && file.getPath.endsWith(".scala")) file.getPath :: acc1 else acc1)
files.foldLeft(acc2)((acc3, file) => if (file.isDirectory) collectAllFilesInDir(file, acc3) else acc3)
}
collectAllFilesInDir(new File(stdLibPath), Nil).sorted
def stdLibSources: List[String] = {
val blacklisted = List(
"volatile.scala", // see #5610
)
sources(Paths.get("tests/scala2-library/src/library/"), excludedFiles = blacklisted)
}

// pos tests lists
Expand Down Expand Up @@ -50,11 +41,41 @@ object TestSources {

// load lists

private def loadList(path: String): List[String] = Source.fromFile(path, "UTF8").getLines()
.map(_.trim) // allow identation
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
.filter(_.nonEmpty)
.toList
private def loadList(path: String): List[String] = {
val list = Files.readAllLines(Paths.get(path))
.iterator()
.asScala
.map(_.trim) // allow indentation
.filterNot(_.startsWith("#")) // allow comment lines prefixed by #
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
.filter(_.nonEmpty)
.toList

assert(list.nonEmpty)
list
}

/** Retrieve sources from a directory */
def sources(path: Path, excludedFiles: List[String] = Nil, shallow: Boolean = false): List[String] = {
def fileFilter(path: Path) = {
val fileName = path.getFileName.toString
(fileName.endsWith(".scala") || fileName.endsWith(".java")) && !excludedFiles.contains(fileName)
}

assert(Files.isDirectory(path))
val files = if (shallow) Files.list(path) else Files.walk(path)
try {
val sources = files
.filter(fileFilter)
.sorted // make compilation order deterministic
.iterator()
.asScala
.map(_.toString)
.toList

assert(sources.nonEmpty)
sources
}
finally files.close()
}
}
43 changes: 14 additions & 29 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import java.util.stream.{ Stream => JStream }
import scala.collection.JavaConverters._
import scala.util.matching.Regex
import scala.concurrent.duration._
import TestSources.sources
import vulpix._
import dotty.tools.io.JFile

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

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

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

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

val compilerDir = Paths.get("compiler/src")
val compilerSources = sources(Files.walk(compilerDir))
val compilerSources = sources(Paths.get("compiler/src"))

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

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

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

tests.foreach(_.delete())
Expand All @@ -282,17 +282,13 @@ class CompilationTests extends ParallelTesting {
// 2. copy `pluginFile` to destination
def compileFilesInDir(dir: String): CompilationTest = {
val outDir = defaultOutputDir + "testPlugins/"
val sourceDir = new JFile(dir)

val dirs = sourceDir.listFiles.foldLeft(List.empty[JFile]) { case (dirs, f) =>
if (f.isDirectory) f :: dirs else dirs
}
val sourceDir = new java.io.File(dir)

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

Expand All @@ -306,15 +302,4 @@ class CompilationTests extends ParallelTesting {
object CompilationTests {
implicit val summaryReport: SummaryReporting = new SummaryReport
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()

def sources(paths: JStream[Path], excludedFiles: List[String] = Nil): List[String] = {
val sources = paths.iterator().asScala
.filter(path =>
(path.toString.endsWith(".scala") || path.toString.endsWith(".java"))
&& !excludedFiles.contains(path.getFileName.toString))
.map(_.toString).toList

paths.close()
sources
}
}
5 changes: 1 addition & 4 deletions compiler/test/dotty/tools/dotc/IdempotencyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class IdempotencyTests extends ParallelTesting {
implicit val testGroup: TestGroup = TestGroup("idempotency")
val opt = defaultOptions

def sourcesFrom(dir: Path) = CompilationTests.sources(Files.walk(dir))


val posIdempotency = {
compileFilesInDir("tests/pos", opt)(TestGroup("idempotency/posIdempotency1")) +
compileFilesInDir("tests/pos", opt)(TestGroup("idempotency/posIdempotency2"))
Expand All @@ -43,7 +40,7 @@ class IdempotencyTests extends ParallelTesting {
(for {
testDir <- new JFile("tests/order-idempotency").listFiles() if testDir.isDirectory
} yield {
val sources = sourcesFrom(testDir.toPath)
val sources = TestSources.sources(testDir.toPath)
compileList(testDir.getName, sources, opt)(TestGroup("idempotency/orderIdempotency1")) +
compileList(testDir.getName, sources.reverse, opt)(TestGroup("idempotency/orderIdempotency2"))
}).reduce(_ + _)
Expand Down
2 changes: 1 addition & 1 deletion doc-tool/test/dotty/tools/dottydoc/WhitelistedStdLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class TestWhitelistedCollections extends DottyDocTest with CheckFromSource {

object TestWhitelistedCollections {
val files: List[String] =
TestSources.stdLibWhitelisted
TestSources.stdLibSources
.filterNot(_.endsWith("package.scala"))
}