From 66a340937b0adead0aa7a96e21f68d43a03cba00 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 5 Jan 2017 11:08:26 +0100 Subject: Add stdlib whitelist loader. --- compiler/test/dotc/tests.scala | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'compiler/test/dotc/tests.scala') diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index eecb068fe..c098aee33 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -2,6 +2,7 @@ package dotc import dotty.Jars import dotty.tools.dotc.CompilerTest +import dotty.tools.StdLibSources import org.junit.{Before, Test} import org.junit.Assert._ @@ -201,46 +202,33 @@ class tests extends CompilerTest { @Test def run_all = runFiles(runDir) - 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) + private val stdlibFiles: List[String] = StdLibSources.whitelisted @Test def checkWBLists = { - val stdlibFilesBlackListed = loadList(stdlibBlackFile) + import StdLibSources.{whitelistFile, blacklistFile} + + val stdlibFilesBlackListed = StdLibSources.blacklisted 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) + checkForRepeated(stdlibFiles, whitelistFile) + checkForRepeated(stdlibFilesBlackListed, blacklistFile) 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") + intersection.map(x => s"'$x'").mkString(s"Entries where found in both $whitelistFile and $blacklistFile:\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 filesInStdLib = StdLibSources.all 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") + missingFiles.map(x => s"'$x'").mkString(s"Entries are missing in $whitelistFile or $blacklistFile:\n", "\n", "\n") assertTrue(msgMissing, missingFiles.isEmpty) } -- cgit v1.2.3