Skip to content

Commit

Permalink
tests for restoring getwd
Browse files Browse the repository at this point in the history
  • Loading branch information
Torbjørn Lindahl authored and AnjaMinsaas committed Sep 10, 2024
1 parent 2eb6080 commit 3703598
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/testthat/test-local_here.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,26 @@ test_that("local_here works", {
expect_pathequal(here(), here_was)

})

test_that("working directory doesn't change", {

# go to a tempdir
local_dir(local_tempdir())

here_was <- here()
wd_was <- getwd()

local({

d <- local_tempdir()
local_here(d)

# here is now d
expect_pathequal(d, here())

})

expect_pathequal(here_was, here())
expect_pathequal(getwd(), wd_was)

})
19 changes: 19 additions & 0 deletions tests/testthat/test-with_here.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ test_that("with_here works", {
expect_pathequal(with_here(d, getwd(), chdir = TRUE), d)

})

test_that("working directory doesn't change", {

# go to a tempdir
local_dir(local_tempdir())

here_was <- here()
wd_was <- getwd()


d <- local_tempdir()
now <- with_here(d, here())

expect_pathequal(d, now)

expect_pathequal(here_was, here())
expect_pathequal(getwd(), wd_was)

})

0 comments on commit 3703598

Please sign in to comment.