| 1 |
|
| 2 |
test_that("reports if status not possible", { |
| 3 |
|
| 4 |
renv_tests_scope() |
| 5 |
expect_snapshot(. <- status()) |
| 6 |
|
| 7 |
init(bare = TRUE) |
| 8 |
expect_snapshot(. <- status()) |
| 9 |
|
| 10 |
snapshot() |
| 11 |
unlink("renv/library", recursive = TRUE) |
| 12 |
expect_snapshot(. <- status()) |
| 13 |
|
| 14 |
}) |
| 15 |
|
| 16 |
test_that("reports when project is synchronised", { |
| 17 |
|
| 18 |
renv_tests_scope() |
| 19 |
init() |
| 20 |
|
| 21 |
expect_snapshot(. <- status()) |
| 22 |
|
| 23 |
}) |
| 24 |
|
| 25 |
test_that("reports installation problems with non-installed packages", { |
| 26 |
|
| 27 |
renv_tests_scope() |
| 28 |
init() |
| 29 |
|
| 30 |
writeLines(c("library(egg)", "library(bread)"), con = "script.R") |
| 31 |
record("egg") |
| 32 |
record("oatmeal") |
| 33 |
|
| 34 |
expect_snapshot(. <- status()) |
| 35 |
|
| 36 |
}) |
| 37 |
|
| 38 |
test_that("reports synchronisation problems with installed packages", { |
| 39 |
|
| 40 |
renv_tests_scope() |
| 41 |
init() |
| 42 |
install(c("egg", "bread")) |
| 43 |
|
| 44 |
writeLines("library(bread)", con = "script.R") |
| 45 |
record("egg") |
| 46 |
|
| 47 |
expect_snapshot(. <- status()) |
| 48 |
|
| 49 |
}) |
| 50 |
|
| 51 |
test_that("reports version differences", { |
| 52 |
|
| 53 |
renv_tests_scope(c("egg", "oatmeal")) |
| 54 |
init() |
| 55 |
record("[email protected]") |
| 56 |
record("[email protected]") |
| 57 |
|
| 58 |
expect_snapshot(. <- status()) |
| 59 |
|
| 60 |
}) |
| 61 |
|
| 62 |
test_that("status() notifies user if R version does not match", { |
| 63 |
|
| 64 |
project <- renv_tests_scope() |
| 65 |
init() |
| 66 |
|
| 67 |
# simulate a different version of R in lockfile |
| 68 |
local({ |
| 69 |
renv_scope_options(renv.verbose = FALSE) |
| 70 |
lockfile <- renv_lockfile_read(file = "renv.lock") |
| 71 |
lockfile$R$Version <- "1.0.0" |
| 72 |
renv_lockfile_write(lockfile, file = "renv.lock") |
| 73 |
}) |
| 74 |
|
| 75 |
expect_snapshot(. <- status()) |
| 76 |
|
| 77 |
}) |
| 78 |
|
| 79 |
test_that("status() notifies user if packages are missing and inconsistent", { |
| 80 |
|
| 81 |
project <- renv_tests_scope("bread") |
| 82 |
init() |
| 83 |
|
| 84 |
writeLines("library(breakfast)", con = "_deps.R") |
| 85 |
install("[email protected]") |
| 86 |
|
| 87 |
expect_snapshot(. <- status()) |
| 88 |
|
| 89 |
}) |
| 90 |
|
| 91 |
test_that("status() version check can be disabled", { |
| 92 |
|
| 93 |
project <- renv_tests_scope("bread") |
| 94 |
init() |
| 95 |
|
| 96 |
# write an incompatible R version into the lockfile |
| 97 |
lockfile <- renv_lockfile_read(file = "renv.lock") |
| 98 |
lockfile$R$Version <- "1.0.0" |
| 99 |
renv_lockfile_write(lockfile, file = "renv.lock") |
| 100 |
|
| 101 |
renv_scope_options(renv.status.check_version = TRUE) |
| 102 |
expect_snapshot(. <- renv::status()) |
| 103 |
|
| 104 |
renv_scope_options(renv.status.check_version = FALSE) |
| 105 |
expect_snapshot(. <- renv::status()) |
| 106 |
|
| 107 |
}) |
| 108 |
|
| 109 |
test_that("status() uses settings$snapshot.dev() as default for dev parameter", { |
| 110 |
|
| 111 |
renv_tests_scope() |
| 112 |
init() |
| 113 |
|
| 114 |
# Create a project that would have dev dependencies |
| 115 |
writeLines("PackageUseDevtools: Yes", con = "project.Rproj") |
| 116 |
|
| 117 |
project <- getwd() |
| 118 |
|
| 119 |
# Verify default setting is FALSE |
| 120 |
expect_false(settings$snapshot.dev()) |
| 121 |
|
| 122 |
# Test that the setting can be set and retrieved |
| 123 |
settings$snapshot.dev(TRUE) |
| 124 |
expect_true(settings$snapshot.dev()) |
| 125 |
|
| 126 |
settings$snapshot.dev(FALSE) |
| 127 |
expect_false(settings$snapshot.dev()) |
| 128 |
|
| 129 |
# Test that dependencies discovered with dev=FALSE don't include devtools |
| 130 |
deps1 <- renv_snapshot_dependencies(project, dev = FALSE) |
| 131 |
expect_false("devtools" %in% deps1) |
| 132 |
|
| 133 |
# Test that dependencies discovered with dev=TRUE do include devtools |
| 134 |
deps2 <- renv_snapshot_dependencies(project, dev = TRUE) |
| 135 |
expect_true("devtools" %in% deps2) |
| 136 |
|
| 137 |
}) |