1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expectations.R
\name{expect_equal}
\alias{expect_equal}
\alias{expect_identical}
\alias{expect_equivalent}
\alias{expect_true}
\alias{expect_false}
\alias{expect_silent}
\alias{expect_null}
\alias{expect_inherits}
\alias{expect_error}
\alias{expect_warning}
\alias{expect_message}
\alias{expect_stdout}
\title{Express expectations}
\usage{
expect_equal(
current,
target,
tolerance = sqrt(.Machine$double.eps),
info = NA_character_,
...
)
expect_identical(current, target, info = NA_character_)
expect_equivalent(
current,
target,
tolerance = sqrt(.Machine$double.eps),
info = NA_character_,
...
)
expect_true(current, info = NA_character_)
expect_false(current, info = NA_character_)
expect_silent(current, quiet = TRUE, info = NA_character_)
expect_null(current, info = NA_character_)
expect_inherits(current, class, info = NA_character_)
expect_error(
current,
pattern = ".*",
class = "error",
info = NA_character_,
...
)
expect_warning(
current,
pattern = ".*",
class = "warning",
info = NA_character_,
strict = FALSE,
...
)
expect_message(
current,
pattern = ".*",
class = "message",
info = NA_character_,
strict = FALSE,
...
)
expect_stdout(current, pattern = ".*", info = NA_character_, ...)
}
\arguments{
\item{current}{\code{[R object or expression]} Outcome or expression under scrutiny.}
\item{target}{\code{[R object or expression]} Expected outcome}
\item{tolerance}{\code{[numeric]} Test equality to machine rounding. Passed
to \code{\link[base]{all.equal} (tolerance)}}
\item{info}{\code{[character]} scalar. Optional user-defined message. Must
be a single character string. Multiline comments may be separated by
\code{"\\n"}.}
\item{...}{passed on to \code{\link{grepl}} (useful for e.g. \code{fixed=TRUE}).}
\item{quiet}{\code{[logical]} suppress output printed by the \code{current}
expression (see examples)}
\item{class}{\code{[character]} For condition signals (error, warning, message)
the class from which the condition should inherit.}
\item{pattern}{\code{[character]} A regular expression to match the message.}
\item{strict}{\code{[logical]} scalar. If set to \code{TRUE}, any exception
worse than the wanted exception will cause the test to fail.}
}
\value{
A \code{\link{tinytest}} object. A tinytest object is a
\code{logical} with attributes holding information about the
test that was run
}
\description{
Express expectations
}
\details{
\code{expect_equivalent} calls \code{expect_equal} with the extra
arguments \code{check.attributes=FALSE} and \code{use.names=FALSE}
\code{expect_silent} fails when an error or warning is thrown.
\code{expect_inherits} fails when \code{\link{inherits}(current,class)} returns \code{FALSE}
\code{expect_stdout} Expects that output is written to \code{stdout},
for example using \code{cat} or \code{print}. Use \code{pattern} to
specify a regular expression matching the output.
}
\note{
Each \code{expect_haha} function can also be called as \code{checkHaha}.
Although the interface is not entirely the same, it is expected that
this makes migration from the \code{RUnit} framework a little easier, for those
who wish to do so.
\code{expect_error}, \code{expect_warning} and \code{expect_message} will
concatenate all messages when multiple exceptions are thrown, before
matching the message to \code{pattern}.
When speccifying regular expression patterns for errors, warnings or messages,
note that \code{\link[base]{message}} adds a LF character by default at the end
of the message string.
}
\section{More information and examples}{
\itemize{
\item{An overview of tinytest can be found in \code{vignette("using_tinytest")}}.
\item{Examples of how tinytest is used in practice can be found in
\code{vignette("tinytest_examples")}}
}
}
\examples{
expect_equal(1 + 1, 2) # TRUE
expect_equal(1 - 1, 2) # FALSE
expect_equivalent(2, c(x=2)) # TRUE
expect_equal(2, c(x=2)) # FALSE
expect_silent(1+1) # TRUE
expect_silent(1+"a") # FALSE
expect_silent(print("hihi")) # TRUE, nothing goes to screen
expect_silent(print("hihi"), quiet=FALSE) # TRUE, and printed
}
\seealso{
Other test-functions:
\code{\link{expect_equal_to_reference}()},
\code{\link{expect_length}()},
\code{\link{expect_match}()},
\code{\link{ignore}()}
}
\concept{test-functions}
|