Skip to content

Commit 66a3409

Browse files
committed
Add stdlib whitelist loader.
1 parent 3922cce commit 66a3409

File tree

4 files changed

+46
-42
lines changed

4 files changed

+46
-42
lines changed

bench/test/dotty/tools/benchmarks/Benchmarks.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotty.tools.benchmarks
22

3+
import dotty.tools.StdLibSources
34
import org.scalameter.Key.reports._
45
import org.scalameter.PerformanceTest.OnlineRegressionReport
56
import org.scalameter.api._
@@ -47,13 +48,7 @@ object BenchTests extends OnlineRegressionReport {
4748

4849
val dottyDir = "../compiler/src/dotty/"
4950

50-
val stdlibFiles = Source.fromFile("../compiler/test/dotc/scala-collections.whitelist", "UTF8").getLines()
51-
.map(_.trim) // allow identation
52-
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
53-
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
54-
.filter(_.nonEmpty)
55-
.map("." + _)
56-
.toList
51+
val stdlibFiles = StdLibSources.whitelisted
5752

5853
def stdLib = compiler.compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode)
5954

compiler/test/dotc/tests.scala

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotc
22

33
import dotty.Jars
44
import dotty.tools.dotc.CompilerTest
5+
import dotty.tools.StdLibSources
56
import org.junit.{Before, Test}
67
import org.junit.Assert._
78

@@ -201,46 +202,33 @@ class tests extends CompilerTest {
201202

202203
@Test def run_all = runFiles(runDir)
203204

204-
def loadList(path: String) = Source.fromFile(path, "UTF8").getLines()
205-
.map(_.trim) // allow identation
206-
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
207-
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
208-
.filter(_.nonEmpty)
209-
.toList
210-
211-
private def stdlibWhitelistFile = "./test/dotc/scala-collections.whitelist"
212-
private def stdlibBlackFile = "./test/dotc/scala-collections.blacklist"
213-
214-
private val stdlibFiles: List[String] = loadList(stdlibWhitelistFile)
205+
private val stdlibFiles: List[String] = StdLibSources.whitelisted
215206

216207
@Test def checkWBLists = {
217-
val stdlibFilesBlackListed = loadList(stdlibBlackFile)
208+
import StdLibSources.{whitelistFile, blacklistFile}
209+
210+
val stdlibFilesBlackListed = StdLibSources.blacklisted
218211

219212
def checkForRepeated(list: List[String], listFile: String) = {
220213
val duplicates = list.groupBy(x => x).filter(_._2.size > 1).filter(_._2.size > 1)
221214
val msg = duplicates.map(x => s"'${x._1}' appears ${x._2.size} times").mkString(s"Duplicate entries in $listFile:\n", "\n", "\n")
222215
assertTrue(msg, duplicates.isEmpty)
223216
}
224-
checkForRepeated(stdlibFiles, stdlibWhitelistFile)
225-
checkForRepeated(stdlibFilesBlackListed, stdlibBlackFile)
217+
checkForRepeated(stdlibFiles, whitelistFile)
218+
checkForRepeated(stdlibFilesBlackListed, blacklistFile)
226219

227220
val whitelistSet = stdlibFiles.toSet
228221
val blacklistSet = stdlibFilesBlackListed.toSet
229222

230223
val intersection = whitelistSet.intersect(blacklistSet)
231224
val msgIntersection =
232-
intersection.map(x => s"'$x'").mkString(s"Entries where found in both $stdlibWhitelistFile and $stdlibBlackFile:\n", "\n", "\n")
225+
intersection.map(x => s"'$x'").mkString(s"Entries where found in both $whitelistFile and $blacklistFile:\n", "\n", "\n")
233226
assertTrue(msgIntersection, intersection.isEmpty)
234227

235-
def collectAllFilesInDir(dir: JFile, acc: List[String]): List[String] = {
236-
val files = dir.listFiles()
237-
val acc2 = files.foldLeft(acc)((acc1, file) => if (file.isFile && file.getPath.endsWith(".scala")) file.getPath :: acc1 else acc1)
238-
files.foldLeft(acc2)((acc3, file) => if (file.isDirectory) collectAllFilesInDir(file, acc3) else acc3)
239-
}
240-
val filesInStdLib = collectAllFilesInDir(new JFile("../scala-scala/src/library/"), Nil)
228+
val filesInStdLib = StdLibSources.all
241229
val missingFiles = filesInStdLib.toSet -- whitelistSet -- blacklistSet
242230
val msgMissing =
243-
missingFiles.map(x => s"'$x'").mkString(s"Entries are missing in $stdlibWhitelistFile or $stdlibBlackFile:\n", "\n", "\n")
231+
missingFiles.map(x => s"'$x'").mkString(s"Entries are missing in $whitelistFile or $blacklistFile:\n", "\n", "\n")
244232
assertTrue(msgMissing, missingFiles.isEmpty)
245233
}
246234

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dotty.tools
2+
3+
import java.io.File
4+
5+
import scala.io.Source
6+
7+
object StdLibSources {
8+
9+
def whitelistFile: String = "./test/dotc/scala-collections.whitelist"
10+
def blacklistFile: String = "./test/dotc/scala-collections.blacklist"
11+
12+
def whitelisted: List[String] = loadList(whitelistFile)
13+
def blacklisted: List[String] = loadList(blacklistFile)
14+
15+
def all: List[String] = {
16+
def collectAllFilesInDir(dir: File, acc: List[String]): List[String] = {
17+
val files = dir.listFiles()
18+
val acc2 = files.foldLeft(acc)((acc1, file) => if (file.isFile && file.getPath.endsWith(".scala")) file.getPath :: acc1 else acc1)
19+
files.foldLeft(acc2)((acc3, file) => if (file.isDirectory) collectAllFilesInDir(file, acc3) else acc3)
20+
}
21+
collectAllFilesInDir(new File("../scala-scala/src/library/"), Nil)
22+
}
23+
24+
private def loadList(path: String): List[String] = Source.fromFile(path, "UTF8").getLines()
25+
.map(_.trim) // allow identation
26+
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
27+
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
28+
.filter(_.nonEmpty)
29+
.toList
30+
31+
}

doc-tool/test/WhitelistedStdLib.scala

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ package dottydoc
44
import org.junit.Test
55
import org.junit.Assert._
66

7-
class TestWhitelistedCollections extends DottyTest {
8-
val files: List[String] = {
9-
val whitelist = "./test/dotc/scala-collections.whitelist"
10-
11-
scala.io.Source.fromFile(whitelist, "UTF8")
12-
.getLines()
13-
.map(_.trim) // allow identation
14-
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
15-
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
16-
.filter(_.nonEmpty)
17-
.filterNot(_.endsWith("package.scala"))
18-
.toList
19-
}
7+
class WhitelistedStdLib extends DottyTest {
8+
val files: List[String] =
9+
StdLibSources.whitelisted.filterNot(_.endsWith("package.scala"))
2010

2111
@Test def arrayHasDocumentation =
2212
checkFiles(files) { packages =>

0 commit comments

Comments
 (0)