Skip to content
Permalink
Browse files

new expectation expect_success

  • Loading branch information...
Kirill Müller
Kirill Müller committed Oct 3, 2015
1 parent 3ecdae7 commit 5c9eec7c805bb4e140b9ce471837f9619de2ae65
Showing with 47 additions and 0 deletions.
  1. +1 −0 DESCRIPTION
  2. +1 −0 NAMESPACE
  3. +24 −0 R/expectations-success.R
  4. +21 −0 man/expect_success.Rd
@@ -32,6 +32,7 @@ Collate:
'expectations-matches.R'
'expectations-old.R'
'expectations-silent.R'
'expectations-success.R'
'expectations.r'
'make-expectation.r'
'mock.r'
@@ -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)
@@ -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))
)
}
@@ -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.
You can’t perform that action at this time.