1
1
# ' The building block of all `expect_` functions
2
2
# '
3
3
# ' Use this if you are writing your own expectation. See
4
- # ' `vignette("custom-expectation")` for details
4
+ # ' `vignette("custom-expectation")` for details.
5
5
# '
6
6
# ' @param ok Was the expectation successful?
7
7
# ' @param failure_message What message should be shown if the expectation was
12
12
# ' forward a srcref captured elsewhere.
13
13
# ' @export
14
14
expect <- function (ok , failure_message , info = NULL , srcref = NULL ) {
15
- exp <- as.expectation.logical(ok , failure_message , info = info , srcref = srcref )
15
+ type <- if (ok ) " success" else " failure"
16
+ message <- paste(c(failure_message , info ), collapse = " \n " )
17
+ exp <- expectation(type , message , srcref = srcref )
16
18
17
19
withRestarts(
18
20
if (expectation_broken(exp )) {
@@ -28,8 +30,14 @@ expect <- function(ok, failure_message, info = NULL, srcref = NULL) {
28
30
29
31
# ' Construct an expectation object
30
32
# '
31
- # ' For advanced use only.
33
+ # ' For advanced use only. If you are creating your own expectation, you should
34
+ # ' call `expect()` instead. See `vignette("custom-expectation")` for more
35
+ # ' details.
32
36
# '
37
+ # ' @param type Expectation type. Must be one of "success", "failure", "error",
38
+ # ' "skip", "warning".
39
+ # ' @param message Message describing test failure
40
+ # ' @param srcref Optional `srcref` giving location of test.
33
41
# ' @keywords internal
34
42
# ' @export
35
43
expectation <- function (type , message , srcref = NULL ) {
@@ -184,17 +192,6 @@ as.expectation.expectation <- function(x, ..., srcref = NULL) {
184
192
x
185
193
}
186
194
187
- # ' @export
188
- as.expectation.logical <- function (x , message , ... , srcref = NULL , info = NULL ) {
189
- type <- if (x ) " success" else " failure"
190
- message <- if (x ) " success" else add_info(message , info )
191
- expectation(type , message , srcref = srcref )
192
- }
193
-
194
- add_info <- function (message , info = NULL ) {
195
- paste(c(message , info ), collapse = " \n " )
196
- }
197
-
198
195
# ' @export
199
196
as.expectation.error <- function (x , ... , srcref = NULL ) {
200
197
error <- x $ message
@@ -227,7 +224,9 @@ as.expectation.skip <- function(x, ..., srcref = NULL) {
227
224
}
228
225
229
226
# ' @export
230
- print.expectation <- function (x , ... ) cat(format(x ), " \n " )
227
+ print.expectation <- function (x , ... ) {
228
+ cat(format(x ), " \n " )
229
+ }
231
230
232
231
# ' @export
233
232
format.expectation_success <- function (x , ... ) {
0 commit comments