summaryrefslogtreecommitdiff
path: root/test/scaladoc
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2011-01-24 14:11:52 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2011-01-24 14:11:52 +0000
commit19b45e964354069137266b101ca06d8541d5d1c3 (patch)
treed407be5104e7a5ca11b73dd23cdf767a38e7ef26 /test/scaladoc
parent3301506556a24a6a08bb2a91b4c1ed02e9617fb9 (diff)
downloadscala-19b45e964354069137266b101ca06d8541d5d1c3.tar.gz
scala-19b45e964354069137266b101ca06d8541d5d1c3.tar.bz2
scala-19b45e964354069137266b101ca06d8541d5d1c3.zip
[scaladoc] Fixed failing test.
Diffstat (limited to 'test/scaladoc')
-rw-r--r--test/scaladoc/IndexTest.scala102
1 files changed, 102 insertions, 0 deletions
diff --git a/test/scaladoc/IndexTest.scala b/test/scaladoc/IndexTest.scala
new file mode 100644
index 0000000000..5e3d02e045
--- /dev/null
+++ b/test/scaladoc/IndexTest.scala
@@ -0,0 +1,102 @@
+import org.scalacheck._
+import org.scalacheck.Prop._
+
+import scala.tools.nsc.doc
+import scala.tools.nsc.doc.html.page.Index
+import java.net.URLClassLoader
+
+object Test extends Properties("Index") {
+
+ def getClasspath = {
+ // these things can be tricky
+ // this test previously relied on the assumption that the current thread's classloader is an url classloader and contains all the classpaths
+ // does partest actually guarantee this? to quote Leonard Nimoy: The answer, of course, is no.
+ // this test _will_ fail again some time in the future.
+ val paths = Thread.currentThread.getContextClassLoader.asInstanceOf[URLClassLoader].getURLs.map(_.getPath)
+ val morepaths = Thread.currentThread.getContextClassLoader.getParent.asInstanceOf[URLClassLoader].getURLs.map(_.getPath)
+ (paths ++ morepaths).mkString(java.io.File.pathSeparator)
+ }
+
+ val docFactory = {
+ val settings = new doc.Settings({Console.err.println(_)})
+
+ settings.classpath.value = getClasspath
+ println(settings.classpath.value)
+
+ val reporter = new scala.tools.nsc.reporters.ConsoleReporter(settings)
+
+ new doc.DocFactory(reporter, settings)
+ }
+
+ val indexModelFactory = doc.model.IndexModelFactory
+
+ def createIndex(path: String): Option[Index] = {
+
+ val maybeUniverse = {
+ //val stream = new java.io.ByteArrayOutputStream
+ //val original = Console.out
+ //Console.setOut(stream)
+
+ val result = docFactory.makeUniverse(List(path))
+
+ // assert(stream.toString == "model contains 2 documentable templates\n")
+ //Console.setOut(original)
+
+ result
+ }
+
+ maybeUniverse match {
+ case Some(universe) => {
+ val index = new Index(universe, indexModelFactory.makeIndex(universe))
+ return Some(index)
+ }
+ case _ => return None
+ }
+
+ }
+
+ property("path") = {
+ createIndex("src/compiler/scala/tools/nsc/doc/html/page/Index.scala") match {
+ case Some(index) =>
+ index.path == List("index.html")
+ case None => false
+ }
+ }
+
+ property("title") = {
+ createIndex("src/compiler/scala/tools/nsc/doc/html/page/Index.scala") match {
+ case Some(index) =>
+ index.title == ""
+
+ case None => false
+ }
+ }
+ property("browser contants a script element") = {
+ createIndex("src/compiler/scala/tools/nsc/doc/html/page/Index.scala") match {
+ case Some(index) =>
+ (index.browser \ "script").size == 1
+
+ case None => false
+ }
+ }
+
+ property("allPackages") = {
+ createIndex("src/compiler/scala/tools/nsc/doc/html/page/Index.scala") match {
+
+ case Some(index) =>
+ index.allPackages.map(_.toString) == List(
+ "scala",
+ "scala.tools",
+ "scala.tools.nsc",
+ "scala.tools.nsc.doc",
+ "scala.tools.nsc.doc.html",
+ "scala.tools.nsc.doc.html.page"
+ )
+
+ case None =>
+ false
+
+ }
+ }
+
+}