@@ -43,7 +43,8 @@ run_test <- function(hook_name,
4343 artifacts = NULL ,
4444 file_transformer = function (files ) files ,
4545 env = character (),
46- expect_success = is.null(std_err )) {
46+ expect_success = is.null(std_err ),
47+ read_only = FALSE ) {
4748 withr :: local_envvar(list (R_PRECOMMIT_HOOK_ENV = " 1" ))
4849 path_executable <- fs :: dir_ls(system.file(
4950 fs :: path(" hooks" , " exported" ),
@@ -62,7 +63,8 @@ run_test <- function(hook_name,
6263 artifacts = ensure_named(artifacts ),
6364 file_transformer = file_transformer ,
6465 env = env ,
65- expect_success = expect_success
66+ expect_success = expect_success ,
67+ read_only = read_only
6668 )
6769}
6870
@@ -93,7 +95,8 @@ run_test_impl <- function(path_executable,
9395 artifacts ,
9496 file_transformer ,
9597 env ,
96- expect_success ) {
98+ expect_success ,
99+ read_only ) {
97100 # ensure cannonical /private/var/... not /var/... on macOS
98101 tempdir <- fs :: path(normalizePath((fs :: dir_create(fs :: file_temp()))))
99102 copy_artifacts(artifacts , tempdir )
@@ -128,6 +131,13 @@ run_test_impl <- function(path_executable,
128131 std_out ,
129132 exit_status
130133 )
134+ if (isTRUE(read_only ) && ! is.null(artifacts )) {
135+ purrr :: iwalk(artifacts , function (reference_path , temp_path ) {
136+ artifact_before_hook <- readLines(testthat :: test_path(reference_path ))
137+ artifact_after_hook <- readLines(fs :: path_join(c(tempdir , temp_path )))
138+ testthat :: expect_equal(artifact_before_hook , artifact_after_hook )
139+ })
140+ }
131141}
132142
133143
0 commit comments