diff --git a/.Rbuildignore b/.Rbuildignore index 91e6269..a45a0c4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,5 @@ ^docs$ ^pkgdown$ ^dev-lib$ +^[\.]?air\.toml$ +^\.vscode$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 064677b..69cfc6a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,7 +8,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: R-CMD-check.yaml diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 4bbce75..bfc9f4d 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -4,7 +4,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] release: types: [published] workflow_dispatch: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9882260..0ab748d 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -4,7 +4,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: test-coverage.yaml @@ -35,14 +34,16 @@ jobs: clean = FALSE, install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") ) + print(cov) covr::to_cobertura(cov) shell: Rscript {0} - - uses: codecov/codecov-action@v4 + - uses: codecov/codecov-action@v5 with: - fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} - file: ./cobertura.xml - plugin: noop + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + files: ./cobertura.xml + plugins: noop disable_search: true token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..344f76e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "Posit.air-vscode" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f2d0b79 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[r]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "Posit.air-vscode" + } +} diff --git a/DESCRIPTION b/DESCRIPTION index 0795b09..3c8ac0a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,8 @@ Authors@R: c( person("Hadley", "Wickham", role = "aut"), person("Jim", "Hester", role = "aut"), person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("aut", "cre")), - person("Posit Software, PBC", role = c("cph", "fnd")) + person("Posit Software, PBC", role = c("cph", "fnd"), + comment = c(ROR = "03wc8by49")) ) Description: Provides functions used to build R packages. Locates compilers needed to build R packages on various platforms and ensures @@ -31,6 +32,7 @@ Suggests: withr (>= 2.3.0) Config/Needs/website: tidyverse/tidytemplate Config/testthat/edition: 3 +Config/usethis/last-upkeep: 2025-04-30 Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 diff --git a/LICENSE b/LICENSE index 5f2d5e0..88b5685 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,2 @@ -YEAR: 2023 +YEAR: 2025 COPYRIGHT HOLDER: pkgbuild authors diff --git a/LICENSE.md b/LICENSE.md index 57df97d..f7b37b1 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2023 pkgbuild authors +Copyright (c) 2025 pkgbuild authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/R/build-bg.R b/R/build-bg.R index 853ae76..96ad233 100644 --- a/R/build-bg.R +++ b/R/build-bg.R @@ -46,15 +46,34 @@ pkgbuild_process <- R6Class( "pkgbuild_process", inherit = callr::rcmd_process, public = list( - initialize = function(path = ".", dest_path = NULL, binary = FALSE, - vignettes = TRUE, manual = FALSE, clean_doc = NULL, - args = NULL, needs_compilation = pkg_has_src(path), - compile_attributes = FALSE, - register_routines = FALSE, quiet = FALSE) { + initialize = function( + path = ".", + dest_path = NULL, + binary = FALSE, + vignettes = TRUE, + manual = FALSE, + clean_doc = NULL, + args = NULL, + needs_compilation = pkg_has_src(path), + compile_attributes = FALSE, + register_routines = FALSE, + quiet = FALSE + ) { rcb_init( - self, private, super, path, dest_path, binary, vignettes, - manual, clean_doc, args, needs_compilation, compile_attributes, - register_routines, quiet + self, + private, + super, + path, + dest_path, + binary, + vignettes, + manual, + clean_doc, + args, + needs_compilation, + compile_attributes, + register_routines, + quiet ) }, is_incomplete_error = function() FALSE, @@ -98,13 +117,34 @@ pkgbuild_process <- R6Class( ) ) -rcb_init <- function(self, private, super, path, dest_path, binary, - vignettes, manual, clean_doc, args, needs_compilation, - compile_attributes, register_routines, quiet) { +rcb_init <- function( + self, + private, + super, + path, + dest_path, + binary, + vignettes, + manual, + clean_doc, + args, + needs_compilation, + compile_attributes, + register_routines, + quiet +) { options <- build_setup( - path, dest_path, binary, vignettes, manual, clean_doc, - args, needs_compilation, compile_attributes, - register_routines, quiet + path, + dest_path, + binary, + vignettes, + manual, + clean_doc, + args, + needs_compilation, + compile_attributes, + register_routines, + quiet ) private$path <- options$path @@ -114,9 +154,13 @@ rcb_init <- function(self, private, super, path, dest_path, binary, ## Build tools already checked in setup - withr_set_makevars(compiler_flags(debug = FALSE), new_path = private$makevars_file) + withr_set_makevars( + compiler_flags(debug = FALSE), + new_path = private$makevars_file + ) withr_with_envvar( - c("R_MAKEVARS_USER" = private$makevars_file), { + c("R_MAKEVARS_USER" = private$makevars_file), + { options <- callr::rcmd_process_options( cmd = options$cmd, cmdargs = c(options$path, options$args), diff --git a/R/build-tools.R b/R/build-tools.R index 4206acb..086ae11 100644 --- a/R/build-tools.R +++ b/R/build-tools.R @@ -45,7 +45,10 @@ has_build_tools <- function(debug = FALSE) { "WARNING: Rtools is required to build R packages, but is not ", "currently installed.\n\n", "Please download and install the appropriate version of Rtools for ", - getRversion(), " from\n", rtools_url(), "." + getRversion(), + " from\n", + rtools_url(), + "." ) } @@ -90,7 +93,11 @@ with_build_tools <- function(code, debug = FALSE, required = TRUE) { #' @rdname has_build_tools #' @param .local_envir The environment to use for scoping. #' @export -local_build_tools <- function(debug = FALSE, required = TRUE, .local_envir = parent.frame()) { +local_build_tools <- function( + debug = FALSE, + required = TRUE, + .local_envir = parent.frame() +) { if (required) { check_build_tools(debug = debug, quiet = TRUE) } diff --git a/R/build.R b/R/build.R index 78dd585..6c04e07 100644 --- a/R/build.R +++ b/R/build.R @@ -109,18 +109,37 @@ #' @export #' @return a string giving the location (including file name) of the built #' package -build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE, - manual = FALSE, clean_doc = NULL, args = NULL, quiet = FALSE, - needs_compilation = pkg_has_src(path), compile_attributes = FALSE, - register_routines = FALSE) { +build <- function( + path = ".", + dest_path = NULL, + binary = FALSE, + vignettes = TRUE, + manual = FALSE, + clean_doc = NULL, + args = NULL, + quiet = FALSE, + needs_compilation = pkg_has_src(path), + compile_attributes = FALSE, + register_routines = FALSE +) { options <- build_setup( - path, dest_path, binary, vignettes, manual, clean_doc, args, - needs_compilation, compile_attributes, register_routines, quiet + path, + dest_path, + binary, + vignettes, + manual, + clean_doc, + args, + needs_compilation, + compile_attributes, + register_routines, + quiet ) on.exit(unlink(options$out_dir, recursive = TRUE), add = TRUE) withr_with_makevars( - compiler_flags(debug = FALSE), { + compiler_flags(debug = FALSE), + { output <- withr_with_temp_libpaths( rcmd_build_tools( options$cmd, @@ -132,10 +151,13 @@ build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE ) ) - if (should_stop_for_warnings() && - grepl("\n\\s*warning:", output$stdout, ignore.case = TRUE)) { + if ( + should_stop_for_warnings() && + grepl("\n\\s*warning:", output$stdout, ignore.case = TRUE) + ) { cli::cli_alert_warning( - "Stopping as requested for a warning during {.code R CMD build}.") + "Stopping as requested for a warning during {.code R CMD build}." + ) if (quiet) { cli::cli_alert_warning("The full output is printed below.") cli::cli_verbatim(output$stdout) @@ -145,7 +167,8 @@ build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE out_file <- dir(options$out_dir) file.copy( - file.path(options$out_dir, out_file), options$dest_path, + file.path(options$out_dir, out_file), + options$dest_path, overwrite = TRUE ) @@ -158,15 +181,29 @@ build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE ) } -build_setup <- function(path, dest_path, binary, vignettes, manual, clean_doc, args, - needs_compilation, compile_attributes, register_routines, quiet) { +build_setup <- function( + path, + dest_path, + binary, + vignettes, + manual, + clean_doc, + args, + needs_compilation, + compile_attributes, + register_routines, + quiet +) { if (!file.exists(path)) { stop("`path` must exist", call. = FALSE) } if (!is_dir(path)) { if (!binary) stop("`binary` must be TRUE for package files", call. = FALSE) if (compile_attributes) { - stop("`compile_attributes` must be FALSE for package files", call. = FALSE) + stop( + "`compile_attributes` must be FALSE for package files", + call. = FALSE + ) } if (register_routines) { stop("`register_routines` must be FALSE for package files", call. = FALSE) @@ -200,7 +237,12 @@ build_setup <- function(path, dest_path, binary, vignettes, manual, clean_doc, a build_setup_binary(path, dest_path, args, needs_compilation) } else { build_setup_source( - path, dest_path, vignettes, manual, clean_doc, args, + path, + dest_path, + vignettes, + manual, + clean_doc, + args, needs_compilation ) } @@ -224,8 +266,15 @@ build_setup_binary <- function(path, dest_path, args, needs_compilation) { ) } -build_setup_source <- function(path, dest_path, vignettes, manual, clean_doc, - args, needs_compilation) { +build_setup_source <- function( + path, + dest_path, + vignettes, + manual, + clean_doc, + args, + needs_compilation +) { if (!("--resave-data" %in% args)) { args <- c(args, "--no-resave-data") } @@ -256,7 +305,11 @@ build_setup_source <- function(path, dest_path, vignettes, manual, clean_doc, doc_dir <- file.path(path, "inst", "doc") if (dir.exists(doc_dir)) { if (is.null(clean_doc) && interactive()) { - message("Building the package will delete...\n '", doc_dir, "'\nAre you sure?") + message( + "Building the package will delete...\n '", + doc_dir, + "'\nAre you sure?" + ) res <- utils::menu(c("Yes", "No")) if (res == 2) { return() diff --git a/R/c-registration.R b/R/c-registration.R index 7976255..83f84aa 100644 --- a/R/c-registration.R +++ b/R/c-registration.R @@ -1,4 +1,9 @@ -update_registration <- function(path, compile_attributes, register_routines, quiet) { +update_registration <- function( + path, + compile_attributes, + register_routines, + quiet +) { if (compile_attributes) { if (pkg_links_to_cpp11(path)) { cpp11::cpp_register(path, quiet = quiet) @@ -17,7 +22,8 @@ update_c_registration <- function(path) { pkgbuild_init_file <- file.path(path, "src", "init.c") - should_update <- !file.exists(pkgbuild_init_file) || any(grepl("generated by pkgbuild", readLines(pkgbuild_init_file))) + should_update <- !file.exists(pkgbuild_init_file) || + any(grepl("generated by pkgbuild", readLines(pkgbuild_init_file))) if (!should_update) { return(invisible(character())) @@ -29,7 +35,11 @@ update_c_registration <- function(path) { } con <- textConnection(NULL, "w") - tools::package_native_routine_registration_skeleton(path, con = con, character_only = FALSE) + tools::package_native_routine_registration_skeleton( + path, + con = con, + character_only = FALSE + ) lines <- textConnectionValue(con) close(con) @@ -74,8 +84,16 @@ tools_generated_section <- function(lines) { } pkgbuild_generated_section <- function(lines) { - start_loc <- grep("/* Section generated by pkgbuild, do not edit */", lines, fixed = TRUE) - end_loc <- grep("/* End section generated by pkgbuild */", lines, fixed = TRUE) + start_loc <- grep( + "/* Section generated by pkgbuild, do not edit */", + lines, + fixed = TRUE + ) + end_loc <- grep( + "/* End section generated by pkgbuild */", + lines, + fixed = TRUE + ) seq(start_loc, end_loc) } @@ -88,9 +106,17 @@ add_generation_message <- function(lines) { stop("Malformed init.c format") } - lines <- append(lines, "/* Section generated by pkgbuild, do not edit */", after = start_loc - 1) + lines <- append( + lines, + "/* Section generated by pkgbuild, do not edit */", + after = start_loc - 1 + ) - lines <- append(lines, "/* End section generated by pkgbuild */", after = end_loc + 1) + lines <- append( + lines, + "/* End section generated by pkgbuild */", + after = end_loc + 1 + ) lines } @@ -105,11 +131,15 @@ check_namespace_registration <- function(path) { } pkg_namespace <- readLines(namespace_file, warn = FALSE) - has_registration <- any(grepl("^[[:space:]]*useDynLib.*[.]registration[[:space:]]*=[[:space:]]*TRUE", pkg_namespace)) + has_registration <- any(grepl( + "^[[:space:]]*useDynLib.*[.]registration[[:space:]]*=[[:space:]]*TRUE", + pkg_namespace + )) if (!has_registration) { warning( - immediate. = TRUE, call. = FALSE, + immediate. = TRUE, + call. = FALSE, sprintf( "NAMESPACE missing native routine registration: * Add `#' @useDynLib %s, .registration = TRUE` to R files. @@ -142,5 +172,6 @@ pkg_links_to_cpp11 <- function(path) { desc <- desc::desc(file = file.path(path, "DESCRIPTION")) deps <- desc$get_deps() - desc$get_field("Package") == "cpp11" || any(deps$type == "LinkingTo" & deps$package == "cpp11") + desc$get_field("Package") == "cpp11" || + any(deps$type == "LinkingTo" & deps$package == "cpp11") } diff --git a/R/compile-dll.R b/R/compile-dll.R index f1e6cf7..014fc5d 100644 --- a/R/compile-dll.R +++ b/R/compile-dll.R @@ -47,12 +47,14 @@ #' `~/.R/Makevars`) then this argument is ignored. #' @seealso [clean_dll()] to delete the compiled files. #' @export -compile_dll <- function(path = ".", - force = FALSE, - compile_attributes = pkg_links_to_cpp11(path) || pkg_links_to_rcpp(path), - register_routines = FALSE, - quiet = FALSE, - debug = TRUE) { +compile_dll <- function( + path = ".", + force = FALSE, + compile_attributes = pkg_links_to_cpp11(path) || pkg_links_to_rcpp(path), + register_routines = FALSE, + quiet = FALSE, + debug = TRUE +) { path <- pkg_path(path) if (!needs_compile(path) && !isTRUE(force)) { @@ -229,7 +231,13 @@ needs_clean <- function(path = ".") { headers > dll } -install_min <- function(path = ".", dest, components = NULL, args = NULL, quiet = FALSE) { +install_min <- function( + path = ".", + dest, + components = NULL, + args = NULL, + quiet = FALSE +) { stopifnot(is.character(dest), length(dest) == 1, file.exists(dest)) poss <- c("R", "data", "help", "demo", "inst", "docs", "exec", "libs") diff --git a/R/compiler-flags.R b/R/compiler-flags.R index 0a3e9f3..3d4f3cc 100644 --- a/R/compiler-flags.R +++ b/R/compiler-flags.R @@ -50,8 +50,12 @@ compiler_flags <- function(debug = FALSE) { if (cli::num_ansi_colors() > 1 && has_compiler_colored_diagnostics()) { flags <- c( - "CFLAGS", "CXXFLAGS", "CXX11FLAGS", - "CXX14FLAGS", "CXX17FLAGS", "CXX20FLAGS" + "CFLAGS", + "CXXFLAGS", + "CXX11FLAGS", + "CXX14FLAGS", + "CXX17FLAGS", + "CXX20FLAGS" ) res[flags] <- paste(res[flags], "-fdiagnostics-color=always") } @@ -78,7 +82,10 @@ has_compiler_colored_diagnostics <- function() { on.exit(cache_remove("has_compiler")) } - res <- withr_with_makevars(c(CFLAGS = "-fdiagnostics-color=always"), has_compiler()) + res <- withr_with_makevars( + c(CFLAGS = "-fdiagnostics-color=always"), + has_compiler() + ) cache_set("has_compiler_colored_diagnostics", res) res diff --git a/R/exclude.R b/R/exclude.R index 6f7e9f7..a6000cc 100644 --- a/R/exclude.R +++ b/R/exclude.R @@ -1,9 +1,8 @@ - copy_package_tree <- function( path = ".", dest, - pkgname = desc::desc_get("Package", path)) { - + pkgname = desc::desc_get("Package", path) +) { if (!file.exists(dest)) mkdirp(dest) pkgdir <- file.path(dest, pkgname) @@ -77,8 +76,8 @@ get_copy_method <- function(path = ".") { build_files <- function( path = ".", - pkgname = desc::desc_get("Package", path)) { - + pkgname = desc::desc_get("Package", path) +) { path <- normalizePath(path) # patterns in .Rbuildignore @@ -96,7 +95,7 @@ build_files <- function( ptrn_dir <- re_exclude_dir(pkgname) # filter at the top level first, so we don't need to enumerate these - top <- dir(path, include.dirs = TRUE, all.files=TRUE, no.. = TRUE) + top <- dir(path, include.dirs = TRUE, all.files = TRUE, no.. = TRUE) # now filter top realtop <- file.path(path, top) @@ -113,8 +112,12 @@ build_files <- function( sub <- unlist(lapply( topfls$path[topfls$isdir & !topfls$exclude], function(t) { - tf <- dir(file.path(path, t), include.dirs = TRUE, all.files = TRUE, - recursive = TRUE) + tf <- dir( + file.path(path, t), + include.dirs = TRUE, + all.files = TRUE, + recursive = TRUE + ) tf <- file.path(t, tf) } )) @@ -143,27 +146,33 @@ build_files <- function( re_exclude <- function(pkg) { c( paste0( - "(?i)", # these are case insensitive + "(?i)", # these are case insensitive c( - "(^|/)\\.DS_Store$", # by macOS finder - "^\\.RData$", # .RData at / - "~$", "\\.bak$", "\\.swp$", # backup files - "(^|/)\\.#[^/]*$", "(^|/)#[^/]*#$", # more backup files (Emacs) - - "^config\\.(cache|log|status)$", # leftover by autoconf + "(^|/)\\.DS_Store$", # by macOS finder + "^\\.RData$", # .RData at / + "~$", + "\\.bak$", + "\\.swp$", # backup files + "(^|/)\\.#[^/]*$", + "(^|/)#[^/]*#$", # more backup files (Emacs) + + "^config\\.(cache|log|status)$", # leftover by autoconf "(^|/)autom4te\\.cache$", - "^src/.*\\.d$", "^src/Makedeps$", # INSTALL leftover on Windows + "^src/.*\\.d$", + "^src/Makedeps$", # INSTALL leftover on Windows - "^inst/doc/Rplots\\.(ps|pdf)$" # Sweave leftover + "^inst/doc/Rplots\\.(ps|pdf)$" # Sweave leftover ) ), - "(^|/)\\._[^/]*$", # macOS resource forks + "(^|/)\\._[^/]*$", # macOS resource forks - paste0( # hidden files + paste0( + # hidden files "(^|/)\\.", - c("Renviron", + c( + "Renviron", "Rprofile", "Rproj.user", "Rhistory", @@ -208,10 +217,12 @@ re_exclude <- function(pkg) { re_exclude_dir <- function(pkg) { c( - "^revdep$", # revdepcheck - paste0( # VC + "^revdep$", # revdepcheck + paste0( + # VC "(^|/)", - c("CVS", + c( + "CVS", ".svn", ".arch-ids", ".bzr", @@ -298,11 +309,11 @@ cp <- local({ i = "Failed to copy {.path {src}} to {.path {tgt}}." ))) } - } else { if (is.null(cpargs)) cpargs <<- detect_cp_args() ret <- processx::run( - "cp", c(cpargs, src, tgt), + "cp", + c(cpargs, src, tgt), stderr = "2>&1", error_on_status = FALSE ) @@ -323,7 +334,13 @@ detect_cp_args <- function() { # `--preserve=timestamps` dir.create(tmp <- tempfile()) old <- getwd() - on.exit({ setwd(old); unlink(tmp, recursive = TRUE) }, add = TRUE) + on.exit( + { + setwd(old) + unlink(tmp, recursive = TRUE) + }, + add = TRUE + ) setwd(tmp) f1 <- basename(tempfile()) f2 <- basename(tempfile()) diff --git a/R/find-package-root.R b/R/find-package-root.R index 40730b2..791aef0 100644 --- a/R/find-package-root.R +++ b/R/find-package-root.R @@ -18,8 +18,10 @@ find_package_root <- function(path = ".") { max_depth <- 100 for (i in 1:max_depth) { dsc_path <- file.path(cur_path, "DESCRIPTION") - if (file.exists(dsc_path) && - any(grepl("^Package: ", readLines(dsc_path)))) { + if ( + file.exists(dsc_path) && + any(grepl("^Package: ", readLines(dsc_path))) + ) { return(cur_path) } else if (is_root(cur_path)) { stop(errmsg) diff --git a/R/has_src.R b/R/has_src.R index 1acfd71..756a347 100644 --- a/R/has_src.R +++ b/R/has_src.R @@ -27,7 +27,8 @@ pkg_has_src <- function(path = ".") { }, error = function(e) { e$message <- paste( - path, "is not a valid package archive file,", + path, + "is not a valid package archive file,", e$message ) stop(e) diff --git a/R/pkgbuild-package.R b/R/pkgbuild-package.R index c4f4cb4..fe7cc21 100644 --- a/R/pkgbuild-package.R +++ b/R/pkgbuild-package.R @@ -10,15 +10,25 @@ NULL } set_pkg_config_path <- function() { - if (Sys.getenv("PKG_BUILD_IGNORE_PKG_CONFIG_PATH") != "true" && + if ( + Sys.getenv("PKG_BUILD_IGNORE_PKG_CONFIG_PATH") != "true" && .Platform$OS.type == "windows" && Sys.which("pkg-config") != "" && - getRversion()[,1:2] == "4.2" && + getRversion()[, 1:2] == "4.2" && Sys.which("gcc") != "" && - grepl("/rtools42/", normalizePath(Sys.which("gcc"), winslash = "/"), ignore.case = TRUE) && - !grepl("/rtools42", Sys.getenv("PKG_CONFIG_PATH"), ignore.case = TRUE)) { + grepl( + "/rtools42/", + normalizePath(Sys.which("gcc"), winslash = "/"), + ignore.case = TRUE + ) && + !grepl("/rtools42", Sys.getenv("PKG_CONFIG_PATH"), ignore.case = TRUE) + ) { old <- Sys.getenv("PKG_CONFIG_PATH") - new <- paste0("/c/rtools42/x86_64-w64-mingw32.static.posix/lib/pkgconfig", ":", old) + new <- paste0( + "/c/rtools42/x86_64-w64-mingw32.static.posix/lib/pkgconfig", + ":", + old + ) message("Updating PKG_CONFIG_PATH.\nOld: ", old, "\nNew: ", new) Sys.setenv(PKG_CONFIG_PATH = new) } diff --git a/R/rcmd.R b/R/rcmd.R index 4a61cdb..eae4106 100644 --- a/R/rcmd.R +++ b/R/rcmd.R @@ -18,7 +18,12 @@ #' rcmd_build_tools("CONFIG", "CC")$stdout #' rcmd_build_tools("CC", "--version")$stdout #' } -rcmd_build_tools <- function(..., env = character(), required = TRUE, quiet = FALSE) { +rcmd_build_tools <- function( + ..., + env = character(), + required = TRUE, + quiet = FALSE +) { env <- c(callr::rcmd_safe_env(), env) if (!quiet) { @@ -36,9 +41,14 @@ rcmd_build_tools <- function(..., env = character(), required = TRUE, quiet = FA res <- with_build_tools( { withCallingHandlers( - callr::rcmd_safe(..., - env = env, spinner = FALSE, show = FALSE, - echo = FALSE, block_callback = callback, stderr = "2>&1" + callr::rcmd_safe( + ..., + env = env, + spinner = FALSE, + show = FALSE, + echo = FALSE, + block_callback = callback, + stderr = "2>&1" ), error = function(e) { if (!quiet) e$echo <- TRUE @@ -55,8 +65,10 @@ rcmd_build_tools <- function(..., env = character(), required = TRUE, quiet = FA } msg_for_long_paths <- function(output) { - if (is_windows() && - any(grepl("over-long path length", output$stdout))) { + if ( + is_windows() && + any(grepl("over-long path length", output$stdout)) + ) { message( "\nIt seems that this package contains files with very long paths.\n", "This is not supported on most Windows versions. Please contact the\n", @@ -67,13 +79,14 @@ msg_for_long_paths <- function(output) { } warn_for_potential_errors <- function() { - if (is_windows() && grepl(" ", R.home()) && - getRversion() <= "3.4.2") { + if (is_windows() && grepl(" ", R.home()) && getRversion() <= "3.4.2") { warning( immediate. = TRUE, "\n!!! Building will probably fail!\n", "This version of R has trouble with building packages if\n", - "the R HOME directory (currently '", R.home(), "')\n", + "the R HOME directory (currently '", + R.home(), + "')\n", "has space characters. Possible workarounds include:\n", "- installing R to the C: drive,\n", "- installing it into a path without a space, or\n", diff --git a/R/rtools-path.R b/R/rtools-path.R index 1852383..c14b7e6 100644 --- a/R/rtools-path.R +++ b/R/rtools-path.R @@ -50,7 +50,6 @@ scan_path_for_rtools <- function(debug = FALSE) { } find_arch_exe <- function(path, debug = FALSE) { - # Convert unix path to Windows if (grepl("^/", path)) { path <- convert_unix_path(path) diff --git a/R/rtools-registry.R b/R/rtools-registry.R index 62ea877..db901a5 100644 --- a/R/rtools-registry.R +++ b/R/rtools-registry.R @@ -9,9 +9,24 @@ scan_registry_for_rtools <- function(debug = FALSE) { if (debug) cat("Scanning registry...\n") keys <- c( - read_registry("SOFTWARE\\R-core\\Rtools", hive = "HCU", view = "32-bit", maxdepth = 2), - read_registry("SOFTWARE\\R-core\\Rtools", hive = "HLM", view = "32-bit", maxdepth = 2), - read_registry("SOFTWARE\\R-core\\Rtools", hive = "HLM", view = "64-bit", maxdepth = 2) + read_registry( + "SOFTWARE\\R-core\\Rtools", + hive = "HCU", + view = "32-bit", + maxdepth = 2 + ), + read_registry( + "SOFTWARE\\R-core\\Rtools", + hive = "HLM", + view = "32-bit", + maxdepth = 2 + ), + read_registry( + "SOFTWARE\\R-core\\Rtools", + hive = "HLM", + view = "64-bit", + maxdepth = 2 + ) ) if (is.null(keys)) { @@ -24,8 +39,10 @@ scan_registry_for_rtools <- function(debug = FALSE) { version <- names(keys)[[i]] key <- keys[[version]] if (!is.list(key) || is.null(key$InstallPath)) next - install_path <- normalizePath(key$InstallPath, - mustWork = FALSE, winslash = "/" + install_path <- normalizePath( + key$InstallPath, + mustWork = FALSE, + winslash = "/" ) if (debug) cat("Found", install_path, "for", version, "\n") diff --git a/R/rtools.R b/R/rtools.R index 9537025..29c22a1 100644 --- a/R/rtools.R +++ b/R/rtools.R @@ -32,7 +32,10 @@ has_rtools <- function(debug = FALSE) { # R 4.5.0 or later on ARM64 if (getRversion() >= "4.5.0" && grepl("aarch", R.version$platform)) { - rtools45_aarch64_home <- Sys.getenv("RTOOLS45_AARCH64_HOME", "C:\\rtools45-aarch64") + rtools45_aarch64_home <- Sys.getenv( + "RTOOLS45_AARCH64_HOME", + "C:\\rtools45-aarch64" + ) if (file.exists(file.path(rtools45_aarch64_home, "usr", "bin"))) { if (debug) { cat("Found in Rtools 4.5 (aarch64) installation folder\n") @@ -55,9 +58,15 @@ has_rtools <- function(debug = FALSE) { } # R 4.4.0 or later on ARM64 - if (getRversion() >= "4.4.0" && getRversion() < "4.5.0" && - grepl("aarch", R.version$platform)) { - rtools44_aarch64_home <- Sys.getenv("RTOOLS44_AARCH64_HOME", "C:\\rtools44-aarch64") + if ( + getRversion() >= "4.4.0" && + getRversion() < "4.5.0" && + grepl("aarch", R.version$platform) + ) { + rtools44_aarch64_home <- Sys.getenv( + "RTOOLS44_AARCH64_HOME", + "C:\\rtools44-aarch64" + ) if (file.exists(file.path(rtools44_aarch64_home, "usr", "bin"))) { if (debug) { cat("Found in Rtools 4.4 (aarch64) installation folder\n") @@ -68,8 +77,11 @@ has_rtools <- function(debug = FALSE) { } # R 4.4.0 or later - if (getRversion() >= "4.4.0" && getRversion() < "4.5.0" && - !grepl("aarch", R.version$platform)) { + if ( + getRversion() >= "4.4.0" && + getRversion() < "4.5.0" && + !grepl("aarch", R.version$platform) + ) { rtools44_home <- Sys.getenv("RTOOLS44_HOME", "C:\\rtools44") if (file.exists(file.path(rtools44_home, "usr", "bin"))) { if (debug) { @@ -81,9 +93,15 @@ has_rtools <- function(debug = FALSE) { } # R 4.3.0 or later on ARM64 - if (getRversion() >= "4.3.0" && getRversion() < "4.4.0" && - grepl("aarch", R.version$platform)) { - rtools43_aarch64_home <- Sys.getenv("RTOOLS43_AARCH64_HOME", "C:\\rtools43-aarch64") + if ( + getRversion() >= "4.3.0" && + getRversion() < "4.4.0" && + grepl("aarch", R.version$platform) + ) { + rtools43_aarch64_home <- Sys.getenv( + "RTOOLS43_AARCH64_HOME", + "C:\\rtools43-aarch64" + ) if (file.exists(file.path(rtools43_aarch64_home, "usr", "bin"))) { if (debug) { cat("Found in Rtools 4.3 (aarch64) installation folder\n") @@ -94,8 +112,11 @@ has_rtools <- function(debug = FALSE) { } # R 4.3.0 or later - if (getRversion() >= "4.3.0" && getRversion() < "4.4.0" && - !grepl("aarch", R.version$platform)) { + if ( + getRversion() >= "4.3.0" && + getRversion() < "4.4.0" && + !grepl("aarch", R.version$platform) + ) { rtools43_home <- Sys.getenv("RTOOLS43_HOME", "C:\\rtools43") if (file.exists(file.path(rtools43_home, "usr", "bin"))) { if (debug) { @@ -168,9 +189,18 @@ has_rtools <- function(debug = FALSE) { # Installed, but not compatible needed <- rtools_needed() message( - "WARNING: Rtools ", from_path$version, " found on the path", - " at ", from_path$path, " is not compatible with R ", getRversion(), ".\n\n", - "Please download and install ", needed, " from ", rtools_url(needed), + "WARNING: Rtools ", + from_path$version, + " found on the path", + " at ", + from_path$path, + " is not compatible with R ", + getRversion(), + ".\n\n", + "Please download and install ", + needed, + " from ", + rtools_url(needed), ", remove the incompatible version from your PATH." ) return(invisible(FALSE)) @@ -186,7 +216,11 @@ has_rtools <- function(debug = FALSE) { message( "WARNING: Rtools is required to build R packages, but is not ", "currently installed.\n\n", - "Please download and install ", needed, " from ", rtools_url(needed), "." + "Please download and install ", + needed, + " from ", + rtools_url(needed), + "." ) return(invisible(FALSE)) } @@ -198,10 +232,17 @@ has_rtools <- function(debug = FALSE) { needed <- rtools_needed() message( "WARNING: Rtools is required to build R packages, but no version ", - "of Rtools compatible with R ", getRversion(), " was found. ", + "of Rtools compatible with R ", + getRversion(), + " was found. ", "(Only the following incompatible version(s) of Rtools were found: ", - paste(versions, collapse = ", "), ")\n\n", - "Please download and install ", needed, " from ", rtools_url(needed), "." + paste(versions, collapse = ", "), + ")\n\n", + "Please download and install ", + needed, + " from ", + rtools_url(needed), + "." ) return(invisible(FALSE)) } @@ -215,9 +256,14 @@ has_rtools <- function(debug = FALSE) { needed <- rtools_needed() message( "WARNING: Rtools is required to build R packages, but the ", - "version of Rtools previously installed in ", from_registry$path, + "version of Rtools previously installed in ", + from_registry$path, " has been deleted.\n\n", - "Please download and install ", needed, " from ", rtools_url(needed), "." + "Please download and install ", + needed, + " from ", + rtools_url(needed), + "." ) return(invisible(FALSE)) } @@ -227,11 +273,21 @@ has_rtools <- function(debug = FALSE) { needed <- rtools_needed() message( "WARNING: Rtools is required to build R packages, but no version ", - "of Rtools compatible with R ", getRversion(), " was found. ", - "Rtools ", from_registry$version, " was previously installed in ", - from_registry$path, " but now that directory contains Rtools ", - installed_ver, ".\n\n", - "Please download and install ", needed, " from ", rtools_url(needed), "." + "of Rtools compatible with R ", + getRversion(), + " was found. ", + "Rtools ", + from_registry$version, + " was previously installed in ", + from_registry$path, + " but now that directory contains Rtools ", + installed_ver, + ".\n\n", + "Please download and install ", + needed, + " from ", + rtools_url(needed), + "." ) return(invisible(FALSE)) } @@ -241,7 +297,8 @@ has_rtools <- function(debug = FALSE) { # Recently Rtools is versioned properly from_registry$version <- sub( - "^([0-9]+[.][0-9]+)[.].*$", "\\1", + "^([0-9]+[.][0-9]+)[.].*$", + "\\1", from_registry$version ) rtools_path_set(from_registry) diff --git a/R/styles.R b/R/styles.R index d239c83..aaf5519 100644 --- a/R/styles.R +++ b/R/styles.R @@ -4,11 +4,11 @@ style <- function(..., sep = "") { st <- names(args) styles <- list( - "ok" = cli::col_green, - "note" = cli::make_ansi_style("orange"), - "warn" = function(x) cli::style_bold(cli::make_ansi_style("orange")(x)), - "err" = cli::col_red, - "pale" = cli::make_ansi_style("darkgrey"), + "ok" = cli::col_green, + "note" = cli::make_ansi_style("orange"), + "warn" = function(x) cli::style_bold(cli::make_ansi_style("orange")(x)), + "err" = cli::col_red, + "pale" = cli::make_ansi_style("darkgrey"), "timing" = cli::make_ansi_style("cyan") ) diff --git a/R/utils.R b/R/utils.R index bb17786..f5e4b49 100644 --- a/R/utils.R +++ b/R/utils.R @@ -43,7 +43,10 @@ makevars_user <- function() { if (file.exists(f)) { m <- f } - } else if ((Sys.getenv("R_ARCH") == "/x64") && file.exists(f <- path.expand("~/.R/Makevars.win64"))) { + } else if ( + (Sys.getenv("R_ARCH") == "/x64") && + file.exists(f <- path.expand("~/.R/Makevars.win64")) + ) { m <- f } else if (file.exists(f <- path.expand("~/.R/Makevars.win"))) { m <- f @@ -55,10 +58,14 @@ makevars_user <- function() { if (file.exists(f)) { m <- f } - } else if (file.exists(f <- path.expand(paste0( - "~/.R/Makevars-", - Sys.getenv("R_PLATFORM") - )))) { + } else if ( + file.exists( + f <- path.expand(paste0( + "~/.R/Makevars-", + Sys.getenv("R_PLATFORM") + )) + ) + ) { m <- f } else if (file.exists(f <- path.expand("~/.R/Makevars"))) { m <- f diff --git a/R/with-debug.R b/R/with-debug.R index 5dafcba..c2d3d98 100644 --- a/R/with-debug.R +++ b/R/with-debug.R @@ -15,12 +15,20 @@ #' install("mypkg") #' with_debug(install("mypkg")) #' } -with_debug <- function(code, CFLAGS = NULL, CXXFLAGS = NULL, - FFLAGS = NULL, FCFLAGS = NULL, debug = TRUE) { +with_debug <- function( + code, + CFLAGS = NULL, + CXXFLAGS = NULL, + FFLAGS = NULL, + FCFLAGS = NULL, + debug = TRUE +) { defaults <- compiler_flags(debug = debug) flags <- c( - CFLAGS = CFLAGS, CXXFLAGS = CXXFLAGS, - FFLAGS = FFLAGS, FCFLAGS = FCFLAGS + CFLAGS = CFLAGS, + CXXFLAGS = CXXFLAGS, + FFLAGS = FFLAGS, + FCFLAGS = FCFLAGS ) flags <- unlist(utils::modifyList(as.list(defaults), as.list(flags))) diff --git a/R/withr.R b/R/withr.R index 6b72e92..f6ebac5 100644 --- a/R/withr.R +++ b/R/withr.R @@ -1,4 +1,3 @@ - withr_with_makevars <- function(new, code, path = makevars_user()) { makevars_file <- tempfile() on.exit(unlink(makevars_file), add = TRUE) @@ -9,8 +8,11 @@ withr_with_makevars <- function(new, code, path = makevars_user()) { }) } -withr_set_makevars <- function(variables, old_path = withr_makevars_user(), - new_path = tempfile()) { +withr_set_makevars <- function( + variables, + old_path = withr_makevars_user(), + new_path = tempfile() +) { if (length(variables) == 0) { return() } @@ -57,8 +59,7 @@ withr_set_envvar <- function(envs, action = "replace") { if (any(both_set)) { if (action == "prefix") { envs[both_set] <- paste(envs[both_set], old[both_set]) - } - else if (action == "suffix") { + } else if (action == "suffix") { envs[both_set] <- paste(old[both_set], envs[both_set]) } } @@ -88,26 +89,26 @@ withr_vlapply <- function(X, FUN, ...) { vapply(X, FUN, FUN.VALUE = logical(1), ...) } -withr_is_named <- function (x) { +withr_is_named <- function(x) { !is.null(names(x)) && all(names(x) != "") } # ------------------------------------------------------------------------- -withr_with_temp_libpaths <- function (code, action = "prefix") { +withr_with_temp_libpaths <- function(code, action = "prefix") { old <- .libPaths() on.exit(.libPaths(old)) withr_set_temp_libpaths(action = action) force(code) } -withr_set_temp_libpaths <- function (action = "prefix") { +withr_set_temp_libpaths <- function(action = "prefix") { paths <- tempfile("temp_libpath") dir.create(paths) withr_set_libpaths(paths, action = action) } -withr_set_libpaths <- function (paths, action = "replace") { +withr_set_libpaths <- function(paths, action = "replace") { paths <- withr_as_character(paths) paths <- normalizePath(paths, mustWork = TRUE) old <- .libPaths() @@ -120,8 +121,7 @@ withr_merge_new <- function(old, new, action, merge_fun = c) { action <- match.arg(action, c("replace", "prefix", "suffix")) if (action == "suffix") { new <- merge_fun(old, new) - } - else if (action == "prefix") { + } else if (action == "prefix") { new <- merge_fun(new, old) } new @@ -152,8 +152,11 @@ withr_reset_options <- function(old_options) { # ------------------------------------------------------------------------- -withr_with_path <- function(new, code, - action = c("prefix", "suffix", "replace")) { +withr_with_path <- function( + new, + code, + action = c("prefix", "suffix", "replace") +) { old <- withr_get_path(path = new, action = action) on.exit((function(old) withr_set_path(old, "replace"))(old)) withr_set_path(path = new, action = action) @@ -175,8 +178,7 @@ withr_merge_new <- function(old, new, action, merge_fun = c) { action <- match.arg(action, c("replace", "prefix", "suffix")) if (action == "suffix") { new <- merge_fun(old, new) - } - else if (action == "prefix") { + } else if (action == "prefix") { new <- merge_fun(new, old) } new @@ -186,11 +188,16 @@ withr_get_path <- function(...) { strsplit(Sys.getenv("PATH"), .Platform$path.sep)[[1]] } -withr_local_path <- function (new = list(), - action = c("prefix", "suffix", "replace"), - .local_envir = parent.frame()) { +withr_local_path <- function( + new = list(), + action = c("prefix", "suffix", "replace"), + .local_envir = parent.frame() +) { old <- withr_get_path(path = new, action = action) - withr_defer((function(old) withr_set_path(old, "replace"))(old), frame = .local_envir) + withr_defer( + (function(old) withr_set_path(old, "replace"))(old), + frame = .local_envir + ) withr_set_path(path = new, action = action) invisible(old) } diff --git a/README.md b/README.md index 8b2ac45..bc6e533 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![R-CMD-check](https://github.com/r-lib/pkgbuild/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/pkgbuild/actions/workflows/R-CMD-check.yaml) -[![Codecov test coverage](https://codecov.io/gh/r-lib/pkgbuild/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/pkgbuild?branch=main) +[![Codecov test coverage](https://codecov.io/gh/r-lib/pkgbuild/graph/badge.svg)](https://app.codecov.io/gh/r-lib/pkgbuild) The goal of pkgbuild is to make it easy to build packages with compiled code. It provides tools to configure your R session, and check that everything is working ok. If you are using RStudio, it also helps you trigger automatic install of the build tools. @@ -10,7 +10,7 @@ The goal of pkgbuild is to make it easy to build packages with compiled code. It ## Installation Install the released version from CRAN - + ```r install.packages("pkgbuild") ``` diff --git a/air.toml b/air.toml new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/_snaps/archives.md b/tests/testthat/_snaps/archives.md new file mode 100644 index 0000000..d6364e5 --- /dev/null +++ b/tests/testthat/_snaps/archives.md @@ -0,0 +1,13 @@ +# pkg_has_src on non-package files + + Code + pkg_has_src(file.path("fixtures", "xxx.zip")) + Condition + Error in `doTryCatch()`: + ! fixtures/xxx.zip is not a valid package archive file, no DESCRIPTION file + Code + pkg_has_src(file.path("fixtures", "xxx.tar.gz")) + Condition + Error in `doTryCatch()`: + ! fixtures/xxx.tar.gz is not a valid package archive file, no DESCRIPTION file + diff --git a/tests/testthat/_snaps/build-process.md b/tests/testthat/_snaps/build-process.md new file mode 100644 index 0000000..0af6ab6 --- /dev/null +++ b/tests/testthat/_snaps/build-process.md @@ -0,0 +1,13 @@ +# build package with src requires compiler + + Code + suppressMessages(local({ + pr <- pkgbuild_process$new("testWithSrc", dest_path = tempdir(), + register_routines = FALSE) + pr$kill() + })) + Condition + Error: + ! Could not find tools necessary to compile a package + Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem. + diff --git a/tests/testthat/_snaps/build.md b/tests/testthat/_snaps/build.md index 2399ee8..34ca978 100644 --- a/tests/testthat/_snaps/build.md +++ b/tests/testthat/_snaps/build.md @@ -1,23 +1,26 @@ -# warnings can be turned into errors +# build package with src requires compiler Code - build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE) - Message - ! Stopping as requested for a warning during `R CMD build`. - ! The full output is printed below. - * checking for file '' ... OK - * preparing 'testDummy': - * checking DESCRIPTION meta-information ... OK - * checking for LF line-endings in source and make files and shell scripts - * checking for empty or unneeded directories - NB: this package now depends on R (>= 3.5.0) - WARNING: Added dependency on R >= 3.5.0 because serialized objects in - serialize/load version 3 cannot be read in older versions of R. - File(s) containing such objects: - 'testDummy/inst/testthat-problems.rds' - * building 'testDummy_0.1.tar.gz' - + suppressMessages(build("testWithSrc", dest_path = tempdir(), quiet = TRUE)) Condition - Error in `force()`: - ! converted from `R CMD build` warning. + Error: + ! Could not find tools necessary to compile a package + Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem. + +# package tarball binary build errors + + Code + build(path, dest_path = tempdir(), quiet = TRUE) + Condition + Error: + ! `binary` must be TRUE for package files + +--- + + Code + build(path, dest_path = tempdir(), quiet = TRUE, binary = TRUE, + needs_compilation = FALSE, compile_attributes = TRUE) + Condition + Error: + ! `compile_attributes` must be FALSE for package files diff --git a/tests/testthat/_snaps/compiler-flags.md b/tests/testthat/_snaps/compiler-flags.md new file mode 100644 index 0000000..b52c1b7 --- /dev/null +++ b/tests/testthat/_snaps/compiler-flags.md @@ -0,0 +1,8 @@ +# has_compiler_colored_diagnostics + + Code + has_compiler_colored_diagnostics() + Condition + Error in `cache_exists()`: + ! nope + diff --git a/tests/testthat/_snaps/compiler.md b/tests/testthat/_snaps/compiler.md index 212831d..40574c0 100644 --- a/tests/testthat/_snaps/compiler.md +++ b/tests/testthat/_snaps/compiler.md @@ -1,5 +1,21 @@ +# has_compiler: succeeds if a compiler exists + + Code + check_compiler() + Condition + Error: + ! Failed to compile C code + # has_compiler: returns the value of the has_compiler option + Code + check_compiler() + Condition + Error: + ! Failed to compile C code + +--- + Code has_compiler() Condition diff --git a/tests/testthat/_snaps/exclude.md b/tests/testthat/_snaps/exclude.md index d52f32c..9e10a4f 100644 --- a/tests/testthat/_snaps/exclude.md +++ b/tests/testthat/_snaps/exclude.md @@ -14,6 +14,15 @@ [1] "testDummy" "testDummy/DESCRIPTION" "testDummy/NAMESPACE" [4] "testDummy/R" "testDummy/R/a.R" "testDummy/R/b.R" +# copy_package_tree errors + + Code + copy_package_tree(test_path("testDummy"), tmp) + Condition + Error in `copy_package_tree()`: + ! Cannot copy package tree to '/pkgbuild-test-' + i Directory '/pkgbuild-test-/testDummy' already exists, and did not want to overwrite. + # exclusions Code @@ -35,6 +44,24 @@ 13 src/src.c FALSE FALSE FALSE 14 src/src.o TRUE FALSE FALSE +# get_copy_method + + Code + get_copy_method() + Condition + Error in `check_method()`: + ! Invalid `pkg.build_copy_method` value: "foobar". + i It must be one of "none", "copy", and "link". + +--- + + Code + get_copy_method() + Condition + Error in `get_copy_method()`: + ! Invalid `pkg.build_copy_method` value. + i It must be a string, but it is an integer vector. + # Ignoring .Rbuildignore Code diff --git a/tests/testthat/_snaps/find-package-root.md b/tests/testthat/_snaps/find-package-root.md new file mode 100644 index 0000000..61b0688 --- /dev/null +++ b/tests/testthat/_snaps/find-package-root.md @@ -0,0 +1,16 @@ +# find_package_root errors + + Code + find_package_root("file1130e91427d3") + Condition + Error in `find_package_root()`: + ! Path does not exist: file1130e91427d3 + +--- + + Code + find_package_root("/") + Condition + Error in `find_package_root()`: + ! Could not find R package in `/` or its parent directories. + diff --git a/tests/testthat/_snaps/new/build.md b/tests/testthat/_snaps/new/build.md new file mode 100644 index 0000000..29030bf --- /dev/null +++ b/tests/testthat/_snaps/new/build.md @@ -0,0 +1,27 @@ +# warnings can be turned into errors + + Code + if (getRversion() >= "4.1") { + build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE) + } else { + suppressMessages(build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE)) + } + Message + ! Stopping as requested for a warning during `R CMD build`. + ! The full output is printed below. + * checking for file '' ... OK + * preparing 'testDummy': + * checking DESCRIPTION meta-information ... OK + * checking for LF line-endings in source and make files and shell scripts + * checking for empty or unneeded directories + NB: this package now depends on R (>= 3.5.0) + WARNING: Added dependency on R >= 3.5.0 because serialized objects in + serialize/load version 3 cannot be read in older versions of R. + File(s) containing such objects: + 'testDummy/inst/testthat-problems.rds' + * building 'testDummy_0.1.tar.gz' + + Condition + Error in `force()`: + ! converted from `R CMD build` warning. + diff --git a/tests/testthat/_snaps/old/build.md b/tests/testthat/_snaps/old/build.md new file mode 100644 index 0000000..1ce5f29 --- /dev/null +++ b/tests/testthat/_snaps/old/build.md @@ -0,0 +1,12 @@ +# warnings can be turned into errors + + Code + if (getRversion() >= "4.1") { + build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE) + } else { + suppressMessages(build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE)) + } + Condition + Error in `force()`: + ! converted from `R CMD build` warning. + diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md index c48ecbf..1bbab1a 100644 --- a/tests/testthat/_snaps/utils.md +++ b/tests/testthat/_snaps/utils.md @@ -1,3 +1,19 @@ +# should_stop_for_warnings + + Code + should_stop_for_warnings() + Condition + Error in `get_config_flag_value()`: + ! The `pkg.build_stop_for_warnings` option must be `TRUE` or `FALSE`, if set. + +--- + + Code + should_stop_for_warnings() + Condition + Error in `interpret_envvar_flag()`: + ! The `PKG_BUILD_STOP_FOR_WARNINGS` environment variable must be `true` or `false`, if set. + # should_add_compiler_flags errors Code diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R new file mode 100644 index 0000000..44e26b1 --- /dev/null +++ b/tests/testthat/helper.R @@ -0,0 +1,15 @@ +transform_tempdir <- function(x) { + x <- sub(tempdir(), "", x, fixed = TRUE) + x <- sub(normalizePath(tempdir()), "", x, fixed = TRUE) + x <- sub( + normalizePath(tempdir(), winslash = "/"), + "", + x, + fixed = TRUE + ) + x <- sub("\\R\\", "/R/", x, fixed = TRUE) + x <- sub("[\\\\/]file[a-zA-Z0-9]+", "/", x) + x <- sub("[A-Z]:.*Rtmp[a-zA-Z0-9]+[\\\\/]", "/", x) + x <- sub("\\", "/", x, fixed = TRUE) + x +} diff --git a/tests/testthat/test-archives.R b/tests/testthat/test-archives.R index a273bc5..50b98b9 100644 --- a/tests/testthat/test-archives.R +++ b/tests/testthat/test-archives.R @@ -1,4 +1,3 @@ - test_that("is_zip_file", { expect_true(is_zip_file(file.path("fixtures", "xxx.zip"))) expect_false(is_zip_file(file.path("fixtures", "xxx.gz"))) @@ -23,6 +22,8 @@ test_that("pkg_has_src", { }) test_that("pkg_has_src on non-package files", { - expect_error(pkg_has_src(file.path("fixtures", "xxx.zip"))) - expect_error(pkg_has_src(file.path("fixtures", "xxx.tar.gz"))) + expect_snapshot(error = TRUE, { + pkg_has_src(file.path("fixtures", "xxx.zip")) + pkg_has_src(file.path("fixtures", "xxx.tar.gz")) + }) }) diff --git a/tests/testthat/test-build-process.R b/tests/testthat/test-build-process.R index 1011d17..4541667 100644 --- a/tests/testthat/test-build-process.R +++ b/tests/testthat/test-build-process.R @@ -1,4 +1,3 @@ - # Package without source code -------------------------------------------- test_that("source builds return correct filenames", { @@ -66,7 +65,11 @@ test_that("source builds return correct filenames", { dir.create(tmp <- tempfile()) on.exit(unlink(tmp, recursive = TRUE), add = TRUE) - pr <- pkgbuild_process$new("testWithSrc", dest_path = tmp, register_routines = FALSE) + pr <- pkgbuild_process$new( + "testWithSrc", + dest_path = tmp, + register_routines = FALSE + ) pr$wait(60000) if (pr$is_alive()) { pr$kill() @@ -80,12 +83,16 @@ test_that("source builds return correct filenames", { test_that("build package with src requires compiler", { without_compiler({ - expect_error( - { - pr <- pkgbuild_process$new("testWithSrc", dest_path = tempdir(), register_routines = FALSE) + expect_snapshot( + error = TRUE, + suppressMessages(local({ + pr <- pkgbuild_process$new( + "testWithSrc", + dest_path = tempdir(), + register_routines = FALSE + ) pr$kill() - }, - "Could not find tools" + })) ) }) }) diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index 23ddf0e..099ab45 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -1,4 +1,3 @@ - # Package build setup ---------------------------------------------------- test_that("with*_latex context fixtures force has_latex result", { @@ -14,22 +13,69 @@ test_that("with*_latex context fixtures force has_latex result", { # expect `manual=TRUE` & empty `args` not to add build --no-manual flag test_that("source build setup accept args and/or parameterized helpers", { - expect_silent(res <- with_latex({ - build_setup_source( + expect_silent( + res <- with_latex({ + build_setup_source( + file.path(testthat::test_path(), "testDummy"), + file.path(tempdir(), "testDummyBuild"), + vignettes = FALSE, + manual = TRUE, + clean_doc = FALSE, + args = c(), + needs_compilation = FALSE + ) + }) + ) + expect_true(!"--no-manual" %in% res$args) + + # expect `manual=FALSE` to affect build --no-manual flag + expect_silent( + res <- with_latex({ + build_setup_source( + file.path(testthat::test_path(), "testDummy"), + file.path(tempdir(), "testDummyBuild"), + vignettes = FALSE, + manual = FALSE, + clean_doc = FALSE, + args = c(), + needs_compilation = FALSE + ) + }) + ) + expect_true("--no-manual" %in% res$args) + + # expect `args` "--no-manual" to affect build --no-manual flag + expect_silent( + res <- with_latex({ + build_setup_source( + file.path(testthat::test_path(), "testDummy"), + file.path(tempdir(), "testDummyBuild"), + vignettes = FALSE, + manual = TRUE, + clean_doc = FALSE, + args = c("--no-manual"), + needs_compilation = FALSE + ) + }) + ) + expect_true("--no-manual" %in% res$args) + + expect_silent( + res <- build_setup_source( file.path(testthat::test_path(), "testDummy"), file.path(tempdir(), "testDummyBuild"), - vignettes = FALSE, - manual = TRUE, + vignettes = TRUE, + manual = FALSE, clean_doc = FALSE, args = c(), needs_compilation = FALSE ) - })) - expect_true(!"--no-manual" %in% res$args) + ) + expect_true(!"--no-build-vignettes" %in% res$args) - # expect `manual=FALSE` to affect build --no-manual flag - expect_silent(res <- with_latex({ - build_setup_source( + # expect `vignettes=FALSE` to affect build --no-build-vignettes flag + expect_silent( + res <- build_setup_source( file.path(testthat::test_path(), "testDummy"), file.path(tempdir(), "testDummyBuild"), vignettes = FALSE, @@ -38,56 +84,21 @@ test_that("source build setup accept args and/or parameterized helpers", { args = c(), needs_compilation = FALSE ) - })) - expect_true("--no-manual" %in% res$args) + ) + expect_true("--no-build-vignettes" %in% res$args) - # expect `args` "--no-manual" to affect build --no-manual flag - expect_silent(res <- with_latex({ - build_setup_source( + # expect `arg` `--no-build-vignettes` to produce --no-build-vignettes flag + expect_silent( + res <- build_setup_source( file.path(testthat::test_path(), "testDummy"), file.path(tempdir(), "testDummyBuild"), - vignettes = FALSE, - manual = TRUE, + vignettes = TRUE, + manual = FALSE, clean_doc = FALSE, - args = c("--no-manual"), + args = c("--no-build-vignettes"), needs_compilation = FALSE ) - })) - expect_true("--no-manual" %in% res$args) - - expect_silent(res <- build_setup_source( - file.path(testthat::test_path(), "testDummy"), - file.path(tempdir(), "testDummyBuild"), - vignettes = TRUE, - manual = FALSE, - clean_doc = FALSE, - args = c(), - needs_compilation = FALSE - )) - expect_true(!"--no-build-vignettes" %in% res$args) - - # expect `vignettes=FALSE` to affect build --no-build-vignettes flag - expect_silent(res <- build_setup_source( - file.path(testthat::test_path(), "testDummy"), - file.path(tempdir(), "testDummyBuild"), - vignettes = FALSE, - manual = FALSE, - clean_doc = FALSE, - args = c(), - needs_compilation = FALSE - )) - expect_true("--no-build-vignettes" %in% res$args) - - # expect `arg` `--no-build-vignettes` to produce --no-build-vignettes flag - expect_silent(res <- build_setup_source( - file.path(testthat::test_path(), "testDummy"), - file.path(tempdir(), "testDummyBuild"), - vignettes = TRUE, - manual = FALSE, - clean_doc = FALSE, - args = c("--no-build-vignettes"), - needs_compilation = FALSE - )) + ) expect_true("--no-build-vignettes" %in% res$args) }) @@ -111,7 +122,12 @@ test_that("binary builds return correct filenames", { test_that("can build package without src without compiler", { without_compiler({ - path <- build("testDummy", binary = TRUE, dest_path = tempdir(), quiet = TRUE) + path <- build( + "testDummy", + binary = TRUE, + dest_path = tempdir(), + quiet = TRUE + ) on.exit(unlink(path)) expect_true(file.exists(path)) @@ -122,7 +138,12 @@ test_that("can build package without src without compiler", { # Package with src code --------------------------------------------------- test_that("source builds return correct filenames", { - path <- build("testWithSrc", dest_path = tempdir(), quiet = TRUE, register_routines = FALSE) + path <- build( + "testWithSrc", + dest_path = tempdir(), + quiet = TRUE, + register_routines = FALSE + ) on.exit(unlink(path)) expect_true(file.exists(path)) @@ -130,9 +151,11 @@ test_that("source builds return correct filenames", { test_that("build package with src requires compiler", { without_compiler({ - expect_error( - build("testWithSrc", dest_path = tempdir(), quiet = TRUE), - "Could not find tools" + expect_snapshot( + error = TRUE, + suppressMessages( + build("testWithSrc", dest_path = tempdir(), quiet = TRUE) + ) ) }) }) @@ -143,9 +166,12 @@ test_that("package tarball binary build", { path <- build("testDummy", dest_path = tempdir(), quiet = TRUE) on.exit(unlink(path), add = TRUE) - path2 <- build(path, - dest_path = tempdir(), quiet = TRUE, - binary = TRUE, needs_compilation = FALSE, + path2 <- build( + path, + dest_path = tempdir(), + quiet = TRUE, + binary = TRUE, + needs_compilation = FALSE, compile_attributes = FALSE ) on.exit(unlink(path2), add = TRUE) @@ -158,16 +184,20 @@ test_that("package tarball binary build errors", { path <- build("testDummy", dest_path = tempdir(), quiet = TRUE) on.exit(unlink(path), add = TRUE) - expect_error( - build(path, dest_path = tempdir(), quiet = TRUE), - "binary" + expect_snapshot( + error = TRUE, + build(path, dest_path = tempdir(), quiet = TRUE) ) - expect_error( - build(path, - dest_path = tempdir(), quiet = TRUE, binary = TRUE, - needs_compilation = FALSE, compile_attributes = TRUE - ), - "compile_attributes" + expect_snapshot( + error = TRUE, + build( + path, + dest_path = tempdir(), + quiet = TRUE, + binary = TRUE, + needs_compilation = FALSE, + compile_attributes = TRUE + ) ) }) @@ -181,33 +211,38 @@ test_that("warnings can be turned into errors", { build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE) ) - dir.create(file.path(src, "testDummy", "inst"), recursive = TRUE, showWarnings = FALSE) + dir.create( + file.path(src, "testDummy", "inst"), + recursive = TRUE, + showWarnings = FALSE + ) saveRDS(1:10, file.path(src, "testDummy", "inst", "testthat-problems.rds")) # No warning/error on R <= 3.5 if (getRversion() <= "3.6") skip("Needs R 3.5.0") # Warning looks different on older R - if (getRversion() >= "4.1") { - expect_snapshot( - error = TRUE, - build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE), - transform = function(x) { - x <- sub("\u2018", "'", x, fixed = TRUE) - x <- sub("\u2019", "'", x, fixed = TRUE) - x <- sub("checking for file '.*'", "checking for file ''", x) - x + expect_snapshot( + error = TRUE, + { + if (getRversion() >= "4.1") { + build(file.path(src, "testDummy"), dest_path = dest, quiet = TRUE) + } else { + suppressMessages(build( + file.path(src, "testDummy"), + dest_path = dest, + quiet = TRUE + )) } - ) - } else { - expect_error( - suppressMessages(build( - file.path(src, "testDummy"), - dest_path = dest, - quiet = TRUE - )) - ) - } + }, + transform = function(x) { + x <- sub("\u2018", "'", x, fixed = TRUE) + x <- sub("\u2019", "'", x, fixed = TRUE) + x <- sub("checking for file '.*'", "checking for file ''", x) + x + }, + variant = if (getRversion() >= "4.1") "new" else "old" + ) }) test_that("Config/build/clean-inst-doc FALSE", { diff --git a/tests/testthat/test-build_tools.R b/tests/testthat/test-build_tools.R index 4226833..5f15c37 100644 --- a/tests/testthat/test-build_tools.R +++ b/tests/testthat/test-build_tools.R @@ -1,4 +1,3 @@ - test_that("tests always run in environment with dev tools", { without_cache({ expect_true(has_build_tools()) diff --git a/tests/testthat/test-c-registration.R b/tests/testthat/test-c-registration.R index 0707818..927f106 100644 --- a/tests/testthat/test-c-registration.R +++ b/tests/testthat/test-c-registration.R @@ -1,11 +1,11 @@ - test_that("update_c_registration does nothing if an init.c file already exists", { skip_if(getRversion() < "3.4") init_file <- test_path("testWithSrc", "src", "init.c") on.exit(unlink(init_file)) - writeLines(' + writeLines( + ' #include #include #include // for NULL @@ -26,7 +26,9 @@ void R_init_testWithSrc(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); -}', init_file) +}', + init_file + ) expect_equal( update_c_registration(test_path("testWithSrc")), @@ -47,10 +49,13 @@ test_that("update_c_registration works", { # Add a call and try to update again src_file <- test_path("testWithSrc", "R", "c.R") - writeLines(' + writeLines( + ' add1 <- function(x) { .Call("add1", x) -}', src_file) +}', + src_file + ) on.exit(unlink(src_file), add = TRUE) @@ -65,14 +70,17 @@ add1 <- function(x) { init_lines ) - writeLines(' + writeLines( + ' add1 <- function(x) { .Call("add1", x) } mult2 <- function(x) { .Call("mult2", x) -}', src_file) +}', + src_file + ) # update_c_registration should be idempotent if nothing has changed update_c_registration(test_path("testWithSrc")) diff --git a/tests/testthat/test-compile_dll.R b/tests/testthat/test-compile_dll.R index 1bb2a9a..345b4e6 100644 --- a/tests/testthat/test-compile_dll.R +++ b/tests/testthat/test-compile_dll.R @@ -1,6 +1,8 @@ - test_that("can compile a DLL and clean up afterwards", { - expect_error(compile_dll("testWithSrc", quiet = TRUE, register_routines = FALSE), NA) + expect_error( + compile_dll("testWithSrc", quiet = TRUE, register_routines = FALSE), + NA + ) clean_dll("testWithSrc") expect_equal(dir("testWithSrc/src"), "add1.c") diff --git a/tests/testthat/test-compiler-flags.R b/tests/testthat/test-compiler-flags.R index a1de580..cf7cecb 100644 --- a/tests/testthat/test-compiler-flags.R +++ b/tests/testthat/test-compiler-flags.R @@ -1,4 +1,3 @@ - test_that("has_compiler_colored_diagnostics", { local_mocked_bindings(cache_exists = function(...) stop("nope")) @@ -9,5 +8,5 @@ test_that("has_compiler_colored_diagnostics", { expect_false(has_compiler_colored_diagnostics()) withr::local_envvar(PKG_BUILD_COLOR_DIAGNOSTICS = NA_character_) - expect_error(has_compiler_colored_diagnostics(), "nope") + expect_snapshot(error = TRUE, has_compiler_colored_diagnostics()) }) diff --git a/tests/testthat/test-compiler.R b/tests/testthat/test-compiler.R index fc80397..b7c1925 100644 --- a/tests/testthat/test-compiler.R +++ b/tests/testthat/test-compiler.R @@ -1,4 +1,3 @@ - describe("has_compiler", { withr::local_options(pkgbuild.has_compiler = NULL) testthat::local_reproducible_output() @@ -7,7 +6,7 @@ describe("has_compiler", { without_cache({ without_compiler({ expect_false(has_compiler()) - expect_error(check_compiler(), "Failed to compile C code") + expect_snapshot(error = TRUE, check_compiler()) }) cache_reset() expect_true(has_compiler()) @@ -32,7 +31,7 @@ describe("has_compiler", { c(pkgbuild.has_compiler = FALSE), { expect_false(has_compiler()) - expect_error(check_compiler(), "Failed to compile C code") + expect_snapshot(error = TRUE, check_compiler()) } ) withr::with_options( diff --git a/tests/testthat/test-exclude.R b/tests/testthat/test-exclude.R index 8fbea3b..b2b86d7 100644 --- a/tests/testthat/test-exclude.R +++ b/tests/testthat/test-exclude.R @@ -1,4 +1,3 @@ - test_that("copy_package_tree creates package dir", { tmp <- withr::local_tempdir("pkgbuild-test-") @@ -26,9 +25,13 @@ test_that("copy_package_tree creates package dir", { test_that("copy_package_tree errors", { tmp <- withr::local_tempdir("pkgbuild-test-") mkdirp(file.path(tmp, "testDummy")) - expect_error( + expect_snapshot( + error = TRUE, copy_package_tree(test_path("testDummy"), tmp), - "already exists" + transform = function(x) { + x <- transform_tempdir(x) + sub("test-[0-9a-f]+", "test-", x) + } ) }) @@ -41,10 +44,13 @@ test_that("exclusions", { ) # create some structure with files to ignore and keep - writeLines(c( - "^docs$", - "^src/.*[.]o$" - ), file.path(pkgdir, ".Rbuildignore")) + writeLines( + c( + "^docs$", + "^src/.*[.]o$" + ), + file.path(pkgdir, ".Rbuildignore") + ) mkdirp(file.path(pkgdir, "src")) file.create(file.path(pkgdir, "src", "src.c")) @@ -75,10 +81,10 @@ test_that("get_copy_method", { expect_equal(get_copy_method(), "copy") withr::local_options(pkg.build_copy_method = "foobar") - expect_error(get_copy_method(), "pkg.build_copy_method") + expect_snapshot(error = TRUE, get_copy_method()) withr::local_options(pkg.build_copy_method = 1:10) - expect_error(get_copy_method(), "It must be a string") + expect_snapshot(error = TRUE, get_copy_method()) withr::local_options(pkg.build_copy_method = NULL) local_mocked_bindings(desc_get = function(...) "link", .package = "desc") @@ -94,11 +100,14 @@ test_that("Ignoring .Rbuildignore", { ) # create some structure with files to ignore and keep - writeLines(c( - "^docs$", - "^src/.*[.]o$", - "^\\.Rbuildignore$" - ), file.path(pkgdir, ".Rbuildignore")) + writeLines( + c( + "^docs$", + "^src/.*[.]o$", + "^\\.Rbuildignore$" + ), + file.path(pkgdir, ".Rbuildignore") + ) mkdirp(file.path(pkgdir, "src")) file.create(file.path(pkgdir, "src", "src.c")) @@ -136,12 +145,14 @@ test_that("cp error", { test_that("detect_cp_args", { local_mocked_bindings( - run = function(...) stop("nope"), .package = "processx" + run = function(...) stop("nope"), + .package = "processx" ) expect_snapshot(detect_cp_args()) local_mocked_bindings( - run = function(f1, f2) file.create(f2), .package = "processx" + run = function(f1, f2) file.create(f2), + .package = "processx" ) expect_snapshot(detect_cp_args()) }) diff --git a/tests/testthat/test-find-package-root.R b/tests/testthat/test-find-package-root.R index 848ddde..f0e265f 100644 --- a/tests/testthat/test-find-package-root.R +++ b/tests/testthat/test-find-package-root.R @@ -12,14 +12,16 @@ test_that("find_package_root", { expect_equal( readLines(file.path( - find_package_root(file.path(tmp, "a")), "DESCRIPTION" + find_package_root(file.path(tmp, "a")), + "DESCRIPTION" )), lns ) expect_equal( readLines(file.path( - find_package_root(file.path(tmp, "a", "b", "c", "d")), "DESCRIPTION" + find_package_root(file.path(tmp, "a", "b", "c", "d")), + "DESCRIPTION" )), lns ) @@ -34,15 +36,9 @@ test_that("find_package_root", { }) test_that("find_package_root errors", { - expect_error( - find_package_root(basename(tempfile())), - "Path does not exist" - ) + expect_snapshot(error = TRUE, find_package_root("file1130e91427d3")) if (!file.exists("/DESCRIPTION")) { - expect_error( - find_package_root("/"), - "Could not find R package" - ) + expect_snapshot(error = TRUE, find_package_root("/")) } }) diff --git a/tests/testthat/test-rtools.R b/tests/testthat/test-rtools.R index 5d835b6..0014018 100644 --- a/tests/testthat/test-rtools.R +++ b/tests/testthat/test-rtools.R @@ -1,4 +1,3 @@ - test_that("has_rtools finds rtools", { skip_if_not(is_windows() && !is.null(scan_path_for_rtools())) diff --git a/tests/testthat/test-style.R b/tests/testthat/test-style.R index 4fbb838..a8a6b94 100644 --- a/tests/testthat/test-style.R +++ b/tests/testthat/test-style.R @@ -2,12 +2,18 @@ test_that("style", { withr::local_options(cli.num_colors = 256) expect_snapshot( cat(style( - ok = "OK", "\n", - note = "NOTE", "\n", - warn = "WARN", "\n", - err = "ERROR", "\n", - pale = "Not important", "\n", - timing = "[1m]", "\n" + ok = "OK", + "\n", + note = "NOTE", + "\n", + warn = "WARN", + "\n", + err = "ERROR", + "\n", + pale = "Not important", + "\n", + timing = "[1m]", + "\n" )) ) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 9acb8e3..66550af 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,4 +1,3 @@ - test_that("should_stop_for_warnings", { withr::local_options(pkg.build_stop_for_warnings = NULL) withr::local_envvar(PKG_BUILD_STOP_FOR_WARNINGS = NA_character_) @@ -22,11 +21,11 @@ test_that("should_stop_for_warnings", { withr::local_options(pkg.build_stop_for_warnings = 1:10) withr::local_envvar(PKG_BUILD_STOP_FOR_WARNINGS = "false") - expect_error(should_stop_for_warnings(), "option must be") + expect_snapshot(error = TRUE, should_stop_for_warnings()) withr::local_options(pkg.build_stop_for_warnings = NULL) withr::local_envvar(PKG_BUILD_STOP_FOR_WARNINGS = "foobar") - expect_error(should_stop_for_warnings(), "environment variable must be") + expect_snapshot(error = TRUE, should_stop_for_warnings()) }) test_that("isFALSE", { diff --git a/tests/testthat/test-withr.R b/tests/testthat/test-withr.R index 1aadddf..c906b2c 100644 --- a/tests/testthat/test-withr.R +++ b/tests/testthat/test-withr.R @@ -1,4 +1,3 @@ - test_that("withr_with_makevars", { skip_on_cran() # need to run this without a user Makevars file @@ -18,10 +17,13 @@ test_that("withr_with_makevars", { # with our own custom Makevars file tmp <- tempfile() on.exit(unlink(tmp), add = TRUE) - writeLines(c( - "CFLAGS=-DTHIS", - "CXXFLAGS+=-DTHAT" - ), tmp) + writeLines( + c( + "CFLAGS=-DTHIS", + "CXXFLAGS+=-DTHAT" + ), + tmp + ) orig <- split_lines(callr::rcmd("config", "CFLAGS")$stdout) new <- withr_with_makevars( diff --git a/tests/testthat/testInstDoc/vignettes/test.Rmd b/tests/testthat/testInstDoc/vignettes/test.Rmd index aafe190..0331870 100644 --- a/tests/testthat/testInstDoc/vignettes/test.Rmd +++ b/tests/testthat/testInstDoc/vignettes/test.Rmd @@ -9,7 +9,9 @@ vignette: > \usepackage[utf8]{inputenc} --- -```{r, setup, include = FALSE} +```{r} +#| label: setup +#| include: FALSE knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ```