diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-01-05 11:08:26 +0100 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-01-05 11:08:26 +0100 |
commit | 66a340937b0adead0aa7a96e21f68d43a03cba00 (patch) | |
tree | c29d139a36a2ecb5db669b613100b63a6dfb5a5f | |
parent | 3922cce7afc295f7816397ebf2d2f59446a89041 (diff) | |
download | dotty-66a340937b0adead0aa7a96e21f68d43a03cba00.tar.gz dotty-66a340937b0adead0aa7a96e21f68d43a03cba00.tar.bz2 dotty-66a340937b0adead0aa7a96e21f68d43a03cba00.zip |
Add stdlib whitelist loader.
-rw-r--r-- | bench/test/dotty/tools/benchmarks/Benchmarks.scala | 9 | ||||
-rw-r--r-- | compiler/test/dotc/tests.scala | 32 | ||||
-rw-r--r-- | compiler/test/dotty/tools/StdLibSources.scala | 31 | ||||
-rw-r--r-- | doc-tool/test/WhitelistedStdLib.scala | 16 |
4 files changed, 46 insertions, 42 deletions
diff --git a/bench/test/dotty/tools/benchmarks/Benchmarks.scala b/bench/test/dotty/tools/benchmarks/Benchmarks.scala index fe5517ad9..242d60788 100644 --- a/bench/test/dotty/tools/benchmarks/Benchmarks.scala +++ b/bench/test/dotty/tools/benchmarks/Benchmarks.scala @@ -1,5 +1,6 @@ package dotty.tools.benchmarks +import dotty.tools.StdLibSources import org.scalameter.Key.reports._ import org.scalameter.PerformanceTest.OnlineRegressionReport import org.scalameter.api._ @@ -47,13 +48,7 @@ object BenchTests extends OnlineRegressionReport { val dottyDir = "../compiler/src/dotty/" - val stdlibFiles = Source.fromFile("../compiler/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) - .map("." + _) - .toList + val stdlibFiles = StdLibSources.whitelisted def stdLib = compiler.compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode) 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) } diff --git a/compiler/test/dotty/tools/StdLibSources.scala b/compiler/test/dotty/tools/StdLibSources.scala new file mode 100644 index 000000000..9afb81d20 --- /dev/null +++ b/compiler/test/dotty/tools/StdLibSources.scala @@ -0,0 +1,31 @@ +package dotty.tools + +import java.io.File + +import scala.io.Source + +object StdLibSources { + + def whitelistFile: String = "./test/dotc/scala-collections.whitelist" + def blacklistFile: String = "./test/dotc/scala-collections.blacklist" + + def whitelisted: List[String] = loadList(whitelistFile) + def blacklisted: List[String] = loadList(blacklistFile) + + 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("../scala-scala/src/library/"), Nil) + } + + 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 + +} diff --git a/doc-tool/test/WhitelistedStdLib.scala b/doc-tool/test/WhitelistedStdLib.scala index 48697ea7f..90df859e0 100644 --- a/doc-tool/test/WhitelistedStdLib.scala +++ b/doc-tool/test/WhitelistedStdLib.scala @@ -4,19 +4,9 @@ package dottydoc import org.junit.Test import org.junit.Assert._ -class TestWhitelistedCollections extends DottyTest { - val files: List[String] = { - val whitelist = "./test/dotc/scala-collections.whitelist" - - scala.io.Source.fromFile(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) - .filterNot(_.endsWith("package.scala")) - .toList - } +class WhitelistedStdLib extends DottyTest { + val files: List[String] = + StdLibSources.whitelisted.filterNot(_.endsWith("package.scala")) @Test def arrayHasDocumentation = checkFiles(files) { packages => |