Skip to content

Commit 056f7bc

Browse files
committed
Use pass(); rearrange for easier comprehension
1 parent 3e7628d commit 056f7bc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

R/expect-self-test.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,48 @@ capture_success_failure <- function(expr) {
4949
expect_success <- function(expr) {
5050
status <- capture_success_failure(expr)
5151

52-
if (status$n_success == 1 && status$n_failure == 0) {
53-
succeed()
54-
} else if (status$n_success == 0) {
52+
if (status$n_success == 0) {
5553
fail("Expectation did not succeed")
5654
} else if (status$n_success > 1) {
5755
fail(sprintf(
5856
"Expectation succeeded %i times, instead of once",
5957
status$n_success
6058
))
61-
} else if (status$n_failure > 0) {
59+
}
60+
61+
if (status$n_failure > 0) {
6262
fail(sprintf(
6363
"Expectation failed %i times, instead of zero",
6464
status$n_failure
6565
))
6666
}
6767

68-
invisible(NULL)
68+
pass(NULL)
6969
}
7070

7171
#' @export
7272
#' @rdname expect_success
7373
expect_failure <- function(expr, message = NULL, ...) {
7474
status <- capture_success_failure(expr)
7575

76-
if (status$n_failure == 1 && status$n_success == 0) {
77-
if (!is.null(message)) {
78-
return(expect_match(status$last_failure$message, message, ...))
79-
}
80-
succeed()
81-
} else if (status$n_failure == 0) {
76+
if (status$n_failure == 0) {
8277
fail("Expectation did not fail")
8378
} else if (status$n_failure > 1) {
8479
# This should be impossible, but including for completeness
8580
fail("Expectation failed more than once")
86-
} else if (status$n_success != 0) {
81+
}
82+
83+
if (status$n_success != 0) {
8784
fail(sprintf(
8885
"Expectation succeeded %i times, instead of never",
8986
status$n_success
9087
))
9188
}
9289

93-
invisible(NULL)
90+
if (!is.null(message)) {
91+
return(expect_match(status$last_failure$message, message, ...))
92+
}
93+
pass(NULL)
9494
}
9595

9696
#' @export

0 commit comments

Comments
 (0)