Skip to content

Commit

Permalink
test #2344: additional tests on dep_auto()
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Oct 17, 2024
1 parent 1e40c4c commit 2fefd8f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/testit/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,43 @@ assert('dep_auto() solves dependencies of child documents', {
dep_list$restore()
knit_code$restore()

assert('dep_auto() solves dependencies of parent and child documents', {
# dependency is empty now
(dep_list$get() %==% list())

# base rmd text
parent = c(
'```{r, autodep=TRUE, cache=TRUE}',
'x = runif(1)',
'```',
'```{r, child="child.Rmd"}',
'```',
'```{r, autodep=TRUE, cache=TRUE}',
'print(x)',
'```'
)
child = c(
'```{r, autodep=TRUE, cache=TRUE}',
'x = %s',
'```'
)

td = tempfile()
dir.create(td, showWarnings = FALSE, recursive = TRUE)

# with child document
in_dir(td, {
# with cache, the result should reproduce
writeLines(sprintf(child, 'runif(1)'), 'child.Rmd')
knit1 = knit(text = parent, quiet = TRUE)
(knit(text = parent, quiet = TRUE) %==% knit1)

# on updating `x`, the printed result should change
writeLines(sprintf(child, '"a"'), "child.Rmd")
knit2 = knit(text = parent, quiet = TRUE)
print2 = gsub("\n.*", "", gsub(".*\n##", "##", knit2))
(print2 %==% '## [1] "a"')
})
})
dep_list$restore()
knit_code$restore()

0 comments on commit 2fefd8f

Please sign in to comment.