testthat :: allow_silent () работает не так, как я ожидал, почему? - PullRequest
0 голосов
/ 12 апреля 2019

Я написал два простых теста для этой функции 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
...