| 1 |
test_that("`action` is checked", { |
| 2 |
expect_snapshot_error(with_path("foo", NULL, action = "Suffix")) |
| 3 |
}) |
| 4 |
|
| 5 |
test_that("with_path works and resets path", { |
| 6 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 7 |
new_path <- normalizePath(".") |
| 8 |
with_path( |
| 9 |
new_path, |
| 10 |
{ |
| 11 |
expect_equal(normalizePath(new_path), head(get_path(), n = 1)) |
| 12 |
expect_equal(length(get_path()), length(current) + 1L) |
| 13 |
} |
| 14 |
) |
| 15 |
expect_equal(current, get_path()) |
| 16 |
}) |
| 17 |
|
| 18 |
test_that("with_path with suffix action works and resets path", { |
| 19 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 20 |
new_path <- normalizePath(".") |
| 21 |
with_path( |
| 22 |
new_path, |
| 23 |
action = "suffix", |
| 24 |
{ |
| 25 |
expect_equal(normalizePath(new_path), tail(get_path(), n = 1)) |
| 26 |
expect_equal(length(get_path()), length(current) + 1L) |
| 27 |
} |
| 28 |
) |
| 29 |
expect_equal(current, get_path()) |
| 30 |
}) |
| 31 |
|
| 32 |
test_that("with_path with replace action works and resets path", { |
| 33 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 34 |
new_path <- normalizePath(".") |
| 35 |
with_path( |
| 36 |
new_path, |
| 37 |
action = "replace", |
| 38 |
{ |
| 39 |
expect_equal(normalizePath(new_path), get_path()) |
| 40 |
expect_equal(length(get_path()), 1L) |
| 41 |
} |
| 42 |
) |
| 43 |
expect_equal(current, get_path()) |
| 44 |
}) |
| 45 |
|
| 46 |
test_that("local_path works and resets path", { |
| 47 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 48 |
new_path <- normalizePath(".") |
| 49 |
local({ |
| 50 |
local_path(new_path) |
| 51 |
expect_equal(normalizePath(new_path), head(get_path(), n = 1)) |
| 52 |
expect_equal(length(get_path()), length(current) + 1L) |
| 53 |
}) |
| 54 |
expect_equal(current, get_path()) |
| 55 |
}) |
| 56 |
|
| 57 |
test_that("local_path with suffix action works and resets path", { |
| 58 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 59 |
new_path <- normalizePath(".") |
| 60 |
local({ |
| 61 |
local_path(new_path, action = "suffix") |
| 62 |
expect_equal(normalizePath(new_path), tail(get_path(), n = 1)) |
| 63 |
expect_equal(length(get_path()), length(current) + 1L) |
| 64 |
}) |
| 65 |
expect_equal(current, get_path()) |
| 66 |
}) |
| 67 |
|
| 68 |
test_that("local_path with replace action works and resets path", { |
| 69 |
current <- normalizePath(get_path(), mustWork = FALSE) |
| 70 |
new_path <- normalizePath(".") |
| 71 |
local({ |
| 72 |
local_path(new_path, action = "replace") |
| 73 |
expect_equal(normalizePath(new_path), get_path()) |
| 74 |
expect_equal(length(get_path()), 1L) |
| 75 |
}) |
| 76 |
expect_equal(current, get_path()) |
| 77 |
}) |