Skip to content

Commit

Permalink
added add = TRUE to all on.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Sep 17, 2024
1 parent 9cccc2a commit 3ee9962
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 61 deletions.
5 changes: 4 additions & 1 deletion R/fetchers.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ get_imports <- function(path) {

existing_columns <- intersect(columns_of_interest, colnames(imports))

on.exit(unlink(tmp_dir, recursive = TRUE))
on.exit(
unlink(tmp_dir, recursive = TRUE),
add = TRUE
)

imports <- imports[, existing_columns, drop = FALSE]

Expand Down
5 changes: 4 additions & 1 deletion R/nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ nix_build <- function(project_path = ".",
if (nzchar(LD_LIBRARY_PATH_default)) {
# set old LD_LIBRARY_PATH (only if system's R session and if it wasn't
# `""`)
on.exit(Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default))
on.exit(
Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default),
add = TRUE
)
}
}

Expand Down
9 changes: 7 additions & 2 deletions R/nix_hash.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ nix_hash <- function(repo_url, commit) {
#' @noRd
hash_url <- function(url) {
path_to_folder <- paste0(
tempdir(), "repo",
tempdir(), "repo_hash_url_",
paste0(sample(letters, 5), collapse = "")
)

dir.create(path_to_folder)

path_to_tarfile <- paste0(path_to_folder, "/package_tar_gz")
path_to_src <- paste0(path_to_folder, "/package_src")

Expand Down Expand Up @@ -146,7 +148,10 @@ nix_sri_hash <- function(path) {
if (isTRUE(needs_ld_fix)) {
# set old LD_LIBRARY_PATH (only if non-Nix R session, and if it wasn't
# `""`)
on.exit(Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default))
on.exit(
Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default),
add = TRUE
)
}

sri_hash <- sys::as_text(proc$stdout)
Expand Down
7 changes: 4 additions & 3 deletions R/rix_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ rix_init <- function(project_path = ".",
cat(readLines(con = file(rprofile_file)), sep = "\n")
}

on.exit({
close(file(rprofile_file))
})
on.exit(
close(file(rprofile_file)),
add = TRUE
)
}

#' Get character vector of length two with comment and code write `.Rprofile`
Expand Down
6 changes: 4 additions & 2 deletions R/with_nix.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ with_nix <- function(expr,
# `""`)
on.exit({
Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default)
})
},
add = TRUE)
}
}

Expand Down Expand Up @@ -356,7 +357,8 @@ with_nix <- function(expr,
tools::pskill(pid = proc)
}
},
after = FALSE
after = FALSE,
add = TRUE
)

return(out)
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ testthat::test_that("Testing that `nix_build()` builds derivation", {
)
)

on.exit({
unlink(path_subshell, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_subshell, recursive = TRUE, force = TRUE),
add = TRUE
)
})
88 changes: 51 additions & 37 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ testthat::test_that("rix(), ide is 'rstudio', Linux", {
name = "rstudio_default.nix",
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})


Expand Down Expand Up @@ -105,9 +106,10 @@ testthat::test_that("rix(), ide is 'other' or 'code'", {
name = "code_default.nix"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})


Expand Down Expand Up @@ -152,9 +154,10 @@ testthat::test_that("Quarto gets added to sys packages", {
name = "yes_quarto_default.nix"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("If on darwin and ide = rstudio, raise warning", {
Expand All @@ -180,9 +183,10 @@ testthat::test_that("If on darwin and ide = rstudio, raise warning", {
regexp = "refer to the macOS"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("If R version is 4.4.0, raise warning", {
Expand All @@ -206,9 +210,10 @@ testthat::test_that("If R version is 4.4.0, raise warning", {
regexp = "version is not available"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("If R version is <= 4.1.1, raise warning", {
Expand All @@ -233,9 +238,10 @@ testthat::test_that("If R version is <= 4.1.1, raise warning", {
)


on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("If on ide = rstudio, but no R packages, raise error", {
Expand All @@ -259,9 +265,10 @@ testthat::test_that("If on ide = rstudio, but no R packages, raise error", {
regexp = "didn't add any R packages"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("If R version is == 3.5.3, raise warning", {
Expand All @@ -285,9 +292,10 @@ testthat::test_that("If R version is == 3.5.3, raise warning", {
regexp = "older version of R"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("rix(), bleeding_edge", {
Expand Down Expand Up @@ -333,9 +341,10 @@ testthat::test_that("rix(), bleeding_edge", {
name = "bleeding_edge_default.nix",
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("rix(), frozen_edge", {
Expand Down Expand Up @@ -396,7 +405,9 @@ testthat::test_that("rix(), frozen_edge", {
paste0("sed -i 's/", frozen_edge_commit, "/REVISION/' _snaps/rix/frozen_edge_default.nix")
)
unlink(path_default_nix, recursive = TRUE, force = FALSE)
})
},
add = TRUE
)
})


Expand Down Expand Up @@ -432,9 +443,10 @@ testthat::test_that("rix(), only one Github package", {
name = "one_git_default.nix",
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})


Expand Down Expand Up @@ -462,9 +474,10 @@ testthat::test_that("rix(), conclusion message", {
regexp = "Successfully"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})


Expand Down Expand Up @@ -509,7 +522,8 @@ testthat::test_that("rix(), warning message if rix_init() already called", {
regexp = "You may"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})
7 changes: 4 additions & 3 deletions tests/testthat/test-rix_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ testthat::test_that("Snapshot test of rix_init()", {
name = "golden_Rprofile.txt",
)

on.exit({
unlink(path_env_nix, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_env_nix, recursive = TRUE, force = TRUE),
add = TRUE
)
})
21 changes: 12 additions & 9 deletions tests/testthat/test-with_nix.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", {
all(c(2, 6, 5, 8, 9) == out_subshell)
)

on.exit({
unlink(path_subshell, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_subshell, recursive = TRUE, force = TRUE),
add = TRUE
)
})

testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", {
Expand Down Expand Up @@ -83,9 +84,10 @@ testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", {
)


on.exit({
unlink(path_subshell, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_subshell, recursive = TRUE, force = TRUE),
add = TRUE
)
})


Expand Down Expand Up @@ -121,7 +123,8 @@ testthat::test_that("Test `with_nix()` correct .libPaths()", {
is.character(out_subshell)
)

on.exit({
unlink(path_subshell, recursive = TRUE, force = TRUE)
})
on.exit(
unlink(path_subshell, recursive = TRUE, force = TRUE),
add = TRUE
)
})

0 comments on commit 3ee9962

Please sign in to comment.