测试不赞成使用的Scala函数时,如何抑制不赞成使用警告?

测试不赞成使用的Scala函数时,如何抑制不赞成使用警告?

问题描述:

假设我有一个包含不推荐使用的函数和首选函数的库:

Suppose I have a library, which contains both a deprecated function and a preferred function:

object MyLib {
  def preferredFunction() = ()
  @deprecated("Use preferredFunction instead", "1.0") def deprecatedFunction() = ()
}

我想同时测试 preferredFunction deprecatedFunction 在ScalaTest中:

I want to test both preferredFunction and deprecatedFunction in ScalaTest:

class MyLibSpec extends FreeSpec with Matchers {
  "preferred function" in {
    MyLib.preferredFunction() should be(())
  }
  "deprecated function" in {
    MyLib.deprecatedFunction() should be(())
  }
}

但是,在 MyLib.deprecatedFunction()$中报告了弃用警告。 c $ c>。

如何避免警告?

Scala不支持,请参见 https://groups.google.com/forum/#!topic/scala-internals/LsycMcEkXiA

Scala does not support that, see https://groups.google.com/forum/#!topic/scala-internals/LsycMcEkXiA

但是其中提到了一个插件:

However there is a plugin mentioned:

https://github.com/ghik/消音器

我没有用过-所以我不确定这是否适合您的情况。

I haven't used it - so I am not sure if this works for your case.