Skip to content

Commit 5af66e5

Browse files
committed
More tweaking
1 parent cdc7f3a commit 5af66e5

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

R/expect-condition.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,19 +586,18 @@ check_condition_dots <- function(
586586
return()
587587
}
588588

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-
)
589+
dot_names <- ...names()
590+
if (is.null(dot_names)) {
591+
dot_names <- rep("", ...length())
596592
}
593+
unnamed <- dot_names == ""
594+
dot_names[unnamed] <- paste0("..", seq_along(dot_names)[unnamed])
595+
597596
cli::cli_abort(
598597
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]]
598+
"Can't supply {.arg ...} unless {.arg regexp} is set.",
599+
"*" = "Unusued arguments: {.arg {dot_names}}.",
600+
i = "{.arg ...} is passed to {.fn grepl} if and only if the {.arg regexp} argument is used."
602601
),
603602
call = error_call
604603
)

tests/testthat/_snaps/expect-condition.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,23 @@
3535
expect_condition(stop("Hi!"), foo = "bar")
3636
Condition
3737
Error in `expect_condition()`:
38-
! Found arguments in `...` to be passed to `grepl()`, but no `regexp`.
39-
* First problematic argument:
40-
i foo
38+
! Can't supply `...` unless `regexp` is set.
39+
* Unusued arguments: `foo`.
40+
i `...` is passed to `grepl()` if and only if the `regexp` argument is used.
41+
Code
42+
expect_condition(stop("Hi!"), , , "bar")
43+
Condition
44+
Error in `expect_condition()`:
45+
! Can't supply `...` unless `regexp` is set.
46+
* Unusued arguments: `..1`.
47+
i `...` is passed to `grepl()` if and only if the `regexp` argument is used.
48+
Code
49+
expect_condition(stop("Hi!"), , , "bar", foo = "bar")
50+
Condition
51+
Error in `expect_condition()`:
52+
! Can't supply `...` unless `regexp` is set.
53+
* Unusued arguments: `..1` and `foo`.
54+
i `...` is passed to `grepl()` if and only if the `regexp` argument is used.
4155
Code
4256
expect_condition(stop("Hi!"), "x", foo = "bar")
4357
Condition

tests/testthat/test-expect-condition.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ test_that("can match parent conditions (#1493)", {
243243
test_that("unused arguments generate an error", {
244244
expect_snapshot(error = TRUE, {
245245
expect_condition(stop("Hi!"), foo = "bar")
246+
expect_condition(stop("Hi!"), , , "bar")
247+
expect_condition(stop("Hi!"), , , "bar", foo = "bar")
246248
expect_condition(stop("Hi!"), "x", foo = "bar")
247249
})
248250
})

0 commit comments

Comments
 (0)