In the following example, the actual vector is missing two elements: OH1 and PA-PPL2. Is there a way to get more useful output than what expect_equal() gives here? I'd like to know which items are missing from actual, not just that the counts are different.
library(testthat)
test_that(
'files are named correctly',
{
expected <- c(AMEREN1 = "AMEREN24.01.15_March-1_DM_RL.pdf", COMED1 = "COMED24.01.15_March-1_DM_RL.pdf",
`MD-OTH1` = "MD-OTH24.01.15_March_DM_RL.pdf", MD1 = "MD24.01.15_March_DM_RL.pdf",
NJ1 = "NJ24.01.15_March_DM_RL.pdf", OH1 = "OH24.01.15_March_DM_RL.pdf",
PA1 = "PA24.01.15_March_DM_RL.pdf", AMEREN2 = "AMEREN24.01.15_March-2_DM_RL.pdf",
COMED2 = "COMED24.01.15_March-2_DM_RL.pdf", `PA-DUQ2` = "PA24.01.15_March-DUQ_DM_RL.pdf",
`PA-METED2` = "PA24.01.15_March-METED_DM_RL.pdf", `PA-PECO2` = "PA24.01.15_March-PECO_DM_RL.pdf",
`PA-PENELEC2` = "PA24.01.15_March-PENELEC_DM_RL.pdf", `PA-PENN2` = "PA24.01.15_March-PENN_DM_RL.pdf",
`PA-PPL2` = "PA24.01.15_March-PPL_DM_RL.pdf", `PA-WPP2` = "PA24.01.15_March-WPP_DM_RL.pdf"
)
actual <- c(AMEREN1 = "AMEREN24.01.15_March-1_DM_RL.pdf", COMED1 = "COMED24.01.15_March-1_DM_RL.pdf",
`MD-OTH1` = "MD-OTH24.01.15_March_DM_RL.pdf", MD1 = "MD24.01.15_March_DM_RL.pdf",
NJ1 = "NJ24.01.15_March_DM_RL.pdf", PA1 = "PA24.01.15_March_DM_RL.pdf",
AMEREN2 = "AMEREN24.01.15_March-2_DM_RL.pdf", COMED2 = "COMED24.01.15_March-2_DM_RL.pdf",
`PA-DUQ2` = "PA24.01.15_March-DUQ_DM_RL.pdf", `PA-METED2` = "PA24.01.15_March-METED_DM_RL.pdf",
`PA-PECO2` = "PA24.01.15_March-PECO_DM_RL.pdf", `PA-PENELEC2` = "PA24.01.15_March-PENELEC_DM_RL.pdf",
`PA-PENN2` = "PA24.01.15_March-PENN_DM_RL.pdf", `PA-WPP2` = "PA24.01.15_March-WPP_DM_RL.pdf"
)
expect_equal(
actual,
expected
)
}
)
#> -- Failure ('<text>:24'): files are named correctly ----------------------------
#> `actual` not equal to `expected`.
#> Lengths differ: 14 is not 16
#> Error in `reporter$stop_if_needed()`:
#> ! Test failed
#> Backtrace:
#> x
#> 1. \-testthat::test_that(...)
#> 2. \-withr (local) `<fn>`(`<env>`)
#> 3. +-base::tryCatch(...)
#> 4. | \-base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 5. | \-base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 6. | \-base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 7. \-base::eval(handler$expr, handler$envir)
#> 8. \-base::eval(handler$expr, handler$envir)
#> 9. \-reporter$stop_if_needed()
#> 10. \-rlang::abort("Test failed")
Created on 2023-12-26 with reprex v2.0.2
In
{testthat}3rd edition, theexpect_equal()comparison is done withwaldo::compare(), which will give more details. You are probably using{testthat}2nd edition, whereexpect_equal()usesall.equal().You can temporarily switch to the 3rd edition for this test with:
or activate it globally as described here.
With a the reprex:
Created on 2023-12-26 with reprex v2.0.2