% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/testit.R
\name{has_message}
\alias{has_message}
\alias{has_warning}
\alias{has_error}
\title{Test whether an expression signals a condition}
\usage{
has_message(expr, message = NULL, ...)

has_warning(expr, message = NULL, ...)

has_error(expr, message = NULL, ...)
}
\arguments{
\item{expr}{An R expression to evaluate.}

\item{message}{An optional string to match against the condition text. Uses
fixed (literal) matching by default. If provided, the function returns
\code{TRUE} only when the condition is signaled \emph{and} the message matches.}

\item{...}{Additional arguments passed to \code{\link[=grepl]{grepl()}} for matching (e.g.,
\code{fixed = FALSE} to use regex, or \code{ignore.case = TRUE}). Note that
\code{fixed = TRUE} is the default.}
}
\value{
\code{TRUE} if the condition was signaled (and the message matched, if
provided), \code{FALSE} otherwise.
}
\description{
Check if evaluating an expression produces a message, warning, or error.
These functions are designed to be used inside \code{\link[=assert]{assert()}} to verify that code
signals the expected conditions. Optionally, you can match against the
condition's text to ensure the \emph{right} message/warning/error was signaled.
}
\examples{
has_message(message('hello'))
has_message(1 + 1)
has_message(message('hello world'), 'hello')

has_warning(1 + 1)
has_warning(1:2 + 1:3)
has_warning(1:2 + 1:3, 'longer object length')

has_error(2 - 3)
has_error(1 + 'a')
has_error(stop('err'), 'err')
has_error(stop('error occurred'), 'error')
}
