tests/testthat/test-with_here.R

library(withr)
suppressMessages(library(here))
library(fs)

source(test_path("helpers.R"))

test_that("with_here works", {

    # setup a working directory
    d <- local_tempdir()

    expect_pathequal(with_here(d, here()), d)

    # check that getwd is unaffected
    expect_pathequal(with_here(d, getwd()), getwd())
    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)

})

Try the wither package in your browser

Any scripts or data that you put into this service are public.

wither documentation built on Sept. 13, 2024, 1:10 a.m.