From 5bd99fc8c862bed33f0be0f7c05e1037bebf05a1 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Mar 2017 11:09:22 +0100 Subject: Remove verbose prints in dottydoc tests --- doc-tool/test/DottyDocTest.scala | 40 +++++++++++++++++++++++++++++++++-- doc-tool/test/WhitelistedStdLib.scala | 8 +++---- 2 files changed, 41 insertions(+), 7 deletions(-) (limited to 'doc-tool') 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") -- cgit v1.2.3