Skip to content

Commit ac6f2c9

Browse files
committed
Add test for where_sep_sheet=TRUE but WhereClause sheet missing
1 parent 323e26d commit ac6f2c9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/testthat/test-reader.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,36 @@ test_that("define_to_metacore(quiet) deprecation message is output when supplied
612612
spec <- define_to_metacore(metacore_example("ADaM_define_CDISC_pilot3.xml"), quiet = TRUE)
613613
)
614614
})
615+
616+
test_that("Informative error when where_sep_sheet=TRUE but WhereClause sheet missing", {
617+
# This should trigger the helpful error message about where_sep_sheet
618+
expect_error(
619+
spec_to_metacore(
620+
"spec_no_val.xlsx", # Use relative path like the existing test
621+
where_sep_sheet = TRUE, # This is the default, but being explicit
622+
verbose = "silent"
623+
),
624+
regexp = "where.*where_sep_sheet",
625+
ignore.case = TRUE
626+
)
627+
628+
# Verify the error message contains helpful context
629+
err <- tryCatch(
630+
spec_to_metacore(
631+
"spec_no_val.xlsx",
632+
where_sep_sheet = TRUE,
633+
verbose = "silent"
634+
),
635+
error = function(e) conditionMessage(e)
636+
)
637+
638+
# Check that the error message mentions:
639+
# 1. That columns couldn't be matched
640+
expect_match(err, "Unable to identify a sheet|Could not find matching columns", ignore.case = TRUE)
641+
642+
# 2. Provides the helpful tip about where_sep_sheet
643+
expect_match(err, "where_sep_sheet", ignore.case = TRUE)
644+
645+
# 3. Shows which sheet was closest
646+
expect_match(err, "Sheet|Closest", ignore.case = TRUE)
647+
})

0 commit comments

Comments
 (0)