R Under development (unstable) (2024-05-02 r86512 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Note that you would never run this file directly. This is used by tools::testInstallPackages() > # and other packages like covr. > # To actually run the tests, you need to set the working directory to pkgnet > # and then run devtools::test() > > # This line ensures that R CMD check can run tests. > # See https://github.com/hadley/testthat/issues/144 > Sys.setenv("R_TESTS" = "") > > > ####### TESTING ON vs. OFF CRAN ############# > # Due to complications on CRAN with handling of temporary packages during testing, continuous integration (CI) > # and local testing will remain the main test processes for pkgnet. > # See https://github.com/uptake/pkgnet/issues/160 for details on this decision. > > cat("testthat.R | NOT_CRAN =", Sys.getenv("NOT_CRAN"), "\n") testthat.R | NOT_CRAN = > if(identical(Sys.getenv("NOT_CRAN"), "true")){ + ######## CI and LOCAL TEST PROCEDURE ############# + + # Check if setup and helper funs have been run. + # If in R CMD CHECK, they may not have been run yet. + Sys.setenv(PKGNET_REBUILD = identical(Sys.getenv('PKGNET_TEST_LIB'), '')) + + # If not yet run, rebuild + if (Sys.getenv('PKGNET_REBUILD')){ + library(pkgnet) + ## ****************************************************************************************** + ## THIS IS THIS SAME CONTENT as setup_setTestEnv.R but neccessary to paste here due to + ## CI checks. + ## ****************************************************************************************** + + # [DEBUG] write("PKGNET_REBUILD triggered", file = "~/thing.txt", append = TRUE) + + # record original libpaths in order to reset later. + # This should be unnecessary since tests are conducted within a seperate enviornment. + # It's done out of an abundance of caution. + origLibPaths <- .libPaths() + + # Set the pkgnet library for testing to a temp directory + Sys.setenv(PKGNET_TEST_LIB = tempdir()) + + # Set the libpaths for testing. + # This has no effect to global libpaths since testing tests are conducted within a + # seperate enviornment. + .libPaths( + new = c(Sys.getenv('PKGNET_TEST_LIB'), origLibPaths) + ) + + # Install Fake Packages - For local testing if not already installed + pkgnet:::.BuildTestLib( + targetLibPath = Sys.getenv('PKGNET_TEST_LIB') + ) + + # [DEBUG] write(paste0("PKGNET_TEST_LIB: ", Sys.getenv('PKGNET_TEST_LIB')), file = "~/thing.txt", append = TRUE) + # [DEBUG] write(list.files(Sys.getenv('PKGNET_TEST_LIB'), recursive = TRUE), file = "~/thing.txt", append = TRUE) + + + } + + # 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. + withr::with_libpaths( + new = .libPaths() + , code = {testthat::test_check('pkgnet')} + ) + + # Tear down temporary test enviorment + if (Sys.getenv('PKGNET_REBUILD')){ + + ## ****************************************************************************************** + ## THIS IS THIS SAME CONTENT as teardown_setTestEnv.R but neccessary to paste here due to + ## CI checks. + ## ****************************************************************************************** + + # [DEBUG] write("PKGNET_REBUILD tear-down triggered", file = "~/thing.txt", append = TRUE) + + # Uninstall Fake Packages From Test Library if Not Already Uninstalled + try( + utils::remove.packages( + pkgs = c('baseballstats', 'sartre', 'milne', 'pkgnet') + , lib = Sys.getenv('PKGNET_TEST_LIB') + ) + ) + + # Reset libpaths. + # This should be unnecessary since tests are conducted within a seperate enviornment. + # It's done out of an abundance of caution. + .libPaths(origLibPaths) + + # Remove test libary path eviornment variable. + Sys.unsetenv('PKGNET_TEST_LIB') + } + } else { + ######## ON CRAN TEST PROCEDURE ############# + testthat::test_check(package = "pkgnet" + , filter = "cran-true" + , load_helpers = FALSE + ) + + } Loading required package: pkgnet Attaching package: 'testthat' The following object is masked from 'package:pkgnet': SummaryReporter setup-setTestEnv.R | NOT_CRAN = [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] teardown-setTestEnv.R | NOT_CRAN = > > proc.time() user system elapsed 0.56 0.21 0.76