shows_message(regexp = NULL, all = FALSE, ...)expect_message(object, regexp = NULL, ..., info = NULL, label = NULL)
TRUE
, all messages must match given
regular expression; if FALSE
(the default), then
only only message needs to matchmatches
NULL
, computed
from deparsed object.equals
,
expect_equal
; expect-compare
,
expect_less_than
,
expect_more_than
,
is_less_than
, is_more_than
;
expect_equivalent
,
is_equivalent_to
;
expect_error
, throws_error
;
expect_false
, is_false
;
expect_identical
,
is_identical_to
; expect_is
,
is_a
; expect_match
,
matches
; expect_named
,
has_names
; expect_null
,
is_null
; expect_output
,
prints_text
; expect_true
,
is_true
; expect_warning
,
gives_warning
;
takes_less_than
f <- function(x) {
if (x < 0) message("*x* is already negative")
-x
}
expect_that(f(-1), shows_message())
expect_that(f(-1), shows_message("already negative"))
expect_that(f(1), shows_message())
expect_message(f(-1))
expect_message(f(-1), "already negative")
expect_message(f(1))
# You can use the arguments of grepl to control the matching
expect_message(f(-1), "*x*", fixed = TRUE)
expect_message(f(-1), "NEGATIVE", ignore.case = TRUE)
Run the code above in your browser using DataLab