r-lib / testthat

An R 📦 to make testing 😀
https://testthat.r-lib.org
Other
868 stars 313 forks source link

expect_error and friends report unused arguments for `fixed` when used interactively but not when used non-interactively #1932

Open billdenney opened 4 months ago

billdenney commented 4 months ago

When I ran the code below interactively, I got the following warning:

Error: 1 did not throw the expected warning.
Warning in expect_warning(1, regexp = "foo", fixed = TRUE) :
  Arguments in `...` must be used.
✖ Problematic argument:
• fixed = TRUE
ℹ Did you misspell an argument name?

But when run in reprex, I don't see the warning about fixed. Why is there different behavior for interactive vs non-interactive use for argument matching?

library(testthat)

expect_message(
  message("foo"),
  regexp = "foo",
  fixed = TRUE
)

expect_message(
  1,
  regexp = "foo",
  fixed = TRUE
)
#> Error: 1 did not produce any messages.

expect_warning(
  warning("foo"),
  regexp = "foo",
  fixed = TRUE
)

expect_warning(
  1,
  regexp = "foo",
  fixed = TRUE
)
#> Error: 1 did not produce any warnings.

expect_error(
  stop("foo"),
  regexp = "foo",
  fixed = TRUE
)

expect_error(
  1,
  regexp = "foo",
  fixed = TRUE
)
#> Error: 1 did not throw an error.

Created on 2024-02-15 with reprex v2.1.0

hadley commented 2 months ago

Somewhat more minimal reprex, but must be run interactively:

testthat::expect_message(1, "x", fixed = TRUE)

This is going to be a fun one to debug!