diff options
Diffstat (limited to 'compiler/test/dotc/tests.scala')
-rw-r--r-- | compiler/test/dotc/tests.scala | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index b389c6ae9..a7961d937 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -3,6 +3,7 @@ package dotc import dotty.Jars import dotty.tools.dotc.CompilerTest import org.junit.{Before, Test} +import org.junit.Assert._ import java.io.{ File => JFile } import scala.reflect.io.Directory @@ -84,6 +85,7 @@ class tests extends CompilerTest { val runDir = testsDir + "run/" val newDir = testsDir + "new/" val replDir = testsDir + "repl/" + val javaDir = testsDir + "pos-java-interop/" val sourceDir = "./src/" val dottyDir = sourceDir + "dotty/" @@ -96,6 +98,9 @@ class tests extends CompilerTest { val typerDir = dotcDir + "typer/" val libDir = "../library/src/" + def dottyBootedLib = compileDir(libDir, ".", List("-deep", "-Ycheck-reentrant", "-strict") ::: defaultOptions)(allowDeepSubtypes) // note the -deep argument + def dottyDependsOnBootedLib = compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict") ::: defaultOptions)(allowDeepSubtypes) // note the -deep argument + @Before def cleanup(): Unit = { // remove class files from stdlib and tests compilation Directory(defaultOutputDir + "scala").deleteRecursively() @@ -196,12 +201,49 @@ class tests extends CompilerTest { @Test def run_all = runFiles(runDir) - val stdlibFiles = Source.fromFile("./test/dotc/scala-collections.whitelist", "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 + def loadList(path: 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 stdlibWhitelistFile = "./test/dotc/scala-collections.whitelist" + private def stdlibBlackFile = "./test/dotc/scala-collections.blacklist" + + private val stdlibFiles: List[String] = loadList(stdlibWhitelistFile) + + @Test def checkWBLists = { + val stdlibFilesBlackListed = loadList(stdlibBlackFile) + + def checkForRepeated(list: List[String], listFile: String) = { + val duplicates = list.groupBy(x => x).filter(_._2.size > 1).filter(_._2.size > 1) + val msg = duplicates.map(x => s"'${x._1}' appears ${x._2.size} times").mkString(s"Duplicate entries in $listFile:\n", "\n", "\n") + assertTrue(msg, duplicates.isEmpty) + } + checkForRepeated(stdlibFiles, stdlibWhitelistFile) + checkForRepeated(stdlibFilesBlackListed, stdlibBlackFile) + + val whitelistSet = stdlibFiles.toSet + val blacklistSet = stdlibFilesBlackListed.toSet + + val intersection = whitelistSet.intersect(blacklistSet) + val msgIntersection = + intersection.map(x => s"'$x'").mkString(s"Entries where found in both $stdlibWhitelistFile and $stdlibBlackFile:\n", "\n", "\n") + assertTrue(msgIntersection, intersection.isEmpty) + + def collectAllFilesInDir(dir: JFile, 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) + } + val filesInStdLib = collectAllFilesInDir(new JFile("../scala-scala/src/library/"), Nil) + val missingFiles = filesInStdLib.toSet -- whitelistSet -- blacklistSet + val msgMissing = + missingFiles.map(x => s"'$x'").mkString(s"Entries are missing in $stdlibWhitelistFile or $stdlibBlackFile:\n", "\n", "\n") + assertTrue(msgMissing, missingFiles.isEmpty) + } + @Test def compileStdLib = compileList("compileStdLib", stdlibFiles, "-migration" :: "-Yno-inline" :: scala2mode) @Test def compileMixed = compileLine( @@ -214,11 +256,10 @@ class tests extends CompilerTest { |../scala-scala/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin) @Test def compileIndexedSeq = compileLine("../scala-scala/src/library/scala/collection/immutable/IndexedSeq.scala") - // Not a junit test anymore since it is order dependent - def dottyBootedLib = compileDir(libDir, ".")(allowDeepSubtypes) // note the -deep argument - - // Not a junit test anymore since it is order dependent - def dottyDependsOnBootedLib = compileDir(dottyDir, ".")(allowDeepSubtypes) // note the -deep argument + @Test def dotty = { + dottyBootedLib + dottyDependsOnBootedLib + } @Test def dotc_ast = compileDir(dotcDir, "ast") @Test def dotc_config = compileDir(dotcDir, "config") @@ -238,7 +279,7 @@ class tests extends CompilerTest { @Test def dotc_typer = compileDir(dotcDir, "typer")// twice omitted to make tests run faster // error: error while loading Checking$$anon$2$, - // class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)' + // class file 'target/scala-2.11/dotty_2.11-0.1.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)' // has location not matching its contents: contains class $anon @Test def dotc_util = compileDir(dotcDir, "util") // twice omitted to make tests run faster @@ -260,7 +301,6 @@ class tests extends CompilerTest { dotcDir + "config/PathResolver.scala" ), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice) - val javaDir = "./tests/pos-java-interop/" @Test def java_all = compileFiles(javaDir, twice) //@Test def dotc_compilercommand = compileFile(dotcDir + "config/", "CompilerCommand") @@ -349,9 +389,10 @@ class tests extends CompilerTest { @Test def tasty_tests = compileDir(testsDir, "tasty", testPickling) @Test def tasty_bootstrap = { - val opt = List("-priorityclasspath", defaultOutputDir, "-Ylog-classpath") + val logging = if (false) List("-Ylog-classpath", "-verbose") else Nil + val opt = List("-priorityclasspath", defaultOutputDir) ++ logging // first compile dotty - compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict"))(allowDeepSubtypes) + compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict") ++ logging)(allowDeepSubtypes) compileDir(libDir, "dotty", "-deep" :: opt) compileDir(libDir, "scala", "-deep" :: opt) |