testthat :: expect_silent()无法正常工作,为什么?

时间:2019-04-12 15:47:48

标签: r devtools side-effects testthat

我为此功能stop_quietly()编写了两个简单的测试:

stop_quietly <- function() {
  # https://stackoverflow.com/questions/14469522/stop-an-r-program-without-error
  opt <- options(show.error.messages = FALSE)
  on.exit(options(opt))
  stop()
}

以下是测试:

test_that('stop_quietly', {
  expect_silent(stop_quietly())
  expect_error(stop_quietly())
})

但是expect_silent测试失败,我不明白为什么。 test-sure.R是包含此单元测试的文件。这是devtools::test(filter = 'sure')的输出:

> devtools::test(filter = 'sure')
Loading gwasrapidd
Testing gwasrapidd
✔ | OK F W S | Context
✖ |  0 1     | test-sure
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
test-sure.R:4: error: stop_quietly

1: expect_silent(stop_quietly()) at /home/rmagno/sci/code/R/pkg/gwasrapidd/tests/testthat/test-sure.R:4
2: quasi_capture(enquo(object), evaluate_promise)
3: capture(act$val <- eval_bare(get_expr(quo), get_env(quo)))
4: withr::with_output_sink(temp, withCallingHandlers(withVisible(code), warning = handle_warning, message = handle_message))
5: force(code)
6: withCallingHandlers(withVisible(code), warning = handle_warning, message = handle_message)
7: withVisible(code)
8: eval_bare(get_expr(quo), get_env(quo))
9: stop_quietly()
10: stop() at /home/rmagno/sci/code/R/pkg/gwasrapidd/R/sure.R:10

0 个答案:

没有答案