aboutsummaryrefslogtreecommitdiff
path: root/doc-tool
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-03-21 11:09:22 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-03-29 10:33:25 +0200
commit5bd99fc8c862bed33f0be0f7c05e1037bebf05a1 (patch)
treede708977efbc16069c74b755632ee8595972f0f7 /doc-tool
parent52488dae47d7c17dbac36c5d1d985e2a81ebe9de (diff)
downloaddotty-5bd99fc8c862bed33f0be0f7c05e1037bebf05a1.tar.gz
dotty-5bd99fc8c862bed33f0be0f7c05e1037bebf05a1.tar.bz2
dotty-5bd99fc8c862bed33f0be0f7c05e1037bebf05a1.zip
Remove verbose prints in dottydoc tests
Diffstat (limited to 'doc-tool')
-rw-r--r--doc-tool/test/DottyDocTest.scala40
-rw-r--r--doc-tool/test/WhitelistedStdLib.scala8
2 files changed, 41 insertions, 7 deletions
diff --git a/doc-tool/test/DottyDocTest.scala b/doc-tool/test/DottyDocTest.scala
index 4202dca73..9e7b70c8f 100644
--- a/doc-tool/test/DottyDocTest.scala
+++ b/doc-tool/test/DottyDocTest.scala
@@ -9,8 +9,13 @@ import dotc.typer.FrontEnd
import dottydoc.core.{ DocASTPhase, ContextDottydoc }
import model.Package
import dotty.tools.dottydoc.util.syntax._
+import dotc.reporting.{ StoreReporter, MessageRendering }
+import dotc.interfaces.Diagnostic.ERROR
+import org.junit.Assert.fail
-trait DottyDocTest {
+import java.io.{ BufferedWriter, OutputStreamWriter }
+
+trait DottyDocTest extends MessageRendering {
dotty.tools.dotc.parsing.Scanners // initialize keywords
implicit val ctx: FreshContext = {
@@ -26,6 +31,7 @@ trait DottyDocTest {
ctx.settings.classpath,
dotty.Jars.dottyLib
)
+ ctx.setReporter(new StoreReporter(ctx.reporter))
base.initialize()(ctx)
ctx
}
@@ -36,17 +42,47 @@ trait DottyDocTest {
def phaseName = "assertionPhase"
override def run(implicit ctx: Context): Unit =
assertion(ctx.docbase.packages)
+ if (ctx.reporter.hasErrors) {
+ System.err.println("reporter had errors:")
+ ctx.reporter.removeBufferedMessages.foreach { msg =>
+ System.err.println {
+ messageAndPos(msg.contained, msg.pos, diagnosticLevel(msg))
+ }
+ }
+ }
}) :: Nil
override def phases =
super.phases ++ assertionPhase
}
+ private def callingMethod: String =
+ Thread.currentThread.getStackTrace.find {
+ _.getMethodName match {
+ case "checkSource" | "callingMethod" | "getStackTrace" | "currentThread" =>
+ false
+ case _ =>
+ true
+ }
+ }
+ .map(_.getMethodName)
+ .getOrElse {
+ throw new IllegalStateException("couldn't get calling method via reflection")
+ }
+
+ private def sourceFileFromString(name: String, contents: String): SourceFile = {
+ val virtualFile = new scala.reflect.io.VirtualFile(name)
+ val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
+ writer.write(contents)
+ writer.close()
+ new SourceFile(virtualFile, scala.io.Codec.UTF8)
+ }
+
def checkSource(source: String)(assertion: Map[String, Package] => Unit): Unit = {
val c = compilerWithChecker(assertion)
c.rootContext(ctx)
val run = c.newRun
- run.compile(source)
+ run.compileSources(sourceFileFromString(callingMethod, source) :: Nil)
}
def checkFiles(sources: List[String])(assertion: Map[String, Package] => Unit): Unit = {
diff --git a/doc-tool/test/WhitelistedStdLib.scala b/doc-tool/test/WhitelistedStdLib.scala
index 9092d1ded..d59457605 100644
--- a/doc-tool/test/WhitelistedStdLib.scala
+++ b/doc-tool/test/WhitelistedStdLib.scala
@@ -6,18 +6,16 @@ import org.junit.Assert._
class TestWhitelistedCollections extends DottyDocTest {
- @Test def arrayHasDocumentation =
+ @Test def arrayAndImmutableHasDocumentation =
checkFiles(TestWhitelistedCollections.files) { packages =>
val array =
packages("scala")
.children.find(_.path.mkString(".") == "scala.Array")
.get
- assert(array.comment.get.body.length > 0)
- }
+ assert(array.comment.get.body.length > 0,
+ "scala.Array didn't have any documentation")
- @Test def traitImmutableHasDocumentation =
- checkFiles(TestWhitelistedCollections.files) { packages =>
val imm =
packages("scala")
.children.find(_.path.mkString(".") == "scala.Immutable")