@@ -9,8 +9,13 @@ import dotc.typer.FrontEnd
9
9
import dottydoc .core .{ DocASTPhase , ContextDottydoc }
10
10
import model .Package
11
11
import dotty .tools .dottydoc .util .syntax ._
12
+ import dotc .reporting .{ StoreReporter , MessageRendering }
13
+ import dotc .interfaces .Diagnostic .ERROR
14
+ import org .junit .Assert .fail
12
15
13
- trait DottyDocTest {
16
+ import java .io .{ BufferedWriter , OutputStreamWriter }
17
+
18
+ trait DottyDocTest extends MessageRendering {
14
19
dotty.tools.dotc.parsing.Scanners // initialize keywords
15
20
16
21
implicit val ctx : FreshContext = {
@@ -26,6 +31,7 @@ trait DottyDocTest {
26
31
ctx.settings.classpath,
27
32
dotty.Jars .dottyLib
28
33
)
34
+ ctx.setReporter(new StoreReporter (ctx.reporter))
29
35
base.initialize()(ctx)
30
36
ctx
31
37
}
@@ -36,17 +42,47 @@ trait DottyDocTest {
36
42
def phaseName = " assertionPhase"
37
43
override def run (implicit ctx : Context ): Unit =
38
44
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
+ }
39
53
}) :: Nil
40
54
41
55
override def phases =
42
56
super .phases ++ assertionPhase
43
57
}
44
58
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
+
45
81
def checkSource (source : String )(assertion : Map [String , Package ] => Unit ): Unit = {
46
82
val c = compilerWithChecker(assertion)
47
83
c.rootContext(ctx)
48
84
val run = c.newRun
49
- run.compile( source)
85
+ run.compileSources(sourceFileFromString(callingMethod, source) :: Nil )
50
86
}
51
87
52
88
def checkFiles (sources : List [String ])(assertion : Map [String , Package ] => Unit ): Unit = {
0 commit comments