Make the DelegatingReporter aware of -nowarn

The test case compiles a project without and with this
setting and checks that a warning is and isn't emitted
respectively.

It's a multi-project build; this bug didn't seem to turn
up in a single-project build.
This commit is contained in:
Jason Zaugg 2013-09-01 16:32:31 +02:00 committed by Mark Harrah
parent d1c68295c0
commit c4efcc4df7
6 changed files with 52 additions and 4 deletions

View File

@ -23,4 +23,7 @@ object Command
def getWarnFatal(settings: Settings): Boolean =
settings.Xwarnfatal.value
def getNoWarn(settings: Settings): Boolean =
settings.nowarn.value
}

View File

@ -9,13 +9,13 @@ package xsbt
private object DelegatingReporter
{
def apply(settings: scala.tools.nsc.Settings, delegate: xsbti.Reporter): DelegatingReporter =
new DelegatingReporter(Command.getWarnFatal(settings), delegate)
new DelegatingReporter(Command.getWarnFatal(settings), Command.getNoWarn(settings), delegate)
}
// The following code is based on scala.tools.nsc.reporters.{AbstractReporter, ConsoleReporter}
// Copyright 2002-2009 LAMP/EPFL
// Original author: Martin Odersky
private final class DelegatingReporter(warnFatal: Boolean, private[this] var delegate: xsbti.Reporter) extends scala.tools.nsc.reporters.Reporter
private final class DelegatingReporter(warnFatal: Boolean, noWarn: Boolean, private[this] var delegate: xsbti.Reporter) extends scala.tools.nsc.reporters.Reporter
{
import scala.tools.nsc.util.{FakePos,NoPosition,Position}
@ -36,8 +36,11 @@ private final class DelegatingReporter(warnFatal: Boolean, private[this] var del
}
protected def info0(pos: Position, msg: String, rawSeverity: Severity, force: Boolean)
{
val severity = if(warnFatal && rawSeverity == WARNING) ERROR else rawSeverity
delegate.log(convert(pos), msg, convert(severity))
val skip = rawSeverity == WARNING && noWarn
if (!skip) {
val severity = if(warnFatal && rawSeverity == WARNING) ERROR else rawSeverity
delegate.log(convert(pos), msg, convert(severity))
}
}
def convert(posIn: Position): xsbti.Position =
{

View File

@ -0,0 +1,24 @@
lazy val sub1 = project
lazy val sub2 = project
val assertNoWarning = taskKey[Unit]("checks warning *is not* emitted")
val assertWarning = taskKey[Unit]("checks warning *is* emitted")
def check(expectation: Boolean) = Def.task[Unit] {
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
val last: String = IO.read(lastLog)
val contains = last.contains("a pure expression does nothing in statement position")
if (expectation && !contains)
sys.error("compiler output does not contain warning")
else if (!expectation && contains)
sys.error(s"compiler output still contains warning")
else {
IO.write(lastLog, "") // clear the backing log for for 'last'.
}
}
assertWarning <<= check(true)
assertNoWarning <<= check(false)

View File

@ -0,0 +1,6 @@
object warney {
def foo = {
0
0
}
}

View File

@ -0,0 +1 @@
object sub2

View File

@ -0,0 +1,11 @@
> compile
> assertWarning
> 'set every scalacOptions := Seq("-nowarn")'
> clean
> compile
> assertNoWarning