mirror of https://github.com/sbt/sbt.git
Merge pull request #158 from dwijnand/StringTypeTag-opt-test-enforcement
Enforce invariant in StringTypeTag optimisation
This commit is contained in:
commit
a0ef0c02d9
|
|
@ -62,20 +62,21 @@ sealed abstract class LogExchange {
|
|||
config.getLoggerConfig(loggerName)
|
||||
}
|
||||
|
||||
// Construct these StringTypeTags manually, because they're used at the very startup of sbt
|
||||
// and we'll try not to initialize the universe by using the StringTypeTag.apply that requires a TypeTag
|
||||
// A better long-term solution could be to make StringTypeTag.apply a macro.
|
||||
lazy val stringTypeTagThrowable = StringTypeTag[Throwable]("scala.Throwable")
|
||||
lazy val stringTypeTagTraceEvent = StringTypeTag[TraceEvent]("sbt.internal.util.TraceEvent")
|
||||
lazy val stringTypeTagSuccessEvent = StringTypeTag[SuccessEvent]("sbt.internal.util.SuccessEvent")
|
||||
|
||||
private[sbt] def initStringCodecs(): Unit = {
|
||||
import sbt.internal.util.codec.ThrowableShowLines._
|
||||
import sbt.internal.util.codec.TraceEventShowLines._
|
||||
import sbt.internal.util.codec.SuccessEventShowLines._
|
||||
|
||||
// Register these StringCodecs manually, because this method will be called at the very startup of sbt
|
||||
// and we'll try not to initialize the universe in StringTypeTag.apply
|
||||
// If these classes are moved around, both the fully qualified names and the strings need to be adapted.
|
||||
// A better long-term solution could be to make StringTypeTag.apply a macro.
|
||||
registerStringCodecByStringTypeTag[_root_.scala.Throwable](StringTypeTag("scala.Throwable"))
|
||||
registerStringCodecByStringTypeTag[_root_.sbt.internal.util.TraceEvent](
|
||||
StringTypeTag("sbt.internal.util.TraceEvent"))
|
||||
registerStringCodecByStringTypeTag[_root_.sbt.internal.util.SuccessEvent](
|
||||
StringTypeTag("sbt.internal.util.SuccessEvent"))
|
||||
registerStringCodecByStringTypeTag(stringTypeTagThrowable)
|
||||
registerStringCodecByStringTypeTag(stringTypeTagTraceEvent)
|
||||
registerStringCodecByStringTypeTag(stringTypeTagSuccessEvent)
|
||||
}
|
||||
|
||||
// This is a dummy layout to avoid casting error during PatternLayout.createDefaultLayout()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package sbt.util
|
||||
|
||||
import sbt.internal.util._
|
||||
|
||||
import org.scalatest._
|
||||
|
||||
class LogExchangeSpec extends FlatSpec with Matchers {
|
||||
import LogExchange._
|
||||
|
||||
checkTypeTag("stringTypeTagThrowable", stringTypeTagThrowable, StringTypeTag[Throwable])
|
||||
checkTypeTag("stringTypeTagTraceEvent", stringTypeTagTraceEvent, StringTypeTag[TraceEvent])
|
||||
checkTypeTag("stringTypeTagSuccessEvent", stringTypeTagSuccessEvent, StringTypeTag[SuccessEvent])
|
||||
|
||||
private def checkTypeTag[A, B](name: String, actual: A, expected: B): Unit =
|
||||
s"LogExchange.$name" should s"match real StringTypeTag[$expected]" in assert(actual == expected)
|
||||
}
|
||||
Loading…
Reference in New Issue