Skip to content

Commit dbc4097

Browse files
committed
Remove verbose prints in dottydoc tests
1 parent f444c08 commit dbc4097

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

doc-tool/test/DottyDocTest.scala

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import dotc.typer.FrontEnd
99
import dottydoc.core.{ DocASTPhase, ContextDottydoc }
1010
import model.Package
1111
import dotty.tools.dottydoc.util.syntax._
12+
import dotc.reporting.{ StoreReporter, MessageRendering }
13+
import dotc.interfaces.Diagnostic.ERROR
14+
import org.junit.Assert.fail
1215

13-
trait DottyDocTest {
16+
import java.io.{ BufferedWriter, OutputStreamWriter }
17+
18+
trait DottyDocTest extends MessageRendering {
1419
dotty.tools.dotc.parsing.Scanners // initialize keywords
1520

1621
implicit val ctx: FreshContext = {
@@ -26,6 +31,7 @@ trait DottyDocTest {
2631
ctx.settings.classpath,
2732
dotty.Jars.dottyLib
2833
)
34+
ctx.setReporter(new StoreReporter(ctx.reporter))
2935
base.initialize()(ctx)
3036
ctx
3137
}
@@ -36,17 +42,47 @@ trait DottyDocTest {
3642
def phaseName = "assertionPhase"
3743
override def run(implicit ctx: Context): Unit =
3844
assertion(ctx.docbase.packages)
45+
if (ctx.reporter.hasErrors) {
46+
System.err.println("reporter had errors:")
47+
ctx.reporter.removeBufferedMessages.foreach { msg =>
48+
System.err.println {
49+
messageAndPos(msg.contained, msg.pos, diagnosticLevel(msg))
50+
}
51+
}
52+
}
3953
}) :: Nil
4054

4155
override def phases =
4256
super.phases ++ assertionPhase
4357
}
4458

59+
private def callingMethod: String =
60+
Thread.currentThread.getStackTrace.find {
61+
_.getMethodName match {
62+
case "checkSource" | "callingMethod" | "getStackTrace" | "currentThread" =>
63+
false
64+
case _ =>
65+
true
66+
}
67+
}
68+
.map(_.getMethodName)
69+
.getOrElse {
70+
throw new IllegalStateException("couldn't get calling method via reflection")
71+
}
72+
73+
private def sourceFileFromString(name: String, contents: String): SourceFile = {
74+
val virtualFile = new scala.reflect.io.VirtualFile(name)
75+
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
76+
writer.write(contents)
77+
writer.close()
78+
new SourceFile(virtualFile, scala.io.Codec.UTF8)
79+
}
80+
4581
def checkSource(source: String)(assertion: Map[String, Package] => Unit): Unit = {
4682
val c = compilerWithChecker(assertion)
4783
c.rootContext(ctx)
4884
val run = c.newRun
49-
run.compile(source)
85+
run.compileSources(sourceFileFromString(callingMethod, source) :: Nil)
5086
}
5187

5288
def checkFiles(sources: List[String])(assertion: Map[String, Package] => Unit): Unit = {

doc-tool/test/WhitelistedStdLib.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import org.junit.Assert._
66

77
class TestWhitelistedCollections extends DottyDocTest {
88

9-
@Test def arrayHasDocumentation =
9+
@Test def arrayAndImmutableHasDocumentation =
1010
checkFiles(TestWhitelistedCollections.files) { packages =>
1111
val array =
1212
packages("scala")
1313
.children.find(_.path.mkString(".") == "scala.Array")
1414
.get
1515

16-
assert(array.comment.get.body.length > 0)
17-
}
16+
assert(array.comment.get.body.length > 0,
17+
"scala.Array didn't have any documentation")
1818

19-
@Test def traitImmutableHasDocumentation =
20-
checkFiles(TestWhitelistedCollections.files) { packages =>
2119
val imm =
2220
packages("scala")
2321
.children.find(_.path.mkString(".") == "scala.Immutable")

0 commit comments

Comments
 (0)