Skip to content

Commit

Permalink
withr::local_tempdir instead of tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Jan 30, 2024
1 parent 7c2af1a commit 96c6f8a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Imports:
httr,
jsonlite,
sys,
utils
utils,
withr
Suggests:
knitr,
rmarkdown,
testthat,
withr
testthat
VignetteBuilder:
knitr
Config/fusen/version: 0.5.2
Expand Down
2 changes: 1 addition & 1 deletion R/with_nix.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ with_nix <- function(expr,

# 1) save all function args onto a temporary folder each with
# `<tag.Rds>` and `value` as serialized objects from RAM ---------------------
temp_dir <- tempdir()
temp_dir <- withr::local_tempdir()
serialize_args(args, temp_dir)

# cast list of symbols/names and calls to list of strings; this is to prepare
Expand Down
22 changes: 13 additions & 9 deletions dev/flat_rix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ flag_rpkgs
```{r, tests-rix}
testthat::test_that("Snapshot test of rix()", {
save_default_nix_test <- function(ide) {
path_default_nix <- withr::local_tempdir()
path_default_nix <- tempdir()
save_default_nix_test <- function(ide, path_default_nix) {
rix(r_ver = "4.3.1",
r_pkgs = c("dplyr", "janitor", "AER@1.2-8", "quarto"),
Expand All @@ -419,21 +419,24 @@ testthat::test_that("Snapshot test of rix()", {
testthat::announce_snapshot_file("find_rev/rstudio_default.nix")
testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "rstudio"),
path = save_default_nix_test(ide = "rstudio",
path_default_nix),
name = "rstudio_default.nix",
)
testthat::announce_snapshot_file("find_rev/other_default.nix")
testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "other"),
path = save_default_nix_test(ide = "other",
path_default_nix),
name = "other_default.nix"
)
testthat::announce_snapshot_file("find_rev/code_default.nix")
testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "code"),
path = save_default_nix_test(ide = "code",
path_default_nix),
name = "code_default.nix"
)
Expand All @@ -444,9 +447,9 @@ testthat::test_that("Snapshot test of rix()", {
```{r, tests-add_quarto_to_sys_pkgs}
testthat::test_that("Quarto gets added to sys packages", {
save_default_nix_test <- function(pkgs) {
path_default_nix <- withr::local_tempdir()
path_default_nix <- tempdir()
save_default_nix_test <- function(pkgs, path_default_nix) {
rix(r_ver = "4.3.1",
r_pkgs = pkgs,
Expand All @@ -461,14 +464,15 @@ testthat::test_that("Quarto gets added to sys packages", {
testthat::announce_snapshot_file("find_rev/no_quarto_default.nix")
testthat::expect_snapshot_file(
path = save_default_nix_test(pkgs = "dplyr"),
path = save_default_nix_test(pkgs = "dplyr", path_default_nix),
name = "no_quarto_default.nix",
)
testthat::announce_snapshot_file("find_rev/yes_quarto_default.nix")
testthat::expect_snapshot_file(
path = save_default_nix_test(pkgs = c("dplyr", "quarto")),
path = save_default_nix_test(pkgs = c("dplyr", "quarto"),
path_default_nix),
name = "yes_quarto_default.nix"
)
Expand Down
6 changes: 3 additions & 3 deletions dev/flat_rix_init.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ nix_rprofile <- function() {
```{r, tests-rix_init}
testthat::test_that("Snapshot test of rix_init()", {
save_rix_init_test <- function() {
path_env_nix <- withr::local_tempdir()
path_env_nix <- tempdir()
save_rix_init_test <- function(path_env_nix) {
rix_init(
project_path = path_env_nix,
Expand All @@ -344,7 +344,7 @@ testthat::test_that("Snapshot test of rix_init()", {
testthat::announce_snapshot_file("find_rev/golden_Rprofile.txt")
testthat::expect_snapshot_file(
path = save_rix_init_test(),
path = save_rix_init_test(path_env_nix),
name = "golden_Rprofile.txt",
)
})
Expand Down
2 changes: 1 addition & 1 deletion dev/flat_with_nix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ with_nix <- function(expr,
# 1) save all function args onto a temporary folder each with
# `<tag.Rds>` and `value` as serialized objects from RAM ---------------------
temp_dir <- tempdir()
temp_dir <- withr::local_tempdir()
serialize_args(args, temp_dir)
# cast list of symbols/names and calls to list of strings; this is to prepare
Expand Down
22 changes: 13 additions & 9 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

testthat::test_that("Snapshot test of rix()", {

save_default_nix_test <- function(ide) {
path_default_nix <- withr::local_tempdir()

path_default_nix <- tempdir()
save_default_nix_test <- function(ide, path_default_nix) {

rix(r_ver = "4.3.1",
r_pkgs = c("dplyr", "janitor", "AER@1.2-8", "quarto"),
Expand All @@ -30,21 +30,24 @@ testthat::test_that("Snapshot test of rix()", {
testthat::announce_snapshot_file("find_rev/rstudio_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "rstudio"),
path = save_default_nix_test(ide = "rstudio",
path_default_nix),
name = "rstudio_default.nix",
)

testthat::announce_snapshot_file("find_rev/other_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "other"),
path = save_default_nix_test(ide = "other",
path_default_nix),
name = "other_default.nix"
)

testthat::announce_snapshot_file("find_rev/code_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "code"),
path = save_default_nix_test(ide = "code",
path_default_nix),
name = "code_default.nix"
)

Expand All @@ -53,9 +56,9 @@ testthat::test_that("Snapshot test of rix()", {

testthat::test_that("Quarto gets added to sys packages", {

save_default_nix_test <- function(pkgs) {
path_default_nix <- withr::local_tempdir()

path_default_nix <- tempdir()
save_default_nix_test <- function(pkgs, path_default_nix) {

rix(r_ver = "4.3.1",
r_pkgs = pkgs,
Expand All @@ -70,14 +73,15 @@ testthat::test_that("Quarto gets added to sys packages", {
testthat::announce_snapshot_file("find_rev/no_quarto_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(pkgs = "dplyr"),
path = save_default_nix_test(pkgs = "dplyr", path_default_nix),
name = "no_quarto_default.nix",
)

testthat::announce_snapshot_file("find_rev/yes_quarto_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(pkgs = c("dplyr", "quarto")),
path = save_default_nix_test(pkgs = c("dplyr", "quarto"),
path_default_nix),
name = "yes_quarto_default.nix"
)

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-rix_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

testthat::test_that("Snapshot test of rix_init()", {

save_rix_init_test <- function() {
path_env_nix <- withr::local_tempdir()

path_env_nix <- tempdir()
save_rix_init_test <- function(path_env_nix) {

rix_init(
project_path = path_env_nix,
Expand All @@ -19,7 +19,7 @@ testthat::test_that("Snapshot test of rix_init()", {
testthat::announce_snapshot_file("find_rev/golden_Rprofile.txt")

testthat::expect_snapshot_file(
path = save_rix_init_test(),
path = save_rix_init_test(path_env_nix),
name = "golden_Rprofile.txt",
)
})

0 comments on commit 96c6f8a

Please sign in to comment.