Skip to content

Commit

Permalink
Add stdlib whitelist loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Jan 5, 2017
1 parent 3922cce commit 66a3409
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
9 changes: 2 additions & 7 deletions bench/test/dotty/tools/benchmarks/Benchmarks.scala
Original file line number Diff line number Diff line change
@@ -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._
Expand Down Expand Up @@ -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)

Expand Down
32 changes: 10 additions & 22 deletions compiler/test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -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)
}

Expand Down
31 changes: 31 additions & 0 deletions compiler/test/dotty/tools/StdLibSources.scala
Original file line number Diff line number Diff line change
@@ -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

}
16 changes: 3 additions & 13 deletions doc-tool/test/WhitelistedStdLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down

0 comments on commit 66a3409

Please sign in to comment.