tests/testthat/test_invoke.R

test_that("invoke", {
  expect_equal(invoke(identity, .args = list(1L)), 1L)

  foo = function(x, y) x + y

  expect_equal(invoke(foo, .args = list(x = 1, y = 2)), 3)
  expect_equal(invoke(foo, .args = list(x = 1), y = 2), 3)
  expect_equal(invoke(foo, x = 1, y = 2), 3)

  f = function(x) warning("foo")
  prev_warn = getOption("warn")
  expect_warning(f(1))
  expect_warning(invoke(f, 1))
  expect_error(invoke(f, 1, .opts = list(warn = 2)))
  expect_equal(getOption("warn"), prev_warn)
})
mlr-org/mlr3misc documentation built on April 13, 2024, 3:37 p.m.