Skip to content

Commit c66877a

Browse files
test: cover the survivor lines of the dead-code removal (#98)
Address self-review nits on PR #99: - nit 1: drop the inert `file.create(fake_tar)` + `on.exit` setup. With `update_tar_gz = FALSE`, the `if (update_tar_gz)` block is skipped and `list.files` never reads the fake file - the setup did nothing. - nit 2: add a second test for the `build_from_source = FALSE, update_tar_gz = TRUE` path. Mocks `pkgbuild::build` (returns a fake tar.gz path) and `usethis::use_build_ignore` (no-op), then asserts both bindings were actually called - the survivor lines of the dead-code removal (`use_build_ignore(files = out)` and the `cat_green_tick(...)` success message) are now exercised. This brings the previously-claimed-but-untested 0% region to covered.
1 parent 85c0509 commit c66877a

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

tests/testthat/test-dock_from_desc.R

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,8 @@ withr::with_dir(
157157
)
158158
})
159159

160-
test_that("dock_from_desc(build_from_source = FALSE) copies a prebuilt tar.gz", {
160+
test_that("dock_from_desc(build_from_source = FALSE, update_tar_gz = FALSE) copies a prebuilt tar.gz", {
161161
skip_if(is_rdevel, "skip on R-devel")
162-
fake_tar <- "fakepkg_0.0.0.tar.gz"
163-
file.create(fake_tar)
164-
on.exit(unlink(fake_tar), add = TRUE)
165162
my_dock <- testthat::with_mocked_bindings(
166163
code = dock_from_desc(
167164
file.path(".", "DESCRIPTION__"),
@@ -176,6 +173,36 @@ withr::with_dir(
176173
expect_match(df, "rm /app.tar.gz", fixed = TRUE)
177174
expect_false(grepl("mkdir /build_zone", df, fixed = TRUE))
178175
})
176+
177+
test_that("dock_from_desc(build_from_source = FALSE, update_tar_gz = TRUE) builds a fresh tar.gz", {
178+
skip_if(is_rdevel, "skip on R-devel")
179+
build_called <- FALSE
180+
use_build_ignore_called <- FALSE
181+
my_dock <- testthat::with_mocked_bindings(
182+
code = dock_from_desc(
183+
file.path(".", "DESCRIPTION__"),
184+
build_from_source = FALSE,
185+
update_tar_gz = TRUE
186+
),
187+
get_sysreqs = function(...) character(0),
188+
build = function(path, dest_path, vignettes) {
189+
build_called <<- TRUE
190+
fake <- file.path(dest_path, "fakepkg_0.0.0.tar.gz")
191+
file.create(fake)
192+
fake
193+
},
194+
use_build_ignore = function(files) {
195+
use_build_ignore_called <<- TRUE
196+
invisible(TRUE)
197+
}
198+
)
199+
# Both surviving lines from the dead-code-removal must execute on
200+
# this code path.
201+
expect_true(build_called)
202+
expect_true(use_build_ignore_called)
203+
df <- paste(my_dock$Dockerfile, collapse = "\n")
204+
expect_match(df, "remotes::install_local", fixed = TRUE)
205+
})
179206
}
180207
)
181208

0 commit comments

Comments
 (0)