| 1 |
|
| 2 |
test_that("renv reports errors when decompressing invalid archives", { |
| 3 |
|
| 4 |
badtar <- renv_scope_tempfile(fileext = ".tar") |
| 5 |
writeLines("oh no", con = badtar) |
| 6 |
expect_error(renv_archive_decompress(badtar, verbose = TRUE)) |
| 7 |
|
| 8 |
badzip <- renv_scope_tempfile(fileext = ".zip") |
| 9 |
writeLines("oh no", con = badzip) |
| 10 |
expect_error(renv_archive_decompress(badzip)) |
| 11 |
|
| 12 |
}) |
| 13 |
|
| 14 |
test_that("we can successfully compress / decompress some sample files", { |
| 15 |
|
| 16 |
renv_scope_tempdir() |
| 17 |
|
| 18 |
for (letter in letters) |
| 19 |
writeLines(letter, con = letter) |
| 20 |
|
| 21 |
tarfile <- renv_scope_tempfile(fileext = ".tar.gz") |
| 22 |
tar(tarfile, files = ".") |
| 23 |
|
| 24 |
actual <- list.files() |
| 25 |
expected <- setdiff(basename(renv_archive_list(tarfile)), ".") |
| 26 |
expect_setequal(actual, expected) |
| 27 |
|
| 28 |
exdir <- renv_scope_tempfile() |
| 29 |
renv_archive_decompress(tarfile, exdir = exdir) |
| 30 |
expect_setequal(list.files(exdir), list.files()) |
| 31 |
|
| 32 |
zipper <- Sys.getenv("R_ZIPCMD", unset = "zip") |
| 33 |
if (nzchar(Sys.which(zipper))) { |
| 34 |
|
| 35 |
zipfile <- renv_scope_tempfile(fileext = ".zip") |
| 36 |
zip(zipfile, files = ".", extras = "-q") |
| 37 |
|
| 38 |
actual <- list.files() |
| 39 |
expected <- basename(renv_archive_list(zipfile)) |
| 40 |
expect_setequal(actual, expected) |
| 41 |
|
| 42 |
exdir <- renv_scope_tempfile() |
| 43 |
renv_archive_decompress(zipfile, exdir = exdir) |
| 44 |
expect_setequal(list.files(exdir), list.files()) |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
}) |
| 49 |
|
| 50 |
test_that("we can decompress an archive with a tilde path", { |
| 51 |
skip_on_cran() |
| 52 |
skip_on_windows() |
| 53 |
|
| 54 |
renv_tests_scope() |
| 55 |
renv_scope_envvars(HOME = getwd()) |
| 56 |
renv_scope_envvars(tar = Sys.which("tar")) |
| 57 |
|
| 58 |
# check that we actually set home correctly? |
| 59 |
if (!identical(path.expand("~"), getwd())) |
| 60 |
skip("couldn't override home path") |
| 61 |
|
| 62 |
# NOTE: in older versions of R, only paths to directory were accepted, |
| 63 |
# so we run out test by attempting to tar up a directory rather than file |
| 64 |
dir.create("subdir") |
| 65 |
writeLines("hello", con = "subdir/a.txt") |
| 66 |
writeLines("goodbye", con = "subdir/b.txt") |
| 67 |
tar("files.tar.gz", files = "subdir", compression = "gzip") |
| 68 |
unlink("subdir", recursive = TRUE) |
| 69 |
|
| 70 |
# double check the files we have in the archive |
| 71 |
# (renv_archive_list might report the folder itself so test files individually) |
| 72 |
files <- renv_archive_list("files.tar.gz") |
| 73 |
expect_true("subdir/a.txt" %in% files) |
| 74 |
expect_true("subdir/b.txt" %in% files) |
| 75 |
expect_false(file.exists("subdir/a.txt")) |
| 76 |
expect_false(file.exists("subdir/b.txt")) |
| 77 |
|
| 78 |
archive <- "~/files.tar.gz" |
| 79 |
if (!file.exists(archive)) |
| 80 |
skip("archive does not exist in home directory") |
| 81 |
|
| 82 |
renv_archive_decompress( |
| 83 |
archive = archive, |
| 84 |
exdir = getwd() |
| 85 |
) |
| 86 |
|
| 87 |
expect_true(file.exists("subdir/a.txt")) |
| 88 |
expect_true(file.exists("subdir/b.txt")) |
| 89 |
|
| 90 |
}) |