测试不赞成使用的Scala函数时,如何抑制不赞成使用警告? [英] How to suppress deprecation warnings when testing deprecated Scala functions?

查看:85
本文介绍了测试不赞成使用的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()

如何避免警告?

推荐答案

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.

这篇关于测试不赞成使用的Scala函数时,如何抑制不赞成使用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