Skip to content

Commit

Permalink
Test out_of_date() and fix bugs thus revealed
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 24, 2024
1 parent 69f7e6b commit 1de84cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pkgdown (development version)

* New light switch makes it easy for users to switch between light and dark themes for the website (based on work in bslib by @gadenbuie). For now this behaviour is opt-in with `template.light-switch: true` but in the future we may turn it on automatically. See the customization vignette for details (#1696).
* The search dropdown has been tweaked to look more like the other navbar menu items (#2338).
* The search drop-down has been tweaked to look more like the other navbar menu items (#2338).
* `vignette("search")` has been removed since BS3 is deprecated and all the BS5 docs are also included in `build_search()` (#2564).
* YAML validation has been substantially improved so you should get much clearer errors if you have made a mistake (#1927). Please file an issue if you find a case where the error message is not helpful.
* `template_reference()` and `template_article()` now only add backticks to function names if needed (#2561).
Expand Down
13 changes: 5 additions & 8 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ create_subdir <- function(pkg, subdir) {

}

out_of_date <- function(source, target) {
if (!file_exists(target))
out_of_date <- function(source, target, call = caller_env()) {
if (!file_exists(target)) {
return(TRUE)

}
if (!file_exists(source)) {
cli::cli_abort(
"{.fn {source}} does not exist",
call = caller_env()
)
cli::cli_abort("{.path {source}} does not exist", call = call)
}

file_info(source)$mtime > file_info(target)$mtime
file_info(source)$modification_time > file_info(target)$modification_time
}

# Path helpers ------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/utils-fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
! Template package "missing" is not installed.
i Please install before continuing.

# out_of_date works as expected

Code
out_of_date("doesntexist", temp1)
Condition
Error:
! 'doesntexist' does not exist

14 changes: 14 additions & 0 deletions tests/testthat/test-utils-fs.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
test_that("missing template package yields custom error", {
expect_snapshot(path_package_pkgdown("x", "missing", 3), error = TRUE)
})


test_that("out_of_date works as expected", {
temp1 <- file_create(withr::local_tempfile())
expect_true(out_of_date(temp1, "doesntexist"))
expect_snapshot(out_of_date("doesntexist", temp1), error = TRUE)

temp2 <- file_create(withr::local_tempfile())
file_touch(temp2, Sys.time() + 10)

expect_true(out_of_date(temp2, temp1))
expect_false(out_of_date(temp1, temp2))
expect_false(out_of_date(temp1, temp1))
})

0 comments on commit 1de84cb

Please sign in to comment.