@@ -11,15 +11,15 @@ import org.junit.Assert._
11
11
12
12
trait ErrorMessagesTest extends DottyTest {
13
13
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
+ }
18
19
19
20
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 =
21
22
f(ictx, messages)
22
- }
23
23
24
24
def expectNoErrors : Unit =
25
25
assert(this .isInstanceOf [EmptyReport ], " errors found when not expected" )
@@ -32,35 +32,16 @@ trait ErrorMessagesTest extends DottyTest {
32
32
|there are no errors or the compiler crashes.""" .stripMargin)
33
33
}
34
34
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
-
59
35
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
+ }
64
45
}
65
46
66
47
def assertMessageCount (expected : Int , messages : List [Message ]): Unit =
0 commit comments