tests/testthat/test-supp_warnings.R

library(testthat)

test_that("supp_warnings blocks specific warnings from specific functions",{

  expect_warning(
    supp_warnings(
      expr = {
        warning("warn", call. = FALSE)
      },
      mess = "warn",
      fun = "test"
    ),
    "warn"
  )

  test <- function(){
    warning("warn", call. = TRUE)
  }

  expect_no_warning(
    supp_warnings(
      expr = test(),
      mess = "warn",
      fun = "test"
    )
  )

  test <- function(){
    warning("warn2", call. = FALSE)
  }

  expect_warning(
    supp_warnings(
      expr = test(),
      mess = "warn",
      fun = "test"
    )
  )


  test2 <- function(){
    warning("warn2", call. = TRUE)
  }
  test <- function(){
    warning("warn", call. = TRUE)
    test2()

  }

  expect_no_warning(
    supp_warnings(
      expr = test(),
      mess = c("warn", "warn2"),
      fun = c("test", "test2")
    )
  )

  expect_warning(
    supp_warnings(
      expr = test(),
      mess = c("warn", "warn2"),
      fun = c("test", "test3")
    )
  )

})

Try the polle package in your browser

Any scripts or data that you put into this service are public.

polle documentation built on May 29, 2024, 1:15 a.m.