/
test-rmd.R
41 lines (32 loc) · 1.43 KB
/
test-rmd.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
test_that("knit_print() and include_meta() work in Rmd", {
skip_if_not(rmarkdown::pandoc_available("1.12.3"))
temp_html <- tempfile("metathis-rmd", fileext = ".html")
test_rmd <- test_path("rmd", "test-metathis.Rmd")
rmarkdown::render(test_rmd, output_file = temp_html, quiet = TRUE)
out <- readLines(temp_html)
has_string <- function(str, n = 1L) {
sum(grepl(str, out, fixed = TRUE)) == n
}
expect_true(has_string('<meta method="KNIT_PRINT" />'))
expect_true(has_string('<meta method="knit_print(2)" />'))
expect_true(has_string('<meta method="INCLUDE_META()" />'))
})
test_that("Doesn't create empty directory for non self-contained RMarkdown", {
skip_if_not(rmarkdown::pandoc_available("1.12.3"))
temp_dir <- tempfile("metathis-rmd")
dir.create(temp_dir)
on.exit(unlink(temp_dir))
test_rmd_src <- test_path("rmd", "test-not-self-contained.Rmd")
test_rmd <- file.path(temp_dir, "test.Rmd")
file.copy(test_rmd_src, test_rmd)
rmarkdown::render(test_rmd, quiet = TRUE)
out <- readLines(file.path(temp_dir, "test.html"))
has_string <- function(str, n = 1L) {
sum(grepl(str, out, fixed = FALSE)) == n
}
expect_true(has_string('<meta method="KNIT_PRINT" ?/?>'))
expect_true(has_string('<meta method="knit_print\\(2\\)" ?/?>'))
expect_true(has_string('<meta method="INCLUDE_META\\(\\)" ?/?>'))
out_files <- dir(file.path(temp_dir, "test_files"))
expect_false(any(grepl("^metathis", out_files)))
})