@@ -11,15 +11,15 @@ import org.junit.Assert._
1111
1212trait ErrorMessagesTest extends DottyTest {
1313
14- ctx = freshReporter(ctx)
15-
16- private def freshReporter (ctx : Context ) =
17- ctx.fresh.setReporter(new CapturingReporter )
14+ private def newContext = {
15+ val rep = new StoreReporter (null )
16+ with UniqueMessagePositions with HideNonSensicalMessages
17+ initialCtx.setReporter(rep)
18+ }
1819
1920 class Report (messages : List [Message ], ictx : Context ) {
20- def expect (f : (Context , List [Message ]) => Unit ): Unit = {
21+ def expect (f : (Context , List [Message ]) => Unit ): Unit =
2122 f(ictx, messages)
22- }
2323
2424 def expectNoErrors : Unit =
2525 assert(this .isInstanceOf [EmptyReport ], " errors found when not expected" )
@@ -32,35 +32,16 @@ trait ErrorMessagesTest extends DottyTest {
3232 |there are no errors or the compiler crashes.""" .stripMargin)
3333 }
3434
35- class CapturingReporter extends Reporter
36- with UniqueMessagePositions with HideNonSensicalMessages {
37- private [this ] val buffer = new mutable.ListBuffer [Message ]
38- private [this ] var capturedContext : Context = _
39-
40- def doReport (m : MessageContainer )(implicit ctx : Context ) = {
41- capturedContext = ctx
42- buffer append m.contained()
43- }
44-
45- def toReport : Report =
46- if (capturedContext eq null )
47- new EmptyReport
48- else {
49- val xs = buffer.reverse.toList
50- buffer.clear()
51-
52- val ctx = capturedContext
53- capturedContext = null
54-
55- new Report (xs, ctx)
56- }
57- }
58-
5935 def checkMessagesAfter (checkAfterPhase : String )(source : String ): Report = {
60- checkCompile(checkAfterPhase, source) { (_,ictx) => () }
61- val rep = ctx.reporter.asInstanceOf [CapturingReporter ].toReport
62- ctx = freshReporter(ctx)
63- rep
36+ ctx = newContext
37+ val runCtx = checkCompile(checkAfterPhase, source) { (_, _) => () }
38+
39+ if (! runCtx.reporter.hasErrors) new EmptyReport
40+ else {
41+ val rep = runCtx.reporter.asInstanceOf [StoreReporter ]
42+ val msgs = rep.removeBufferedMessages(runCtx).map(_.contained()).reverse
43+ new Report (msgs, runCtx)
44+ }
6445 }
6546
6647 def assertMessageCount (expected : Int , messages : List [Message ]): Unit =
0 commit comments