Skip to content

Commit 325995d

Browse files
authored
Correctly test inputs in expect_setequal() (#2244)
1 parent 0ff28c7 commit 325995d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

R/expect-setequal.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ expect_setequal <- function(object, expected) {
2828
act <- quasi_label(enquo(object))
2929
exp <- quasi_label(enquo(expected))
3030

31-
check_vector(object)
32-
check_vector(expected)
31+
check_vector(act$val, error_arg = "object")
32+
check_vector(exp$val, error_arg = "expected")
3333
if (!is.null(names(act$val)) && !is.null(names(exp$val))) {
3434
testthat_warn("expect_setequal() ignores names")
3535
}

tests/testthat/_snaps/expect-setequal.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
Condition
1919
Error in `expect_setequal()`:
2020
! `expected` must be a vector, not a primitive function.
21+
Code
22+
expect_setequal(!!fun, 1)
23+
Condition
24+
Error in `expect_setequal()`:
25+
! `object` must be a vector, not a primitive function.
26+
Code
27+
expect_setequal(1, !!fun)
28+
Condition
29+
Error in `expect_setequal()`:
30+
! `expected` must be a vector, not a primitive function.
2131

2232
# useful message on failure
2333

tests/testthat/test-expect-setequal.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ test_that("warns if both inputs are named", {
2626
})
2727

2828
test_that("checks inputs", {
29+
fun <- sum
2930
expect_snapshot(error = TRUE, {
3031
expect_setequal(sum, 1)
3132
expect_setequal(1, sum)
33+
expect_setequal(!!fun, 1)
34+
expect_setequal(1, !!fun)
3235
})
3336
})
3437

0 commit comments

Comments
 (0)