Skip to content

Upgrade 2.13 #162

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 4 commits into from
May 28, 2019
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: scala
scala:
- 2.12.8
- 2.11.12
- 2.13.0-M5
- 2.13.0-RC2
env:
- JDK=oraclejdk8
- JDK=openjdk8
Expand Down
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ scalacOptions ++= List(
"-encoding", "UTF-8"
)

// TODO: drop when RC2 artifacts are available for mockito (or 2.13.0 final)
conflictWarning := ConflictWarning.disable

osgiSettings

OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging"
Expand Down
12 changes: 7 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import sbt._

object Version {
val logback = "1.2.3"
val mockito = "1.10.19"
val mockito = "1.4.6"
val scala = "2.12.8"
val crossScala = List(scala, "2.11.12", "2.13.0-M5")
val scalaTest = "3.0.6-SNAP6" // only version available for 2.13.0-M4
val crossScala = List(scala, "2.11.12", "2.13.0-RC2")
val scalaTest = "3.0.8-RC4"
val slf4j = "1.7.26"
}

object Library {
val logbackClassic = "ch.qos.logback" % "logback-classic" % Version.logback
val mockitoAll = "org.mockito" % "mockito-all" % Version.mockito
def mockitoScala(v: String) =
if (v == "2.13.0-RC2") "org.mockito" % "mockito-scala_2.13.0-RC1" % Version.mockito // TODO: drop when RC2 artifacts are available (or 2.13.0 final)
else "org.mockito" %% "mockito-scala" % Version.mockito
def scalaReflect(scalaVersion: String) = "org.scala-lang" % "scala-reflect" % scalaVersion
val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest
val slf4jApi = "org.slf4j" % "slf4j-api" % Version.slf4j
Expand All @@ -24,7 +26,7 @@ object Dependencies {
scalaReflect(scalaVersion),
slf4jApi,
logbackClassic % "test",
mockitoAll % "test",
mockitoScala(scalaVersion) % "test",
scalaTest % "test"
)
}
18 changes: 16 additions & 2 deletions src/main/scala/com/typesafe/scalalogging/LoggerMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,23 @@ private object LoggerMacro {

/** Checks whether `message` is an interpolated string and transforms it into SLF4J string interpolation. */
private def deconstructInterpolatedMessage(c: LoggerContext)(message: c.Expr[String]) = {
import c.universe._
val u: c.universe.type = c.universe
// Eww; gross! In 2.13, the `s` interpolator on StringContext became a macro, so we have to look at the pre-macro
// expansion tree to recover what the user wrote...
val tree: u.Tree = {
// ... but there's no way to do that within scala.reflect.api!
// Worse, MacroExpansionAttachment is in scala-compiler, not scala-reflect, so we don't even have it on the compilation classpath.
// Hence, getClass.getSimplename....
val uInternal = u.asInstanceOf[scala.reflect.internal.SymbolTable]
import uInternal._
message.tree.asInstanceOf[uInternal.Tree].attachments.all.collect {
case orig if orig.getClass.getSimpleName == "MacroExpansionAttachment" => orig.asInstanceOf[{ def expandee: Tree }].expandee.asInstanceOf[u.Tree]
}.headOption.getOrElse(message.tree)
}

import u._

message.tree match {
tree match {
case q"scala.StringContext.apply(..$parts).s(..$args)" =>
val format = parts.iterator.map({ case Literal(Constant(str: String)) => str })
// Emulate standard interpolator escaping
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/scalalogging/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ package object scalalogging {
type Seq[+A] = scala.collection.immutable.Seq[A]

type IndexedSeq[+A] = scala.collection.immutable.IndexedSeq[A]

}
62 changes: 34 additions & 28 deletions src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ package com.typesafe.scalalogging

import java.io._

import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.slf4j.{ Logger => Underlying }
import org.scalatest.{ Matchers, WordSpec }
import org.scalatest.mockito.MockitoSugar

class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
trait Varargs {
// TODO: we used to wrap in List(...): _*, which I assume was to force the varags method to be chosen.
// I encapsulated that here in something that works across 2.12/2.13.
def forceVarargs[T](xs: T*): scala.Seq[T] = scala.Seq(xs: _*)
}

class LoggerSpec extends WordSpec with Matchers with MockitoSugar with Varargs {

// Error

Expand Down Expand Up @@ -58,7 +64,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isErrorEnabled, isEnabled = true)
import f._
logger.error(s"msg $arg1 $arg2")
verify(underlying).error("msg {} {}", List(arg1, arg2): _*)
verify(underlying).error("msg {} {}", forceVarargs(arg1, arg2): _*)
}

}
Expand Down Expand Up @@ -86,9 +92,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isErrorEnabled, isEnabled = true)
import f._
logger.error(msg, arg1)
verify(underlying).error(msg, List(arg1): _*)
verify(underlying).error(msg, arg1)
logger.error(msg, arg1, arg2)
verify(underlying).error(msg, List(arg1, arg2): _*)
verify(underlying).error(msg, forceVarargs(arg1, arg2): _*)
logger.error(msg, arg1, arg2, arg3)
verify(underlying).error(msg, arg1, arg2, arg3)
}
Expand All @@ -97,9 +103,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isErrorEnabled, isEnabled = false)
import f._
logger.error(msg, arg1)
verify(underlying, never).error(msg, List(arg1): _*)
verify(underlying, never).error(msg, arg1)
logger.error(msg, arg1, arg2)
verify(underlying, never).error(msg, List(arg1, arg2): _*)
verify(underlying, never).error(msg, forceVarargs(arg1, arg2): _*)
logger.error(msg, arg1, arg2, arg3)
verify(underlying, never).error(msg, arg1, arg2, arg3)
}
Expand Down Expand Up @@ -137,7 +143,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isWarnEnabled, isEnabled = true)
import f._
logger.warn(s"msg $arg1 $arg2")
verify(underlying).warn("msg {} {}", List(arg1, arg2): _*)
verify(underlying).warn("msg {} {}", forceVarargs(arg1, arg2): _*)
}
}

