Skip to content

Commit e8fb98f

Browse files
committed
Check expect() inputs
Fixes #2247
1 parent b3aaec1 commit e8fb98f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

R/expectation.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ expect <- function(
2020
trace = NULL,
2121
trace_env = caller_env()
2222
) {
23+
check_bool(ok)
24+
check_character(failure_message)
25+
2326
if (!ok) {
2427
return(fail(
2528
failure_message,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# validates key inputs
2+
3+
Code
4+
expect(1)
5+
Condition
6+
Error in `expect()`:
7+
! `ok` must be `TRUE` or `FALSE`, not the number 1.
8+
Code
9+
expect(TRUE, 1)
10+
Condition
11+
Error in `expect()`:
12+
! `failure_message` must be a character vector, not the number 1.
13+

tests/testthat/test-expectation.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ test_that("info only evaluated on failure", {
77
expect_no_error(expect(TRUE, "fail", info = stop("!")))
88
})
99

10+
test_that("validates key inputs", {
11+
expect_snapshot(error = TRUE, {
12+
expect(1)
13+
expect(TRUE, 1)
14+
})
15+
})
16+
1017
test_that("can subclass expectation", {
1118
exp <- new_expectation(
1219
"failure",

0 commit comments

Comments
 (0)