| 1 |
describe("file_delete", { |
| 2 |
with_dir_tree(list("foo/bar" = "test"), { |
| 3 |
it("returns the input path and deletes the file", { |
| 4 |
expect_true(file_exists("foo/bar")) |
| 5 |
expect_equal(file_delete("foo/bar"), fs_path("foo/bar")) |
| 6 |
expect_false(file_exists("foo/bar")) |
| 7 |
}) |
| 8 |
it("can delete directories and files", { |
| 9 |
dir_create("baz") |
| 10 |
|
| 11 |
expect_true(dir_exists("baz")) |
| 12 |
expect_equal(file_delete("baz"), fs_path("baz")) |
| 13 |
expect_false(dir_exists("baz")) |
| 14 |
|
| 15 |
dir_create("baz") |
| 16 |
file_create(c("baz/bar", "faz")) |
| 17 |
|
| 18 |
expect_true(dir_exists("baz")) |
| 19 |
expect_true(file_exists("faz")) |
| 20 |
|
| 21 |
expect_equal(file_delete(c("baz", "faz")), fs_path(c("baz", "faz"))) |
| 22 |
|
| 23 |
expect_false(dir_exists("baz")) |
| 24 |
expect_false(file_exists("faz")) |
| 25 |
}) |
| 26 |
it("errors on missing input", { |
| 27 |
expect_error(file_delete(NA), class = "invalid_argument") |
| 28 |
}) |
| 29 |
}) |
| 30 |
}) |
| 31 |
|
| 32 |
describe("dir_delete", { |
| 33 |
it("deletes an empty directory and returns the path", { |
| 34 |
with_dir_tree(list("foo"), { |
| 35 |
expect_true(dir_exists("foo")) |
| 36 |
expect_equal(dir_delete("foo"), fs_path("foo")) |
| 37 |
expect_false(dir_exists("foo")) |
| 38 |
}) |
| 39 |
}) |
| 40 |
it("deletes a non-empty directory and returns the path", { |
| 41 |
with_dir_tree( |
| 42 |
list("foo/bar" = "test", "foo/baz" = "test2"), |
| 43 |
{ |
| 44 |
expect_true(dir_exists("foo")) |
| 45 |
expect_equal(dir_delete("foo"), fs_path("foo")) |
| 46 |
expect_false(dir_exists("foo")) |
| 47 |
} |
| 48 |
) |
| 49 |
}) |
| 50 |
it("deletes nested directories and returns the path", { |
| 51 |
with_dir_tree( |
| 52 |
list("foo/bar/baz" = "test", "foo/baz/qux" = "test2"), |
| 53 |
{ |
| 54 |
expect_true(dir_exists("foo")) |
| 55 |
expect_equal(dir_delete("foo"), fs_path("foo")) |
| 56 |
expect_false(dir_exists("foo")) |
| 57 |
} |
| 58 |
) |
| 59 |
}) |
| 60 |
it("deletes a non-empty directory with hidden files and directories and returns the path", { |
| 61 |
with_dir_tree( |
| 62 |
list( |
| 63 |
"foo/bar" = "test", |
| 64 |
"foo/baz" = "test2", |
| 65 |
"foo/.blah" = "foo", |
| 66 |
".dir" |
| 67 |
), |
| 68 |
{ |
| 69 |
expect_true(dir_exists("foo")) |
| 70 |
expect_equal(dir_delete("foo"), fs_path("foo")) |
| 71 |
expect_false(dir_exists("foo")) |
| 72 |
} |
| 73 |
) |
| 74 |
}) |
| 75 |
it("errors on missing input", { |
| 76 |
expect_error(dir_delete(NA), class = "invalid_argument") |
| 77 |
}) |
| 78 |
}) |
| 79 |
|
| 80 |
describe("link_delete", { |
| 81 |
skip_on_os("windows") |
| 82 |
|
| 83 |
with_dir_tree(list("foo/bar" = "test"), { |
| 84 |
link_create("foo/bar", "loo") |
| 85 |
it("returns the input path and deletes the file", { |
| 86 |
expect_true(file_exists("loo")) |
| 87 |
expect_equal(link_delete("loo"), fs_path("loo")) |
| 88 |
expect_false(file_exists("loo")) |
| 89 |
}) |
| 90 |
it("errors on missing input", { |
| 91 |
expect_error(link_delete(NA), class = "invalid_argument") |
| 92 |
}) |
| 93 |
it("errors on non-link input", { |
| 94 |
expect_error(link_delete("foo"), class = "invalid_argument") |
| 95 |
expect_error(link_delete("foo/bar"), class = "invalid_argument") |
| 96 |
}) |
| 97 |
}) |
| 98 |
}) |