From fe3b0cb0dcf38151b8c55b57f003bd830df061a7 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Fri, 1 Jul 2022 09:53:54 -0700 Subject: [PATCH 1/3] add windows reporting --- tests/testthat/test-build_markdown.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-build_markdown.R b/tests/testthat/test-build_markdown.R index aaa6a127f..a37620018 100644 --- a/tests/testthat/test-build_markdown.R +++ b/tests/testthat/test-build_markdown.R @@ -227,6 +227,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("file: ", built[[1]]) + print("id: ", outid) + print("fence: ", fence) + print("output: ", output) + print("episode: ", ep) + } expect_match(output, "^\\[1\\]") expect_match(fence, "^[`]{3}[{]?\\.?output[}]?") From c164db2879fc7e71b1136f99f86b2cdccbf140c7 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Fri, 1 Jul 2022 10:12:38 -0700 Subject: [PATCH 2/3] I really should have known about print dots --- tests/testthat/test-build_markdown.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-build_markdown.R b/tests/testthat/test-build_markdown.R index a37620018..4edf25cc7 100644 --- a/tests/testthat/test-build_markdown.R +++ b/tests/testthat/test-build_markdown.R @@ -228,11 +228,11 @@ test_that("Output is not commented", { output <- ep[outid[1]] fence <- ep[outid[1] - 1] if (tolower(Sys.info()[["sysname"]]) == "windows") { - print("file: ", built[[1]]) - print("id: ", outid) - print("fence: ", fence) - print("output: ", output) - print("episode: ", ep) + 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[}]?") From 33067501e6f14fcd21031fc9a6f7cbe846dde842 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Fri, 1 Jul 2022 10:35:08 -0700 Subject: [PATCH 3/3] move this to the bottom so windows does not complain --- tests/testthat/test-build_markdown.R | 77 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/tests/testthat/test-build_markdown.R b/tests/testthat/test-build_markdown.R index 4edf25cc7..7ab7e4863 100644 --- a/tests/testthat/test-build_markdown.R +++ b/tests/testthat/test-build_markdown.R @@ -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", { @@ -335,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") + }) + }) +})