Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
处理生成警告但又返回值的调用的最佳方法是什么?
例如
> require(testthat) > expect_warning(log(-1)) > expect_equal(log(-1), NaN) Warning message: In log(-1) : NaNs produced
我想编写测试,以便对 log(-1) 的调用应该(a)生成警告和(b)返回值 NaN。上面的方法有效,但看到底部的“警告信息:”可能会使人们感到困惑。我应该暂时禁止警告吗?
require(testthat) expect_warning(val <- log(-1)) expect_true(is.nan(val))