diff --git a/R/testing_utils.R b/R/testing_utils.R index 1f940d9..b2d470c 100644 --- a/R/testing_utils.R +++ b/R/testing_utils.R @@ -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) + } + } +} \ No newline at end of file diff --git a/tests/testthat.R b/tests/testthat.R index 1575fba..756f49d 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -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. diff --git a/tests/testthat/test-0-test-package-installation.R b/tests/testthat/test-0-test-package-installation.R index 51dbebb..e6e7304 100644 --- a/tests/testthat/test-0-test-package-installation.R +++ b/tests/testthat/test-0-test-package-installation.R @@ -12,4 +12,9 @@ test_that('Test packages installed correctly',{ , info = sprintf("Test package %s is not installed.", thisTestPkg) ) } -}) \ No newline at end of file +}) + +# 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)) \ No newline at end of file diff --git a/tests/testthat/test-Z-test-no-source-modifcations.R b/tests/testthat/test-Z-test-no-source-modifcations.R new file mode 100644 index 0000000..1574b42 --- /dev/null +++ b/tests/testthat/test-Z-test-no-source-modifcations.R @@ -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." + ) + +}) \ No newline at end of file