Skip to content

Commit

Permalink
Fix test compilerReporter/simple
Browse files Browse the repository at this point in the history
  • Loading branch information
Duhemm committed Oct 28, 2017
1 parent 57f93ac commit b2ff999
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions sbt-dotty/sbt-test/compilerReporter/simple/project/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,29 @@ import Keys._
import KeyRanks.DTask

object Reporter {
import xsbti.{Reporter, Problem, Position, Severity, Maybe}
import xsbti.{Reporter, Problem, Position, Severity}

lazy val check = TaskKey[Unit]("check", "make sure compilation info are forwared to sbt")

// compilerReporter is marked private in sbt
lazy val compilerReporter = TaskKey[Option[xsbti.Reporter]]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask)
lazy val reporter =
Some(new xsbti.Reporter {
lazy val compilerReporter = TaskKey[xsbti.Reporter]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask)

lazy val reporter =
new xsbti.Reporter {
private val buffer = collection.mutable.ArrayBuffer.empty[Problem]
def reset(): Unit = buffer.clear()
def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error)
def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn)
def printSummary(): Unit = println(problems.mkString(System.lineSeparator))
def problems: Array[Problem] = buffer.toArray
def log(pos: Position, msg: String, sev: Severity): Unit = {
object MyProblem extends Problem {
def category: String = null
def severity: Severity = sev
def message: String = msg
def position: Position = pos
override def toString = s"custom: $position:$severity: $message"
}
buffer.append(MyProblem)
}
def log(problem: Problem): Unit = buffer.append(problem)
def comment(pos: xsbti.Position, msg: String): Unit = ()
})
}

lazy val checkSettings = Seq(
compilerReporter in (Compile, compile) := reporter,
check <<= (compile in Compile).mapFailure( _ => {
val problems = reporter.get.problems
check := (compile in Compile).failure.map(_ => {
val problems = reporter.problems
println(problems.toList)
assert(problems.size == 1)

Expand All @@ -43,6 +34,6 @@ object Reporter {
// assert(problems.forall(_.position.offset.isDefined))

assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1,
})
}).value
)
}

0 comments on commit b2ff999

Please sign in to comment.