Skip to content

Commit

Permalink
Fix coverage hole
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Sep 29, 2023
1 parent 232b9fe commit c9a85bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 3 additions & 5 deletions R/util_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ assert_file_exists_relative <- function(files, workdir, name, call = NULL) {
files_canonical <- file_canonical_case(files, workdir)
err <- is.na(files_canonical) | fs::path(files) != files_canonical
if (any(err)) {
n <- cli::qty(sum(err))
if (any(is.na(files_canonical))) {
browser()
}
i <- err & !is.na(files_canonical)
hint_case <- sprintf("For '%s', did you mean '%s'?",
files[err], files_canonical[err])
files[i], files_canonical[i])
n <- cli::qty(sum(err))
cli::cli_abort(
c("{name}{n}{?s} {?does/do} not exist: {collapseq(files[err])}",
set_names(hint_case, "i"),
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-util-assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ test_that("assert_file_exists_relative informs about case mismatch", {
expect_equal(err$body[[2]], "For 'b/C/d', did you mean 'b/c/d'?")
expect_match(err$body[[3]], "If you don't use the canonical case for a file")
expect_match(err$body[[4]], "Looked within directory '.+'")

err <- expect_error(
assert_file_exists_relative(c("A", "b/X/d"), tmp, "File"),
"Files do not exist: 'A', 'b/X/d'")
expect_length(err$body, 3)
expect_equal(names(err$body), c("i", "i", "i"))
expect_equal(err$body[[1]], "For 'A', did you mean 'a'?")
expect_match(err$body[[3]], "If you don't use the canonical case for a file")
expect_match(err$body[[4]], "Looked within directory '.+'")
})


Expand Down

0 comments on commit c9a85bb

Please sign in to comment.