@@ -280,6 +280,7 @@ expect_condition_matching <- function(
280280 trace_env = caller_env(),
281281 error_call = caller_env()
282282) {
283+ check_condition_dots(regexp , ... , error_call = error_call )
283284 matcher <- cnd_matcher(
284285 base_class ,
285286 class ,
@@ -329,25 +330,6 @@ cnd_matcher <- function(
329330 check_string(class , allow_null = TRUE , call = error_call )
330331 check_string(regexp , allow_null = TRUE , allow_na = TRUE , call = error_call )
331332
332- if (is.null(regexp ) && dots_n(... ) > 0 ) {
333- # pretty adversarial: expect_error(foo(), NULL, "error", 1)
334- dots_names <- ... names()
335- if (is.null(dots_names )) {
336- cli :: cli_abort(
337- " Found unnamed arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}." ,
338- call = error_call
339- )
340- }
341- cli :: cli_abort(
342- c(
343- " Found arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}." ,
344- " *" = " First problematic argument:" ,
345- " i" = dots_names [which(nzchar(dots_names ))[1L ]]
346- ),
347- call = error_call
348- )
349- }
350-
351333 function (cnd ) {
352334 if (! inherit ) {
353335 cnd $ parent <- NULL
@@ -594,3 +576,30 @@ cnd_message <- function(x) {
594576 withr :: local_options(rlang_backtrace_on_error = " none" )
595577 conditionMessage(x )
596578}
579+
580+ check_condition_dots <- function (
581+ regexp = NULL ,
582+ ... ,
583+ error_call = caller_env()
584+ ) {
585+ if (! is.null(regexp ) || missing(... )) {
586+ return ()
587+ }
588+
589+ # pretty adversarial: expect_error(foo(), NULL, "error", 1)
590+ dots_names <- ... names()
591+ if (is.null(dots_names )) {
592+ cli :: cli_abort(
593+ " Found unnamed arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}." ,
594+ call = error_call
595+ )
596+ }
597+ cli :: cli_abort(
598+ c(
599+ " Found arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}." ,
600+ " *" = " First problematic argument:" ,
601+ " i" = dots_names [which(nzchar(dots_names ))[1L ]]
602+ ),
603+ call = error_call
604+ )
605+ }
0 commit comments