| 1 |
|
| 2 |
test_that("we can use R CMD build to build a package", { |
| 3 |
skip_on_cran() |
| 4 |
if (renv_platform_windows()) { |
| 5 |
zip <- Sys.which("zip") |
| 6 |
if (!nzchar(zip)) |
| 7 |
skip("test requires 'zip'") |
| 8 |
} |
| 9 |
|
| 10 |
testdir <- renv_scope_tempfile("renv-r-tests-") |
| 11 |
ensure_directory(testdir) |
| 12 |
# R CMD install creates file in working directory |
| 13 |
renv_scope_wd(testdir) |
| 14 |
|
| 15 |
package <- "sample.package" |
| 16 |
pkgdir <- file.path(testdir, package) |
| 17 |
ensure_directory(pkgdir) |
| 18 |
|
| 19 |
data <- list(Package = package, Type = "Package", Version = "0.1.0") |
| 20 |
renv_dcf_write(data, file = file.path(pkgdir, "DESCRIPTION")) |
| 21 |
expect_equal(renv_project_type(pkgdir), "package") |
| 22 |
|
| 23 |
tarball <- r_cmd_build(package, pkgdir) |
| 24 |
ensure_existing_path(tarball) |
| 25 |
ensure_existing_file(tarball) |
| 26 |
expect_true(file.exists(tarball)) |
| 27 |
files <- renv_archive_list(tarball) |
| 28 |
expect_true(all(c("DESCRIPTION", "NAMESPACE", "MD5") %in% basename(files))) |
| 29 |
|
| 30 |
# NOTE: R 3.6 seems to check the permissions of the target library, |
| 31 |
# even when you just want to build a binary? |
| 32 |
before <- list.files(testdir) |
| 33 |
args <- c( |
| 34 |
"CMD", "INSTALL", |
| 35 |
"-l", renv_shell_path(tempdir()), |
| 36 |
"--no-multiarch", |
| 37 |
"--build", package |
| 38 |
) |
| 39 |
output <- r(args, stdout = TRUE, stderr = TRUE) |
| 40 |
after <- list.files(testdir) |
| 41 |
binball <- renv_vector_diff(after, c("NULL", before)) |
| 42 |
|
| 43 |
expect_true(length(binball) == 1L) |
| 44 |
expect_equal(renv_package_type(binball), "binary") |
| 45 |
}) |
| 46 |
|
| 47 |
test_that("we can supply custom options to R CMD INSTALL", { |
| 48 |
skip_on_cran() |
| 49 |
renv_tests_scope() |
| 50 |
|
| 51 |
# work in new renv context (don't re-use cache) |
| 52 |
renv_scope_envvars(RENV_PATHS_ROOT = renv_scope_tempfile()) |
| 53 |
|
| 54 |
# make install 'fail' with bad option |
| 55 |
renv_scope_options(install.opts = list(oatmeal = "--version")) |
| 56 |
expect_error(install("oatmeal")) |
| 57 |
}) |