Skip to content

Commit a317937

Browse files
committed
feat: make read_only check for file creation
1 parent ecdd419 commit a317937

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

R/testing.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ run_test <- function(hook_name,
8686
#' @param expect_success Whether or not an exit code 0 is expected. This can
8787
#' be derived from `std_err`, but sometimes, non-empty stderr does not mean
8888
#' error, but just a message.
89-
#' @param read_only If `TRUE` and `artifacts` are not `NULL`, then assert that hook
90-
#' did not modify the artifacts.
89+
#' @param read_only If `TRUE`, then assert that no new files were created.
90+
#' Additionally, if `artifacts` are not `NULL`, then assert that hook did not
91+
#' modify the artifacts.
9192
#' @keywords internal
9293
run_test_impl <- function(path_executable,
9394
path_candidate,
@@ -112,6 +113,7 @@ run_test_impl <- function(path_executable,
112113
)
113114
path_stderr <- tempfile()
114115
path_stdout <- tempfile()
116+
files_before_hook <- fs::dir_ls(tempdir, all = TRUE, recurse = TRUE)
115117
exit_status <- hook_state_create(
116118
tempdir,
117119
path_candidate_temp,
@@ -133,12 +135,17 @@ run_test_impl <- function(path_executable,
133135
std_out,
134136
exit_status
135137
)
136-
if (isTRUE(read_only) && !is.null(artifacts)) {
137-
purrr::iwalk(artifacts, function(reference_path, temp_path) {
138-
artifact_before_hook <- readLines(testthat::test_path(reference_path))
139-
artifact_after_hook <- readLines(fs::path_join(c(tempdir, temp_path)))
140-
testthat::expect_equal(artifact_before_hook, artifact_after_hook)
141-
})
138+
if (isTRUE(read_only)) {
139+
files_after_hook <- fs::dir_ls(tempdir, all = TRUE, recurse = TRUE)
140+
testthat::expect_equal(files_before_hook, files_after_hook)
141+
142+
if (!is.null(artifacts)) {
143+
purrr::iwalk(artifacts, function(reference_path, temp_path) {
144+
artifact_before_hook <- readLines(reference_path)
145+
artifact_after_hook <- readLines(fs::path_join(c(tempdir, temp_path)))
146+
testthat::expect_equal(artifact_before_hook, artifact_after_hook)
147+
})
148+
}
142149
}
143150
}
144151

man/run_test.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/run_test_impl.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)