R Under development (unstable) (2023-04-30 r84357 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) 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. > library(testthat) > > local({ + + # Disable test on Windows, pending devtools + # compatibility with new toolchain + isWindows <- Sys.info()[["sysname"]] == "Windows" + if (isWindows) + return() + + # Disable tests on Solaris, because we don't use Catch there. + isSolaris <- Sys.info()[["sysname"]] == "SunOS" + if (isSolaris) + return() + + if (!requireNamespace("usethis", quietly = TRUE)) + return() + + # devel <- try(pkgbuild::has_compiler(), silent = TRUE) + # if (!isTRUE(devel)) + # return() + + quietly <- function(expr) { + suppressMessages(capture_output(result <- expr)) + result + } + + perform_test <- function(pkgName, catchEnabled) { + + owd <- setwd(tempdir()) + on.exit(setwd(owd), add = TRUE) + + pkgPath <- file.path(tempdir(), pkgName) + libPath <- file.path(tempdir(), "rlib") + if (!utils::file_test("-d", libPath)) + dir.create(libPath) + .libPaths(c(libPath, .libPaths())) + + on.exit({ + unlink(pkgPath, recursive = TRUE) + unlink(libPath, recursive = TRUE) + }, add = TRUE) + + quietly(usethis::create_package(pkgPath, open = FALSE)) + quietly(testthat::use_catch(pkgPath)) + + cat("LinkingTo: testthat", + file = file.path(pkgPath, "DESCRIPTION"), + append = TRUE, + sep = "\n") + + cat( + sprintf("useDynLib(%s, .registration=TRUE)", pkgName), + file = file.path(pkgPath, "NAMESPACE"), + append = TRUE, + sep = "\n" + ) + + if (!catchEnabled) { + + makevarsPath <- file.path( + pkgPath, + "src", + if (isWindows) "Makevars.win" else "Makevars" + ) + + cat( + "PKG_CPPFLAGS = -DTESTTHAT_DISABLED", + file = makevarsPath, + sep = "\n" + ) + + } + + install.packages(pkgs = pkgPath, repos = NULL, type = "source") + library(pkgName, character.only = TRUE) + stopifnot(.Call("run_testthat_tests", FALSE, PACKAGE = pkgName)) + pkgload::unload(pkgName) + } + + withr::with_envvar(c(R_TESTS = ''), perform_test("testthatclient1", TRUE)) + withr::with_envvar(c(R_TESTS = ''), perform_test("testthatclient2", FALSE)) + }) NULL > > proc.time() user system elapsed 0.46 0.25 0.68