Skip to content

Commit

Permalink
Merge pull request #313 from carpentries/fix-win
Browse files Browse the repository at this point in the history
try to fix odd windows error in tests
  • Loading branch information
zkamvar authored Jul 1, 2022
2 parents 35be48e + 3306750 commit e26d5f9
Showing 1 changed file with 46 additions and 38 deletions.
84 changes: 46 additions & 38 deletions tests/testthat/test-build_markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,44 +68,6 @@ test_that("changes in config.yaml triggers a rebuild of the site yaml", {
})


test_that("setting `fail_on_error: true` in config will cause build to fail", {
old_yaml <- withr::local_tempfile()
old_episode <- withr::local_tempfile()
suppressMessages(episode <- get_episodes(res, trim = FALSE)[[1]])
yaml <- fs::path(res, "config.yaml")
fs::file_copy(yaml, old_yaml)
fs::file_copy(episode, old_episode)
withr::defer({
fs::file_copy(old_yaml, yaml, overwrite = TRUE)
fs::file_copy(old_episode, episode, overwrite = TRUE)
})
ep <- pegboard::Episode$new(episode)$confirm_sandpaper()
# Adding two errors to the top of the document. The first one will not error
# because it has `error = TRUE`, meaning that it will pass.
noerr <- "```{r this-will-not-error, error=TRUE}\nstop('hammertime')\n```\n"
# The second error will throw an error because it does not have an error=TRUE
err <- "```{r this-will-error}\nstop('in the name of love')\n```\n"
ep$add_md(err, 1L)
ep$add_md(noerr, 1L)
ep$write(fs::path(res, "episodes"), format = "Rmd")
cat("fail_on_error: true\n", file = yaml, append = TRUE)
# Important context for the test: there are two chunks in the top of the
# document that will throw errors in this order:
#
# 1. hammertime
# 2. in the name of love
#
# The first chunk is allowed to show the error in the document, the second
# is not. When we check for the text of the second error, that confirms that
# the first error is passed over.
suppressMessages({
out <- capture.output({
build_markdown(res, quiet = FALSE) %>%
expect_message("use error=TRUE") %>%
expect_error("in the name of love")
})
})
})


test_that("markdown sources can be rebuilt without fail", {
Expand Down Expand Up @@ -227,6 +189,13 @@ test_that("Output is not commented", {
outid <- grep("[1]", ep, fixed = TRUE)
output <- ep[outid[1]]
fence <- ep[outid[1] - 1]
if (tolower(Sys.info()[["sysname"]]) == "windows") {
print(c("file: ", built[[1]]))
print(c("id: ", outid))
print(c("fence: ", fence))
print(c("output: ", output))
print(c("episode: ", ep))
}
expect_match(output, "^\\[1\\]")
expect_match(fence, "^[`]{3}[{]?\\.?output[}]?")

Expand Down Expand Up @@ -328,3 +297,42 @@ test_that("Removing partially matching slugs will not have side-effects", {
expect_true(fs::file_exists(pyramid_fig))

})

test_that("setting `fail_on_error: true` in config will cause build to fail", {
old_yaml <- withr::local_tempfile()
old_episode <- withr::local_tempfile()
suppressMessages(episode <- get_episodes(res, trim = FALSE)[[1]])
yaml <- fs::path(res, "config.yaml")
fs::file_copy(yaml, old_yaml)
fs::file_copy(episode, old_episode)
withr::defer({
fs::file_copy(old_yaml, yaml, overwrite = TRUE)
fs::file_copy(old_episode, episode, overwrite = TRUE)
})
ep <- pegboard::Episode$new(episode)$confirm_sandpaper()
# Adding two errors to the top of the document. The first one will not error
# because it has `error = TRUE`, meaning that it will pass.
noerr <- "```{r this-will-not-error, error=TRUE}\nstop('hammertime')\n```\n"
# The second error will throw an error because it does not have an error=TRUE
err <- "```{r this-will-error}\nstop('in the name of love')\n```\n"
ep$add_md(err, 1L)
ep$add_md(noerr, 1L)
ep$write(fs::path(res, "episodes"), format = "Rmd")
cat("fail_on_error: true\n", file = yaml, append = TRUE)
# Important context for the test: there are two chunks in the top of the
# document that will throw errors in this order:
#
# 1. hammertime
# 2. in the name of love
#
# The first chunk is allowed to show the error in the document, the second
# is not. When we check for the text of the second error, that confirms that
# the first error is passed over.
suppressMessages({
out <- capture.output({
build_markdown(res, quiet = FALSE) %>%
expect_message("use error=TRUE") %>%
expect_error("in the name of love")
})
})
})

0 comments on commit e26d5f9

Please sign in to comment.