From 7f168bc4afc7326da35d31b13e34c2c568561bac Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Sun, 4 Feb 2024 16:01:45 +0100 Subject: [PATCH] Add tests --- R/xlsx_cutter.R | 5 +++-- tests/testthat/_snaps/xlsx_cutter.md | 6 ++++++ tests/testthat/test-xlsx_cutter.R | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/R/xlsx_cutter.R b/R/xlsx_cutter.R index 86a8735..9c8d6e8 100644 --- a/R/xlsx_cutter.R +++ b/R/xlsx_cutter.R @@ -82,8 +82,9 @@ xlsx_cutter <- function( if (any(failed)) { warning( - "parsing failed for ", sum(failed), " files:\n", - toString(data_files[failed]) + "parsing failed for ", sum(failed), " files:\n - ", + paste(data_files[failed], collapse = "\n - "), + call. = FALSE ) } diff --git a/tests/testthat/_snaps/xlsx_cutter.md b/tests/testthat/_snaps/xlsx_cutter.md index a302d27..7c5aac1 100644 --- a/tests/testthat/_snaps/xlsx_cutter.md +++ b/tests/testthat/_snaps/xlsx_cutter.md @@ -63,3 +63,9 @@ ] } +# failures don't stop loop + + parsing failed for 2 files: + - nonexistent_file.xlsx + - nonexistent_file2.xlsx + diff --git a/tests/testthat/test-xlsx_cutter.R b/tests/testthat/test-xlsx_cutter.R index c4958b2..92bf330 100644 --- a/tests/testthat/test-xlsx_cutter.R +++ b/tests/testthat/test-xlsx_cutter.R @@ -19,3 +19,16 @@ test_that("xlsx_cutter() works", { ) }) + +test_that("failures don't stop loop", { + + expect_snapshot_warning( + res <- xlsx_cutter( # nolintr: assignment_linter. + c("nonexistent_file.xlsx", "nonexistent_file2.xlsx", data_files), + template_file + ) + ) + + expect_identical(nrow(res), length(data_files)) + +})