Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move rmarkdown::render action to happen in a temp directory #330

Merged
merged 3 commits into from
May 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unit test to confirm no source dir modifications
bburns632 committed May 18, 2024
commit 8624a454ab802944362601ef723e28bddf4fc51c
26 changes: 26 additions & 0 deletions R/testing_utils.R
Original file line number Diff line number Diff line change
@@ -104,3 +104,29 @@

return(invisible(TRUE))
}


# Get Files with Modification Date after a specific date
# Used to provide more verbose logging in the event package directory is modified.
# Will not list files created and deleted in the interium but it helps.
.printModifiedFiles <- function(dir_path, after_posixct){
file_list <- list.files(
path = dir_path,
full.names = TRUE
)

print(sprintf("FILE INFO FOR UPDATES AFTER %s", as.character(after_posixct)))
for (file in file_list){
info <- as.list(file.info(file))
if (info['mtime'] > after_posixct){
msg <- sprintf(
"%s %s %s %s",
file,
info['mtime'],
info['mode'],
info['isdir']
)
print(msg)
}
}
}
5 changes: 5 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -57,6 +57,11 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")){

}

# Record modifaction time of package directory to be checked at end of testing
# in test-Z-test-no-source-modifcations.R
tmp_pkgnet_path <- file.path(Sys.getenv('PKGNET_TEST_LIB'), 'pkgnet')
Sys.setenv(PKGNET_LATEST_MOD = as.character(file.info(tmp_pkgnet_path)$mtime))

# This withr statement should be redundant.
# This is within a test environment in which .libpaths() has been altered to include PKGNET_TEST_LIB.
# Yet, it appears to be necessary.
7 changes: 6 additions & 1 deletion tests/testthat/test-0-test-package-installation.R
Original file line number Diff line number Diff line change
@@ -12,4 +12,9 @@ test_that('Test packages installed correctly',{
, info = sprintf("Test package %s is not installed.", thisTestPkg)
)
}
})
})

# Record modifaction time of package directory to be checked at end of testing
# in test-Z-test-no-source-modifcations.R
tmp_pkgnet_path <- file.path(Sys.getenv('PKGNET_TEST_LIB'), 'pkgnet')
Sys.setenv(PKGNET_LATEST_MOD = as.character(file.info(tmp_pkgnet_path)$mtime))
21 changes: 21 additions & 0 deletions tests/testthat/test-Z-test-no-source-modifcations.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Inditended to be run last, this is to confirm that no files
# within the package directory are modified during the normal
# operation of pkgnet during these tests. This includes the
# creation and deletion of temp files for rendering.

test_that('No modification to pkgnet directory during testing',{
startModTime <- as.POSIXct(Sys.getenv('PKGNET_LATEST_MOD'))

tmp_pkgnet_path <- file.path(Sys.getenv('PKGNET_TEST_LIB'), 'pkgnet')
currentModTime <- file.info(tmp_pkgnet_path)$mtime

if (as.character(startModTime) != as.character(currentModTime)){
pkgnet:::.printModifiedFiles(tmp_pkgnet_path, startModTime)
}

expect_equal(object = currentModTime
, expected = startModTime
, info = "The source directory was modified during the execution of tests."
)

})