Skip to content

Commit

Permalink
new expectation expect_success
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Müller committed Oct 3, 2015
1 parent 3ecdae7 commit 5c9eec7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -32,6 +32,7 @@ Collate:
'expectations-matches.R'
'expectations-old.R'
'expectations-silent.R'
'expectations-success.R'
'expectations.r'
'make-expectation.r'
'mock.r'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -43,6 +43,7 @@ export(expect_named)
export(expect_null)
export(expect_output)
export(expect_silent)
export(expect_success)
export(expect_that)
export(expect_true)
export(expect_warning)
Expand Down
24 changes: 24 additions & 0 deletions R/expectations-success.R
@@ -0,0 +1,24 @@
#' Expect that code succeeds.
#'
#' Use it when failure should not abort the current test.
#'
#' @param expr Expression to evaluate
#' @export
#' @examples
#' expect_success(print("Hi!"))
#' \dontrun{
#' expect_success(stop("What?"))
#' }
expect_success <- function(expr) {
label <- find_expr("expr")
out <- evaluate_promise(expr)

res <- try(force(expr), silent = TRUE)

This comment has been minimized.

Copy link
@krlmlr

krlmlr Oct 4, 2015

Owner

I missed r-lib#219, the new function seems largely unnecessary. I'd rather change it to a simple forwarder, or remove it altogether.


success <- !inherits(res, "try-error")

expect(
success,
paste(label, "raised an error:", as.character(res))
)
}
21 changes: 21 additions & 0 deletions man/expect_success.Rd
@@ -0,0 +1,21 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/expectations-success.R
\name{expect_success}
\alias{expect_success}
\title{Expect that code succeeds.}
\usage{
expect_success(expr)
}
\arguments{
\item{expr}{Expression to evaluate}
}
\description{
Use it when failure should not abort the current test.
}
\examples{
expect_success(print("Hi!"))
\dontrun{
expect_success(stop("What?"))
}
}

0 comments on commit 5c9eec7

Please sign in to comment.