Skip to content

Commit 2931bd9

Browse files
committed
More consistentct
1 parent cdf59be commit 2931bd9

25 files changed

+216
-437
lines changed

R/expect-condition.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ compare_condition_3e <- function(cond_type, cond_class, cond, lab, expected) {
455455
} else {
456456
if (!is.null(cond)) {
457457
c(
458-
sprintf("Expected %s to not throw a %s.", lab, cond_type),
458+
sprintf("Expected %s to not throw any %ss.", lab, cond_type),
459459
actual_condition(cond)
460460
)
461461
} else {

R/expect-constant.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ expect_false <- function(object, info = NULL, label = NULL) {
5858
#' show_failure(expect_null(y))
5959
expect_null <- function(object, info = NULL, label = NULL) {
6060
act <- quasi_label(enquo(object), label)
61-
exp <- labelled_value(NULL, "FALSE")
61+
exp <- labelled_value(NULL, "NULL")
6262
expect_waldo_constant_(act, exp, info = info)
6363
}
6464

R/expect-equality.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ expect_equal <- function(
7777
}
7878

7979
if (!comp$equal) {
80-
msg <- sprintf(
81-
"Expected %s to equal %s.\nActual:\n%s",
82-
act$lab,
83-
exp$lab,
80+
msg <- c(
81+
sprintf("Expected %s to equal %s.", act$lab, exp$lab),
82+
"Differences:",
8483
comp$message
8584
)
8685
return(fail(msg, info = info))
@@ -89,6 +88,7 @@ expect_equal <- function(
8988
}
9089
}
9190

91+
9292
#' @export
9393
#' @rdname equality-expectations
9494
expect_identical <- function(
@@ -120,6 +120,7 @@ expect_identical <- function(
120120
if (!ident) {
121121
msg <- c(
122122
sprintf("Expected %s to be identical to %s.", act$lab, exp$lab),
123+
"Differences:",
123124
msg_act
124125
)
125126
return(fail(msg, info = info))

R/expect-inheritance.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ expect_is <- function(object, class, info = NULL, label = NULL) {
255255

256256
if (!inherits(act$val, class)) {
257257
msg <- sprintf(
258-
"Expected %s to inherit from `%s`.\nActual inheritance: `%s`",
258+
"Expected %s to inherit from %s.\nActual inheritance: %s",
259259
act$lab,
260260
exp_lab,
261261
act$class
@@ -270,7 +270,7 @@ expect_is <- function(object, class, info = NULL, label = NULL) {
270270
isS3 <- function(x) is.object(x) && !isS4(x)
271271

272272
format_class <- function(x) {
273-
paste0(encodeString(x, quote = "'"), collapse = "/")
273+
paste0(encodeString(x, quote = '"'), collapse = "/")
274274
}
275275

276276
oo_type <- function(x) {

R/expect-no-condition.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ expect_no_ <- function(
111111
msg_exp <- paste0(
112112
"Expected ",
113113
act$lab,
114-
" to run without any ",
114+
" to not throw any ",
115115
base_class,
116116
"s",
117117
if (!is.null(class)) paste0(" of class '", class, "'"),

R/expect-self-test.R

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ capture_success_failure <- function(expr) {
4646
expect_success <- function(expr) {
4747
status <- capture_success_failure(expr)
4848

49-
if (status$n_success == 0) {
50-
return(fail("Expectation did not succeed"))
51-
} else if (status$n_success > 1) {
52-
return(fail(sprintf(
53-
"Expected expectation to succeed once.\nActually succeeded: %i times",
54-
status$n_success
55-
)))
49+
if (status$n_success != 1) {
50+
msg <- c(
51+
"Expected code to succeed exactly once.",
52+
sprintf("Actually succeeded %i times", status$n_success)
53+
)
54+
return(fail(msg))
5655
}
5756

5857
if (status$n_failure > 0) {
59-
return(fail(sprintf(
60-
"Expected expectation to not fail.\nActually failed: %i times",
61-
status$n_failure
62-
)))
58+
msg <- c(
59+
"Expected code to not fail.",
60+
sprintf("Actually failed %i times", status$n_failure)
61+
)
62+
return(fail(msg))
6363
}
6464

6565
pass(NULL)
@@ -70,23 +70,25 @@ expect_success <- function(expr) {
7070
expect_failure <- function(expr, message = NULL, ...) {
7171
status <- capture_success_failure(expr)
7272

73-
if (status$n_failure == 0) {
74-
return(fail("Expectation did not fail"))
75-
} else if (status$n_failure > 1) {
76-
# This should be impossible, but including for completeness
77-
return(fail("Expectation failed more than once"))
73+
if (status$n_failure != 1) {
74+
msg <- c(
75+
"Expected code to fail exactly once.",
76+
sprintf("Actually failed %i times", status$n_failure)
77+
)
78+
return(fail(msg))
7879
}
7980

8081
if (status$n_success != 0) {
81-
return(fail(sprintf(
82-
"Expected expectation to never succeed.\nActually succeeded: %i times",
83-
status$n_success
84-
)))
82+
msg <- c(
83+
"Expected code to succeed exactly once.",
84+
sprintf("Actually succeeded %i times", status$n_success)
85+
)
86+
return(fail(msg))
8587
}
8688

8789
if (!is.null(message)) {
88-
act <- labelled_value(status$last_failure$message, "Failure message")
89-
return(expect_match_(act, message, ...))
90+
act <- labelled_value(status$last_failure$message, "failure message")
91+
return(expect_match_(act, message, ..., title = "message"))
9092
}
9193
pass(NULL)
9294
}

R/expect-setequal.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ expect_in <- function(object, expected) {
123123
act_miss <- !act$val %in% exp$val
124124
if (any(act_miss)) {
125125
msg_exp <- sprintf(
126-
"Expected all values in %s to be in %s.",
126+
"Expected %s to only contain values from %s.",
127127
act$lab,
128128
exp$lab
129129
)
130-
msg_act <- sprintf("Extra: %s", values(act$val[act_miss]))
130+
msg_act <- sprintf("Invalid: %s", values(act$val[act_miss]))
131131
fail(c(msg_exp, msg_act))
132132
}
133133

R/expect-silent.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ expect_silent <- function(object) {
2929
if (length(outputs) != 0) {
3030
msg <- c(
3131
sprintf("Expected %s to run silently.", act$lab),
32-
sprintf("Actually produced: %s.", paste(outputs, collapse = ", "))
32+
sprintf("Actual noise: %s.", paste(outputs, collapse = ", "))
3333
)
3434
return(fail(msg))
3535
}

tests/testthat/_snaps/expect-condition.md

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
expect_error(stop("Yes"), NA)
1313
Condition
1414
Error:
15-
! Expected `stop("Yes")` to not throw a error.
15+
! Expected `stop("Yes")` to not throw any errors.
1616
Actually got a <simpleError> with message:
1717
Yes
1818

@@ -48,7 +48,7 @@
4848
expect_error(fb(), NA)
4949
Condition
5050
Error:
51-
! Expected `fb()` to not throw a error.
51+
! Expected `fb()` to not throw any errors.
5252
Actually got a <foobar> with message:
5353
dispatched!
5454

@@ -78,10 +78,10 @@
7878
# regexp = NA checks for absence of message
7979

8080
Code
81-
expect_message(message("!"), NA)
81+
expect_message(f(), NA)
8282
Condition
8383
Error:
84-
! Expected `message("!")` to not throw a message.
84+
! Expected `f()` to not throw any messages.
8585
Actually got a <simpleMessage> with message:
8686
!
8787
@@ -173,67 +173,3 @@
173173
* Unused arguments: `pattern` and `fixed`.
174174
i Did you mean to use `regexp` so `...` is passed to `grepl()`?
175175

176-
# other conditions are swallowed
177-
178-
Code
179-
expect_error(f("error"), "not a match")
180-
Condition
181-
Error:
182-
! `f("error")` threw an error with unexpected message.
183-
Expected match: "not a match"
184-
Actual message: "error"
185-
186-
---
187-
188-
Code
189-
expect_warning(f("warning"), "not a match")
190-
Condition
191-
Error:
192-
! `f("warning")` produced unexpected warnings.
193-
Expected match: not a match
194-
Actual values:
195-
* warning
196-
197-
---
198-
199-
Code
200-
expect_message(f("message"), "not a match")
201-
Condition
202-
Error:
203-
! `f("message")` produced unexpected messages.
204-
Expected match: not a match
205-
Actual values:
206-
* message
207-
208-
---
209-
210-
Code
211-
expect_condition(f("condition"), "not a match")
212-
Condition
213-
Error:
214-
! `f("condition")` threw an condition with unexpected message.
215-
Expected match: "not a match"
216-
Actual message: "signal"
217-
218-
---
219-
220-
Code
221-
expect_error(f("error"), class = "not a match")
222-
Condition
223-
Error:
224-
! `f("error")` threw an error with unexpected class.
225-
Expected class: not a match
226-
Actual class: simpleError/error/condition
227-
Message: error
228-
229-
---
230-
231-
Code
232-
expect_condition(f("message"), class = "not a match")
233-
Condition
234-
Error:
235-
! `f("message")` threw an condition with unexpected class.
236-
Expected class: not a match
237-
Actual class: simpleMessage/message/condition
238-
Message: message
239-

tests/testthat/_snaps/expect-constant.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
expect_null(df)
5353
Condition
5454
Error:
55-
! Expected `df` to be FALSE.
55+
! Expected `df` to be NULL.
5656
Differences:
5757
`actual` is an S3 object of class <data.frame>, a list
5858
`expected` is NULL

0 commit comments

Comments
 (0)