From c9a85bb4f92db858b751cfabc629372e381aa35f Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Fri, 29 Sep 2023 16:08:11 +0100 Subject: [PATCH] Fix coverage hole --- R/util_assert.R | 8 +++----- tests/testthat/test-util-assert.R | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/R/util_assert.R b/R/util_assert.R index d67c3171..f8091943 100644 --- a/R/util_assert.R +++ b/R/util_assert.R @@ -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"), diff --git a/tests/testthat/test-util-assert.R b/tests/testthat/test-util-assert.R index 98dfd017..12a3c9a7 100644 --- a/tests/testthat/test-util-assert.R +++ b/tests/testthat/test-util-assert.R @@ -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 '.+'") })