tests/testthat/test-hook_benchmark.R

init <- function() {
  knitr::opts_chunk$delete("benchmark")
  knitr::knit_hooks$delete("benchmark")
}

test_that("Set chunk options and hooks", {
  init()
  hook <- hook_benchmark(default = TRUE)
  testthat::expect_type(hook, "closure")
  expect_true(knitr::opts_chunk$get("benchmark"))
  expect_identical(knitr::knit_hooks$get("benchmark"), hook)
})

test_that("Skip set chunk options and hooks", {
  init()
  hook <- hook_benchmark(default = TRUE, .set = FALSE)
  testthat::expect_type(hook, "closure")
  expect_null(knitr::opts_chunk$get("benchmark"))
  expect_null(knitr::knit_hooks$get("benchmark"))
})

Try the chunkhooks package in your browser

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

chunkhooks documentation built on Aug. 5, 2020, 5:09 p.m.