Skip to content

Commit bd74210

Browse files
committed
Merge branch 'master' into fix_inv_metric_scientific_notation
2 parents 50f28ff + 075a595 commit bd74210

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/testthat/test-knitr.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
context("knitr engine")
2+
3+
test_that("eng_cmdstan throws correct errors", {
4+
skip_on_cran()
5+
skip_if_not_installed("knitr")
6+
expect_error(eng_cmdstan(list(output.var = 1)), "must be a character string")
7+
expect_error(eng_cmdstan(list(output.var = c("A", "B"))), "must be a character string")
8+
})
9+
10+
test_that("eng_cmdstan works", {
11+
skip_on_cran()
12+
skip_if_not_installed("knitr")
13+
opts <- knitr::opts_chunk$merge(list(
14+
output.var = "ABC",
15+
file = testing_stan_file("bernoulli"),
16+
cache = TRUE,
17+
cache.path = tempdir()
18+
))
19+
expect_message(eng_cmdstan(opts), "Compiling Stan program")
20+
21+
opts$eval <- FALSE
22+
expect_silent(eng_cmdstan(opts))
23+
})
24+
25+
test_that("register_knitr_engine works with and without override", {
26+
skip_on_cran()
27+
skip_if_not_installed("knitr")
28+
29+
knitr::knit_engines$delete(keys = "stan")
30+
expect_false("stan" %in% names(knitr::knit_engines$get()))
31+
32+
register_knitr_engine(override = TRUE)
33+
expect_false("cmdstan" %in% names(knitr::knit_engines$get()))
34+
expect_true("stan" %in% names(knitr::knit_engines$get()))
35+
36+
register_knitr_engine(override = FALSE)
37+
expect_true("cmdstan" %in% names(knitr::knit_engines$get()))
38+
39+
knitr::knit_engines$restore()
40+
})

0 commit comments

Comments
 (0)