airframe icon indicating copy to clipboard operation
airframe copied to clipboard

Scalamock with LogSupport fail to compile

Open yoyama opened this issue 6 years ago • 2 comments

Scalamock with LogSupport cause the compilation error as follows.

  • airframe 19.10.1
  • scalamock 4.4.0
import org.scalamock.scalatest.MockFactory
import wvlet.log.LogSupport

class Target extends LogSupport

class TargetTest extends MockFactory {
  val t = mock[Target]
}
[error] /Users/youy/workspace1/digdag-client-scala/digdag-client/src/test/scala/io/github/yoyama/digdag/client/MockTest.scala:9:15: overriding macro method logAt in trait LoggingMethods of type (logLevel: wvlet.log.LogLevel, message: Any)Unit;
[error]  method logAt cannot be used here - only term macros can override term macros
[error]   val t = mock[Target]

yoyama avatar Oct 27 '19 08:10 yoyama

It looks like a bug of ScalaMock as LogSupport.logAt is just a protected-def macro. Generally speaking, mock implementation should not override any def-macros, which will be expanded at compile time.

xerial avatar Oct 27 '19 09:10 xerial

For example, mockit has no such issue:

leo@TD-0504:~/work/git/airframe> amm                                                                                                                          [18:46:00 Oct 24 2019]
Loading...
Welcome to the Ammonite Repl 1.6.9
(Scala 2.12.8 Java 11.0.4)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $ivy.`org.wvlet.airframe::airframe-log:19.10.1`, wvlet.log._
import $ivy.$                                         , wvlet.log._

@ import $ivy.`org.mockito:mockito-all:1.10.19`, org.mockito.Mockito._
import $ivy.$                                , org.mockito.Mockito._

@ class Target extends LogSupport
defined class Target

@ class A { val a = mock(classOf[Target]) }
defined class A

xerial avatar Oct 27 '19 09:10 xerial