| 1 |
|
| 2 |
test_that("renv.lock is added to .Rbuildignore", { |
| 3 |
|
| 4 |
skip_on_cran() |
| 5 |
renv_tests_scope() |
| 6 |
|
| 7 |
# use custom userdir |
| 8 |
userdir <- renv_scope_tempfile("renv-userdir-override") |
| 9 |
ensure_directory(userdir) |
| 10 |
userdir <- renv_path_normalize(userdir, mustWork = TRUE) |
| 11 |
renv_scope_options(renv.userdir.override = userdir) |
| 12 |
|
| 13 |
# sanity check |
| 14 |
userdir <- renv_bootstrap_user_dir() |
| 15 |
if (!identical(expect_true(renv_path_within(userdir, tempdir())), TRUE)) |
| 16 |
skip("userdir not in tempdir; cannot proceed") |
| 17 |
|
| 18 |
# initialize |
| 19 |
writeLines(c("Type: Package", "Package: test"), con = "DESCRIPTION") |
| 20 |
init() |
| 21 |
|
| 22 |
# check |
| 23 |
expect_true(file.exists(".Rbuildignore")) |
| 24 |
contents <- readLines(".Rbuildignore") |
| 25 |
expect_true("^renv\\.lock$" %in% contents) |
| 26 |
|
| 27 |
}) |
| 28 |
|
| 29 |
test_that("infrastructure can be removed", { |
| 30 |
|
| 31 |
renv_tests_scope("breakfast") |
| 32 |
|
| 33 |
before <- list.files(recursive = TRUE) |
| 34 |
init() |
| 35 |
deactivate() |
| 36 |
renv_infrastructure_remove() |
| 37 |
unlink("renv.lock") |
| 38 |
after <- list.files(recursive = TRUE) |
| 39 |
|
| 40 |
expect_setequal(before, after) |
| 41 |
|
| 42 |
}) |
| 43 |
|
| 44 |
test_that("library/ is excluded from .gitignore as appropriate", { |
| 45 |
|
| 46 |
skip_if_not(nzchar(Sys.which("git")), "git is not available") |
| 47 |
|
| 48 |
renv_tests_scope() |
| 49 |
system("git init", ignore.stdout = TRUE, ignore.stderr = TRUE) |
| 50 |
init(bare = TRUE) |
| 51 |
|
| 52 |
contents <- readLines("renv/.gitignore") |
| 53 |
expect_true("library/" %in% contents) |
| 54 |
|
| 55 |
settings$vcs.ignore.library(FALSE) |
| 56 |
|
| 57 |
contents <- readLines("renv/.gitignore") |
| 58 |
expect_true("# library/" %in% contents) |
| 59 |
expect_false("library/" %in% contents) |
| 60 |
|
| 61 |
settings$vcs.ignore.library(TRUE) |
| 62 |
|
| 63 |
contents <- readLines("renv/.gitignore") |
| 64 |
expect_true("library/" %in% contents) |
| 65 |
expect_false("# library/" %in% contents) |
| 66 |
|
| 67 |
settings$vcs.ignore.local(TRUE) |
| 68 |
|
| 69 |
contents <- readLines("renv/.gitignore") |
| 70 |
expect_true("local/" %in% contents) |
| 71 |
expect_false("# local/" %in% contents) |
| 72 |
|
| 73 |
settings$vcs.ignore.local(FALSE) |
| 74 |
|
| 75 |
contents <- readLines("renv/.gitignore") |
| 76 |
expect_false("local/" %in% contents) |
| 77 |
expect_true("# local/" %in% contents) |
| 78 |
|
| 79 |
}) |
| 80 |
|
| 81 |
test_that("whitespace in infrastructure file is preserved", { |
| 82 |
renv_tests_scope() |
| 83 |
before <- c("^renv$", "", "^renv\\.lock$", "", "c") |
| 84 |
writeLines(before, ".Rbuildignore") |
| 85 |
renv_infrastructure_write() |
| 86 |
after <- readLines(".Rbuildignore") |
| 87 |
expect_equal(before, after) |
| 88 |
}) |
| 89 |
|
| 90 |
test_that("lines are commented, uncommented as appropriate", { |
| 91 |
|
| 92 |
renv_tests_scope() |
| 93 |
|
| 94 |
text <- " # Some pre-existing text" |
| 95 |
writeLines(text, con = ".Rprofile") |
| 96 |
|
| 97 |
init(bare = TRUE) |
| 98 |
|
| 99 |
before <- readLines(".Rprofile") |
| 100 |
|
| 101 |
deactivate() |
| 102 |
|
| 103 |
after <- readLines(".Rprofile") |
| 104 |
|
| 105 |
expected <- c("# source(\"renv/activate.R\")", text) |
| 106 |
expect_identical(after, expected) |
| 107 |
|
| 108 |
}) |
| 109 |
|
| 110 |
test_that("comments after a required line are preserved", { |
| 111 |
renv_tests_scope() |
| 112 |
|
| 113 |
before <- c("# a comment", "source(\"renv/activate.R\")") |
| 114 |
after <- c("# a comment", "# source(\"renv/activate.R\")") |
| 115 |
|
| 116 |
writeLines(before, con = ".Rprofile") |
| 117 |
renv_infrastructure_remove() |
| 118 |
|
| 119 |
expect_identical(readLines(con = ".Rprofile"), after) |
| 120 |
|
| 121 |
renv_infrastructure_write() |
| 122 |
expect_identical(readLines(con = ".Rprofile"), before) |
| 123 |
|
| 124 |
}) |
| 125 |
|
| 126 |
test_that("the project .Rprofile is removed if only autoloader exists", { |
| 127 |
|
| 128 |
renv_tests_scope() |
| 129 |
writeLines("source(\"renv/activate.R\")", con = ".Rprofile") |
| 130 |
renv_infrastructure_remove() |
| 131 |
expect_false(file.exists(".Rprofile")) |
| 132 |
|
| 133 |
}) |
| 134 |
|
| 135 |
test_that("the renv .gitignore is updated for sub-projects", { |
| 136 |
|
| 137 |
renv_tests_scope() |
| 138 |
dir.create(".git") |
| 139 |
project <- file.path(getwd(), "project") |
| 140 |
dir.create(project) |
| 141 |
renv_infrastructure_write(project = project) |
| 142 |
expect_true(file.exists("project/renv/.gitignore")) |
| 143 |
|
| 144 |
}) |