Skip to content

Commit f31b024

Browse files
kevinusheyhadley
andauthored
Fix message typos (#1824)
And tweak failure mesage --------- Co-authored-by: Hadley Wickham <[email protected]>
1 parent db92502 commit f31b024

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
* `expect_error()`, `expect_warning()`, and `expect_message()` now correctly
4343
enforce that the condition is of the expected base class (e.g. error,
44-
warning, messsage) even when the `class` argument is used (#1168).
44+
warning, message) even when the `class` argument is used (#1168).
4545

4646
* `it()` now calls `local_test_context()` so that it behaves more
4747
similarly to `test_that()` (#1731), and is now exported so that you
@@ -483,7 +483,7 @@ Learn more in `vignette("third-edition")`.
483483

484484
* Messages are no longer automatically silenced. Either use
485485
`suppressMessages()` to hide unimportant messages, or
486-
`expect_messsage()` to catch important messages (#1095).
486+
`expect_message()` to catch important messages (#1095).
487487

488488
* `setup()` and `teardown()` are deprecated in favour of test fixtures.
489489
See `vignette("test-fixtures")` for more details.

R/expect-no-condition.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ expect_no_message <- function(object,
6868
class = NULL
6969
) {
7070
check_dots_empty()
71-
expect_no_("messsage", {{ object }}, regexp = message, class = class)
71+
expect_no_("message", {{ object }}, regexp = message, class = class)
7272
}
7373

7474
#' @export
@@ -111,8 +111,8 @@ expect_no_ <- function(base_class,
111111
"."
112112
)
113113
actual <- paste0(
114-
"Actually got a <", class(cnd)[[1]], ">:\n",
115-
indent_lines(rlang::cnd_message(cnd, prefix = TRUE))
114+
"Actually got a <", class(cnd)[[1]], "> with text:\n",
115+
indent_lines(rlang::cnd_message(cnd))
116116
)
117117
message <- format_error_bullets(c(expected, i = actual))
118118
fail(message, trace_env = error_call)
Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,68 @@
1+
# expect_no_* conditions behave as expected
2+
3+
Expected `stop("error")` to run without any errors.
4+
i Actually got a <simpleError> with text:
5+
error
6+
7+
---
8+
9+
Expected `warning("warning")` to run without any warnings.
10+
i Actually got a <simpleWarning> with text:
11+
warning
12+
13+
---
14+
15+
Expected `message("message")` to run without any messages.
16+
i Actually got a <simpleMessage> with text:
17+
message
18+
19+
20+
---
21+
22+
Expected `abort("error")` to run without any errors.
23+
i Actually got a <rlang_error> with text:
24+
error
25+
26+
---
27+
28+
Expected `warn("warning")` to run without any warnings.
29+
i Actually got a <rlang_warning> with text:
30+
warning
31+
32+
---
33+
34+
Expected `inform("message")` to run without any messages.
35+
i Actually got a <rlang_message> with text:
36+
message
37+
138
# matched conditions give informative message
239

340
Code
441
expect_no_warning(foo())
542
Condition
643
Error:
744
! Expected `foo()` to run without any warnings.
8-
i Actually got a <test>:
9-
Warning:
45+
i Actually got a <test> with text:
1046
This is a problem!
1147
Code
1248
expect_no_warning(foo(), message = "problem")
1349
Condition
1450
Error:
1551
! Expected `foo()` to run without any warnings matching pattern 'problem'.
16-
i Actually got a <test>:
17-
Warning:
52+
i Actually got a <test> with text:
1853
This is a problem!
1954
Code
2055
expect_no_warning(foo(), class = "test")
2156
Condition
2257
Error:
2358
! Expected `foo()` to run without any warnings of class 'test'.
24-
i Actually got a <test>:
25-
Warning:
59+
i Actually got a <test> with text:
2660
This is a problem!
2761
Code
2862
expect_no_warning(foo(), message = "problem", class = "test")
2963
Condition
3064
Error:
3165
! Expected `foo()` to run without any warnings of class 'test' matching pattern 'problem'.
32-
i Actually got a <test>:
33-
Warning:
66+
i Actually got a <test> with text:
3467
This is a problem!
3568

tests/testthat/test-expect-no-condition.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2+
test_that("expect_no_* conditions behave as expected", {
3+
4+
# base R
5+
expect_snapshot_failure(expect_no_error(stop("error")))
6+
expect_snapshot_failure(expect_no_warning(warning("warning")))
7+
expect_snapshot_failure(expect_no_message(message("message")))
8+
9+
# rlang equivalents
10+
expect_snapshot_failure(expect_no_error(abort("error")))
11+
expect_snapshot_failure(expect_no_warning(warn("warning")))
12+
expect_snapshot_failure(expect_no_message(inform("message")))
13+
14+
})
15+
116
test_that("unmatched conditions bubble up", {
217
expect_error(expect_no_error(abort("foo"), message = "bar"), "foo")
318
expect_warning(expect_no_warning(warn("foo"), message = "bar"), "foo")

0 commit comments

Comments
 (0)