Expand All @@ -164,9 +170,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isWarnEnabled, isEnabled = true)
import f._
logger.warn(msg, arg1)
verify(underlying).warn(msg, List(arg1): _*)
verify(underlying).warn(msg, arg1)
logger.warn(msg, arg1, arg2)
verify(underlying).warn(msg, List(arg1, arg2): _*)
verify(underlying).warn(msg, forceVarargs(arg1, arg2): _*)
logger.warn(msg, arg1, arg2, arg3)
verify(underlying).warn(msg, arg1, arg2, arg3)
}
Expand All @@ -175,9 +181,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isWarnEnabled, isEnabled = false)
import f._
logger.warn(msg, arg1)
verify(underlying, never).warn(msg, List(arg1): _*)
verify(underlying, never).warn(msg, arg1)
logger.warn(msg, arg1, arg2)
verify(underlying, never).warn(msg, List(arg1, arg2): _*)
verify(underlying, never).warn(msg, forceVarargs(arg1, arg2): _*)
logger.warn(msg, arg1, arg2, arg3)
verify(underlying, never).warn(msg, arg1, arg2, arg3)
}
Expand Down Expand Up @@ -215,7 +221,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isInfoEnabled, isEnabled = true)
import f._
logger.info(s"msg $arg1 $arg2")
verify(underlying).info("msg {} {}", List(arg1, arg2): _*)
verify(underlying).info("msg {} {}", forceVarargs(arg1, arg2): _*)
}
}

