diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-05-05 15:22:29 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-08-19 15:37:22 +0200 |
commit | 8e39b71b29afd7951745dbaf957eade0e9f51434 (patch) | |
tree | 720ab08f15936a8c0cd4cf5da5f792fcdab3150b /dottydoc/jvm/test | |
parent | bc594c81c6ce8c696dde2f7668132952e83b383a (diff) | |
download | dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.tar.gz dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.tar.bz2 dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.zip |
Fix repeated traversal of packages when generating docs (5x speedup)
Diffstat (limited to 'dottydoc/jvm/test')
-rw-r--r-- | dottydoc/jvm/test/BaseTest.scala (renamed from dottydoc/jvm/test/CompilerTest.scala) | 12 | ||||
-rw-r--r-- | dottydoc/jvm/test/PackageStructure.scala | 89 | ||||
-rw-r--r-- | dottydoc/jvm/test/SimpleComments.scala (renamed from dottydoc/jvm/test/TestSimpleComments.scala) | 2 | ||||
-rw-r--r-- | dottydoc/jvm/test/TestWhitelistedStdLib.scala | 17 | ||||
-rw-r--r-- | dottydoc/jvm/test/WhitelistedStdLib.scala | 28 | ||||
-rw-r--r-- | dottydoc/jvm/test/WhitelistedStdLibMain.scala | 23 |
6 files changed, 134 insertions, 37 deletions
diff --git a/dottydoc/jvm/test/CompilerTest.scala b/dottydoc/jvm/test/BaseTest.scala index 001e4d422..2703f8169 100644 --- a/dottydoc/jvm/test/CompilerTest.scala +++ b/dottydoc/jvm/test/BaseTest.scala @@ -3,6 +3,7 @@ package dottydoc import dotc.core.Contexts import Contexts.{ Context, ContextBase, FreshContext } +import dotc.util.SourceFile import dotc.core.Phases.Phase import dotc.typer.FrontEnd import dottydoc.core.Phases.DocPhase @@ -34,17 +35,24 @@ trait DottyTest { Nil } - def checkCompile(source: String)(assertion: DocPhase => Unit): Unit = { + def checkSource(source: String)(assertion: DocPhase => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(source) } - def checkCompile(sources: List[String])(assertion: DocPhase => Unit): Unit = { + def checkFiles(sources: List[String])(assertion: DocPhase => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(sources) } + + def checkSources(sourceFiles: List[SourceFile])(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compileSources(sourceFiles) + } } diff --git a/dottydoc/jvm/test/PackageStructure.scala b/dottydoc/jvm/test/PackageStructure.scala new file mode 100644 index 000000000..af6e52184 --- /dev/null +++ b/dottydoc/jvm/test/PackageStructure.scala @@ -0,0 +1,89 @@ +package dotty.tools +package dottydoc + +import org.junit.Test +import org.junit.Assert._ + +import dotc.util.SourceFile +import model.internal._ + +class PackageStructure extends DottyTest { + @Test def multipleCompilationUnits = { + val source1 = new SourceFile( + "<test>", + """ + |package scala + | + |trait A + """.stripMargin + ) + + val source2 = new SourceFile( + "<test>", + """ + |package scala + | + |trait B + """.stripMargin + ) + + checkSources(source1 :: source2 :: Nil) { doc => + doc.packages("scala") match { + case PackageImpl(_, List(tA, tB), _, _) => + assert( + tA.name == "A" && tB.name == "B", + s"trait A had name '${tA.name}' and trait B had name '${tB.name}'" + ) + case _ => fail("Incorrect package structure after run") + } + } + } + + + @Test def multiplePackages = { + val source1 = new SourceFile( + "<test>", + """ + |package scala + |package collection + | + |trait A + """.stripMargin) + + val source2 = new SourceFile( + "<test>", + """ + |package scala + |package collection + | + |trait B + """.stripMargin) + + checkSources(source1 :: source2 :: Nil) { doc => + doc.packages("scala") match { + case PackageImpl( + "scala", + List(PackageImpl("scala.collection", List(tA, tB), _, _)), + _, _ + ) => + assert( + tA.name == "A" && tB.name == "B", + s"trait A had name '${tA.name}' and trait B had name '${tB.name}'" + ) + + case _ => + fail(s"""Incorrect package structure for 'scala' package: ${doc.packages("scala")}""") + } + + doc.packages("scala.collection") match { + case PackageImpl("scala.collection", List(tA, tB), _, _) => + assert( + tA.name == "A" && tB.name == "B", + s"trait A had name '${tA.name}' and trait B had name '${tB.name}'" + ) + + case _ => fail("Incorrect package structure for 'scala.collection' package") + } + } + } +} diff --git a/dottydoc/jvm/test/TestSimpleComments.scala b/dottydoc/jvm/test/SimpleComments.scala index 48cdecec0..ad9b7b1a6 100644 --- a/dottydoc/jvm/test/TestSimpleComments.scala +++ b/dottydoc/jvm/test/SimpleComments.scala @@ -15,7 +15,7 @@ class TestSimpleComments extends DottyTest { |trait HelloWorld """.stripMargin - checkCompile(source) { doc => + checkSource(source) { doc => val traitCmt = doc .packages("scala") .children.find(_.path.mkString(".") == "scala.HelloWorld") diff --git a/dottydoc/jvm/test/TestWhitelistedStdLib.scala b/dottydoc/jvm/test/TestWhitelistedStdLib.scala deleted file mode 100644 index 763f41370..000000000 --- a/dottydoc/jvm/test/TestWhitelistedStdLib.scala +++ /dev/null @@ -1,17 +0,0 @@ -package dotty.tools -package dottydoc - -import org.junit.Test -import org.junit.Assert._ - -class TestWhitelistedCollections extends DottyTest { - @Test def arrayHasDocumentation = - checkCompile(WhitelistedStandardLib.files) { doc => - val array = doc - .packages("scala") - .children.find(_.path.mkString(".") == "scala.Array") - .get - - assert(array.comment.get.body.length > 0) - } -} diff --git a/dottydoc/jvm/test/WhitelistedStdLib.scala b/dottydoc/jvm/test/WhitelistedStdLib.scala index f4a2f9dc6..bbf0b4c6b 100644 --- a/dottydoc/jvm/test/WhitelistedStdLib.scala +++ b/dottydoc/jvm/test/WhitelistedStdLib.scala @@ -1,23 +1,17 @@ package dotty.tools package dottydoc -import scala.io.Source +import org.junit.Test +import org.junit.Assert._ -object WhitelistedStandardLib extends DottyDoc { - val files: List[String] = { - val whitelist = "../../test/dotc/scala-collections.whitelist" +class TestWhitelistedCollections extends DottyTest { + @Test def arrayHasDocumentation = + checkFiles(WhitelistedStandardLib.files) { doc => + val array = doc + .packages("scala") + .children.find(_.path.mkString(".") == "scala.Array") + .get - 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")) - .map("../." + _) - .toList - } - - override def main(args: Array[String]) = - super.main("-language:Scala2" +: files.toArray) + assert(array.comment.get.body.length > 0) + } } diff --git a/dottydoc/jvm/test/WhitelistedStdLibMain.scala b/dottydoc/jvm/test/WhitelistedStdLibMain.scala new file mode 100644 index 000000000..f4a2f9dc6 --- /dev/null +++ b/dottydoc/jvm/test/WhitelistedStdLibMain.scala @@ -0,0 +1,23 @@ +package dotty.tools +package dottydoc + +import scala.io.Source + +object WhitelistedStandardLib extends DottyDoc { + val files: List[String] = { + val whitelist = "../../test/dotc/scala-collections.whitelist" + + 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")) + .map("../." + _) + .toList + } + + override def main(args: Array[String]) = + super.main("-language:Scala2" +: files.toArray) +} |