Skip to content

Allow multiple calls to checkMessagesAfter in ErrorMessagesTests #2832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/test/dotty/tools/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ trait DottyTest extends ContextEscapeDetection {

dotc.parsing.Scanners // initialize keywords

implicit var ctx: Context = {
implicit var ctx: Context = initialCtx

protected def initialCtx: FreshContext = {
val base = new ContextBase {}
import base.settings._
val ctx = base.initialCtx.fresh
Expand Down Expand Up @@ -55,18 +57,20 @@ trait DottyTest extends ContextEscapeDetection {
}
}

def checkCompile(checkAfterPhase: String, source: String)(assertion: (tpd.Tree, Context) => Unit): Unit = {
def checkCompile(checkAfterPhase: String, source: String)(assertion: (tpd.Tree, Context) => Unit): Context = {
val c = compilerWithChecker(checkAfterPhase)(assertion)
c.rootContext(ctx)
val run = c.newRun
run.compile(source)
run.runContext
}

def checkCompile(checkAfterPhase: String, sources: List[String])(assertion: (tpd.Tree, Context) => Unit): Unit = {
def checkCompile(checkAfterPhase: String, sources: List[String])(assertion: (tpd.Tree, Context) => Unit): Context = {
val c = compilerWithChecker(checkAfterPhase)(assertion)
c.rootContext(ctx)
val run = c.newRun
run.compile(sources)
run.runContext
}

def methType(names: String*)(paramTypes: Type*)(resultType: Type = defn.UnitType) =
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/dotc/ast/DesugarTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DesugarTests extends DottyTest {
)
}

@Test def caseClassHasCorrectMembers =
@Test def caseClassHasCorrectMembers: Unit =
checkCompile("frontend", "case class Foo(x: Int, y: String)") { (tree, context) =>
implicit val ctx = context
val ccTree = tree.find(tree => tree.symbol.name == typeName("Foo")).get
Expand All @@ -38,7 +38,7 @@ class DesugarTests extends DottyTest {
rest.foreach(validSym)
}

@Test def caseClassCompanionHasCorrectMembers =
@Test def caseClassCompanionHasCorrectMembers: Unit =
checkCompile("frontend", "case class Foo(x: Int, y: String)") { (tree, context) =>
implicit val ctx = context
val ccTree = tree.find(tree => tree.symbol.name == termName("Foo")).get
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/ast/TreeInfoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TreeInfoTest extends DottyTest {
import tpd._

@Test
def testDefPath = checkCompile("frontend", "class A { def bar = { val x = { val z = 0; 0} }} ") {
def testDefPath: Unit = checkCompile("frontend", "class A { def bar = { val x = { val z = 0; 0} }} ") {
(tree, context) =>
implicit val ctx = context
val xTree = tree.find(tree => tree.symbol.name == termName("x")).get
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/parsing/DocstringTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait DocstringTest extends DottyTest {
assert(false, s"Couldn't match resulting AST to expected AST in: $x")
}

def checkFrontend(source: String)(docAssert: PartialFunction[Tree[Untyped], Unit]) = {
def checkFrontend(source: String)(docAssert: PartialFunction[Tree[Untyped], Unit]): Unit = {
checkCompile("frontend", source) { (_, ctx) =>
implicit val c: Context = ctx
(docAssert orElse defaultAssertion)(ctx.compilationUnit.untpdTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DocstringTests extends DocstringTest {
checkDocString(t.rawComment.map(_.raw), "/** Hello /* multiple open */ world! */")
}
}
@Test def multipleClassesInPackage = {
@Test def multipleClassesInPackage: Unit = {
val source =
"""
|package a
Expand Down
49 changes: 15 additions & 34 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import org.junit.Assert._

trait ErrorMessagesTest extends DottyTest {

ctx = freshReporter(ctx)

private def freshReporter(ctx: Context) =
ctx.fresh.setReporter(new CapturingReporter)
private def newContext = {
val rep = new StoreReporter(null)
with UniqueMessagePositions with HideNonSensicalMessages
initialCtx.setReporter(rep)
}

class Report(messages: List[Message], ictx: Context) {
def expect(f: (Context, List[Message]) => Unit): Unit = {
def expect(f: (Context, List[Message]) => Unit): Unit =
f(ictx, messages)
}

def expectNoErrors: Unit =
assert(this.isInstanceOf[EmptyReport], "errors found when not expected")
Expand All @@ -32,35 +32,16 @@ trait ErrorMessagesTest extends DottyTest {
|there are no errors or the compiler crashes.""".stripMargin)
}

class CapturingReporter extends Reporter
with UniqueMessagePositions with HideNonSensicalMessages {
private[this] val buffer = new mutable.ListBuffer[Message]
private[this] var capturedContext: Context = _

def doReport(m: MessageContainer)(implicit ctx: Context) = {
capturedContext = ctx
buffer append m.contained()
}

def toReport: Report =
if (capturedContext eq null)
new EmptyReport
else {
val xs = buffer.reverse.toList
buffer.clear()

val ctx = capturedContext
capturedContext = null

new Report(xs, ctx)
}
}

def checkMessagesAfter(checkAfterPhase: String)(source: String): Report = {
checkCompile(checkAfterPhase, source) { (_,ictx) => () }
val rep = ctx.reporter.asInstanceOf[CapturingReporter].toReport
ctx = freshReporter(ctx)
rep
ctx = newContext
val runCtx = checkCompile(checkAfterPhase, source) { (_, _) => () }

if (!runCtx.reporter.hasErrors) new EmptyReport
else {
val rep = runCtx.reporter.asInstanceOf[StoreReporter]
val msgs = rep.removeBufferedMessages(runCtx).map(_.contained()).reverse
new Report(msgs, runCtx)
}
}

def assertMessageCount(expected: Int, messages: List[Message]): Unit =
Expand Down
Loading