From d9cfd766652b5975f98ce678e86dab008ccdd751 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 14 Dec 2016 11:05:46 +0100 Subject: Add scala-collections.blacklist and crosscheck with whitelist. --- compiler/test/dotc/tests.scala | 50 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'compiler/test/dotc/tests.scala') diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index f858926d5..84cf1a051 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 @@ -197,12 +198,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( -- cgit v1.2.3