Expand All @@ -242,9 +248,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isInfoEnabled, isEnabled = true)
import f._
logger.info(msg, arg1)
verify(underlying).info(msg, List(arg1): _*)
verify(underlying).info(msg, arg1)
logger.info(msg, arg1, arg2)
verify(underlying).info(msg, List(arg1, arg2): _*)
verify(underlying).info(msg, forceVarargs(arg1, arg2): _*)
logger.info(msg, arg1, arg2, arg3)
verify(underlying).info(msg, arg1, arg2, arg3)
}
Expand All @@ -253,9 +259,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isInfoEnabled, isEnabled = false)
import f._
logger.info(msg, arg1)
verify(underlying, never).info(msg, List(arg1): _*)
verify(underlying, never).info(msg, arg1)
logger.info(msg, arg1, arg2)
verify(underlying, never).info(msg, List(arg1, arg2): _*)
verify(underlying, never).info(msg, forceVarargs(arg1, arg2): _*)
logger.info(msg, arg1, arg2, arg3)
verify(underlying, never).info(msg, arg1, arg2, arg3)
}
Expand Down Expand Up @@ -292,7 +298,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isDebugEnabled, isEnabled = true)
import f._
logger.debug(s"msg $arg1 $arg2")
verify(underlying).debug("msg {} {}", List(arg1, arg2): _*)
verify(underlying).debug("msg {} {}", forceVarargs(arg1, arg2): _*)
}
}

Expand All @@ -319,9 +325,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isDebugEnabled, isEnabled = true)
import f._
logger.debug(msg, arg1)
verify(underlying).debug(msg, List(arg1): _*)
verify(underlying).debug(msg, arg1)
logger.debug(msg, arg1, arg2)
verify(underlying).debug(msg, List(arg1, arg2): _*)
verify(underlying).debug(msg, forceVarargs(arg1, arg2): _*)
logger.debug(msg, arg1, arg2, arg3)
verify(underlying).debug(msg, arg1, arg2, arg3)
}
Expand All @@ -330,9 +336,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isDebugEnabled, isEnabled = false)
import f._
logger.debug(msg, arg1)
verify(underlying, never).debug(msg, List(arg1): _*)
verify(underlying, never).debug(msg, arg1)
logger.debug(msg, arg1, arg2)
verify(underlying, never).debug(msg, List(arg1, arg2): _*)
verify(underlying, never).debug(msg, forceVarargs(arg1, arg2): _*)
logger.debug(msg, arg1, arg2, arg3)
verify(underlying, never).debug(msg, arg1, arg2, arg3)
}
Expand Down Expand Up @@ -370,7 +376,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isTraceEnabled, isEnabled = true)
import f._
logger.trace(s"msg $arg1 $arg2")
verify(underlying).trace("msg {} {}", List(arg1, arg2): _*)
verify(underlying).trace("msg {} {}", forceVarargs(arg1, arg2): _*)
}
}

Expand All @@ -397,9 +403,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isTraceEnabled, isEnabled = true)
import f._
logger.trace(msg, arg1)
verify(underlying).trace(msg, List(arg1): _*)
verify(underlying).trace(msg, arg1)
logger.trace(msg, arg1, arg2)
verify(underlying).trace(msg, List(arg1, arg2): _*)
verify(underlying).trace(msg, forceVarargs(arg1, arg2): _*)
logger.trace(msg, arg1, arg2, arg3)
verify(underlying).trace(msg, arg1, arg2, arg3)
}
Expand All @@ -408,9 +414,9 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isTraceEnabled, isEnabled = false)
import f._
logger.trace(msg, arg1)
verify(underlying, never).trace(msg, List(arg1): _*)
verify(underlying, never).trace(msg, arg1)
logger.trace(msg, arg1, arg2)
verify(underlying, never).trace(msg, List(arg1, arg2): _*)
verify(underlying, never).trace(msg, forceVarargs(arg1, arg2): _*)
logger.trace(msg, arg1, arg2, arg3)
verify(underlying, never).trace(msg, arg1, arg2, arg3)
}
Expand Down Expand Up @@ -468,7 +474,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
val f = fixture(_.isErrorEnabled, isEnabled = true)
import f._
logger.error("foo {}, bar {}", arg4, arg5)
verify(underlying).error("foo {}, bar {}", Array(arg4ref, arg5ref): _*)
verify(underlying).error("foo {}, bar {}", forceVarargs(arg4ref, arg5ref): _*)
}

"map args to AnyRef for non 2 args" in {
Expand Down
Loading