Skip to content

Commit 55453da

Browse files
authored
Simplify tests by using cnd_class = TRUE from expect_snapshot() (#1758)
1 parent 3d48c13 commit 55453da

36 files changed

+387
-496
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Suggests:
3636
pillar,
3737
rmarkdown,
3838
stats,
39-
testthat (>= 3.0.0),
39+
testthat (>= 3.2.0),
4040
tibble,
4141
usethis,
4242
vctrs (>= 0.2.3),

tests/testthat/_snaps/arg.md

Lines changed: 70 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,224 +5,199 @@
55
# gives an error with more than one arg
66

77
Code
8-
(expect_error(arg_match0_wrapper(c("bar", "fun"), c("bar", "baz"))))
9-
Output
10-
<error/rlang_error>
8+
arg_match0_wrapper(c("bar", "fun"), c("bar", "baz"))
9+
Condition <rlang_error>
1110
Error in `arg_match0_wrapper()`:
1211
! `arg` must be length 1 or a permutation of `c("bar", "baz")`.
1312

1413
# gives error with different than rearranged arg vs value
1514

16-
`myarg` must be one of "fun" or "bar", not "foo".
17-
18-
---
19-
20-
`arg` must be length 1 or a permutation of `c("foo", "bar")`.
15+
Code
16+
f()
17+
Condition
18+
Error in `f()`:
19+
! `myarg` must be one of "fun" or "bar", not "foo".
20+
Code
21+
arg_match0_wrapper(c("foo", "foo"), c("foo", "bar"), arg_nm = "x")
22+
Condition
23+
Error in `arg_match0_wrapper()`:
24+
! `arg` must be length 1 or a permutation of `c("foo", "bar")`.
2125

2226
# `arg_match()` has informative error messages
2327

2428
Code
25-
(expect_error(arg_match_wrapper("continuuos", c("discrete", "continuous"),
26-
"my_arg")))
27-
Output
28-
<error/rlang_error>
29+
arg_match_wrapper("continuuos", c("discrete", "continuous"), "my_arg")
30+
Condition <rlang_error>
2931
Error in `arg_match0_wrapper()`:
3032
! `my_arg` must be one of "discrete" or "continuous", not "continuuos".
3133
i Did you mean "continuous"?
3234
Code
33-
(expect_error(arg_match_wrapper("fou", c("bar", "foo"), "my_arg")))
34-
Output
35-
<error/rlang_error>
35+
arg_match_wrapper("fou", c("bar", "foo"), "my_arg")
36+
Condition <rlang_error>
3637
Error in `arg_match0_wrapper()`:
3738
! `my_arg` must be one of "bar" or "foo", not "fou".
3839
i Did you mean "foo"?
3940
Code
40-
(expect_error(arg_match_wrapper("fu", c("ba", "fo"), "my_arg")))
41-
Output
42-
<error/rlang_error>
41+
arg_match_wrapper("fu", c("ba", "fo"), "my_arg")
42+
Condition <rlang_error>
4343
Error in `arg_match0_wrapper()`:
4444
! `my_arg` must be one of "ba" or "fo", not "fu".
4545
i Did you mean "fo"?
4646
Code
47-
(expect_error(arg_match_wrapper("baq", c("foo", "baz", "bas"), "my_arg")))
48-
Output
49-
<error/rlang_error>
47+
arg_match_wrapper("baq", c("foo", "baz", "bas"), "my_arg")
48+
Condition <rlang_error>
5049
Error in `arg_match0_wrapper()`:
5150
! `my_arg` must be one of "foo", "baz", or "bas", not "baq".
5251
i Did you mean "baz"?
5352
Code
54-
(expect_error(arg_match_wrapper("", character(), "my_arg")))
55-
Output
56-
<error/rlang_error>
53+
arg_match_wrapper("", character(), "my_arg")
54+
Condition <rlang_error>
5755
Error in `arg_match0()`:
5856
! `values` must have at least one element.
5957
Code
60-
(expect_error(arg_match_wrapper("fo", "foo", quote(f()))))
61-
Output
62-
<error/rlang_error>
58+
arg_match_wrapper("fo", "foo", quote(f()))
59+
Condition <rlang_error>
6360
Error in `arg_match0()`:
6461
! `arg_nm` must be a string or symbol.
6562

6663
# `arg_match()` provides no suggestion when the edit distance is too large
6764

6865
Code
69-
(expect_error(arg_match0_wrapper("foobaz", c("fooquxs", "discrete"), "my_arg")))
70-
Output
71-
<error/rlang_error>
66+
arg_match0_wrapper("foobaz", c("fooquxs", "discrete"), "my_arg")
67+
Condition <rlang_error>
7268
Error in `arg_match0_wrapper()`:
7369
! `my_arg` must be one of "fooquxs" or "discrete", not "foobaz".
7470
Code
75-
(expect_error(arg_match0_wrapper("a", c("b", "c"), "my_arg")))
76-
Output
77-
<error/rlang_error>
71+
arg_match0_wrapper("a", c("b", "c"), "my_arg")
72+
Condition <rlang_error>
7873
Error in `arg_match0_wrapper()`:
7974
! `my_arg` must be one of "b" or "c", not "a".
8075

8176
# `arg_match()` makes case-insensitive match
8277

8378
Code
84-
(expect_error(arg_match0_wrapper("a", c("A", "B"), "my_arg"),
85-
"Did you mean \"A\"?"))
86-
Output
87-
<error/rlang_error>
79+
arg_match0_wrapper("a", c("A", "B"), "my_arg")
80+
Condition <rlang_error>
8881
Error in `arg_match0_wrapper()`:
8982
! `my_arg` must be one of "A" or "B", not "a".
9083
i Did you mean "A"?
9184
Code
92-
(expect_error(arg_match0_wrapper("aa", c("AA", "aA"), "my_arg"),
93-
"Did you mean \"aA\"?"))
94-
Output
95-
<error/rlang_error>
85+
arg_match0_wrapper("aa", c("AA", "aA"), "my_arg")
86+
Condition <rlang_error>
9687
Error in `arg_match0_wrapper()`:
9788
! `my_arg` must be one of "AA" or "aA", not "aa".
9889
i Did you mean "aA"?
9990

10091
# check_required() checks argument is supplied (#1118)
10192

10293
Code
103-
(expect_error(f()))
104-
Output
105-
<error/rlang_error>
94+
f()
95+
Condition <rlang_error>
10696
Error in `f()`:
10797
! `x` is absent but must be supplied.
10898
Code
109-
(expect_error(g()))
110-
Output
111-
<error/rlang_error>
99+
g()
100+
Condition <rlang_error>
112101
Error in `f()`:
113102
! `x` is absent but must be supplied.
114103

115104
# arg_match() supports symbols and scalar strings
116105

117106
Code
118-
(expect_error(arg_match0_wrapper(chr_get("fo", 0L), c("bar", "foo"), "my_arg")))
119-
Output
120-
<error/rlang_error>
107+
arg_match0_wrapper(chr_get("fo", 0L), c("bar", "foo"), "my_arg")
108+
Condition <rlang_error>
121109
Error in `arg_match0_wrapper()`:
122110
! `my_arg` must be one of "bar" or "foo", not "fo".
123111
i Did you mean "foo"?
124112

125113
# arg_match() requires an argument symbol
126114

127115
Code
128-
(expect_error(wrapper()))
129-
Output
130-
<error/rlang_error>
116+
wrapper()
117+
Condition <rlang_error>
131118
Error in `arg_match()`:
132119
! `arg` must be a symbol, not the string "foo".
133120

134121
# can match multiple arguments
135122

136123
Code
137-
(expect_error(my_wrapper("ba")))
138-
Output
139-
<error/rlang_error>
124+
my_wrapper("ba")
125+
Condition <rlang_error>
140126
Error in `my_wrapper()`:
141127
! `my_arg` must be one of "foo", "bar", or "baz", not "ba".
142128
i Did you mean "bar"?
143129
Code
144-
(expect_error(my_wrapper(c("foo", "ba"))))
145-
Output
146-
<error/rlang_error>
130+
my_wrapper(c("foo", "ba"))
131+
Condition <rlang_error>
147132
Error in `my_wrapper()`:
148133
! `my_arg` must be one of "foo", "bar", or "baz", not "ba".
149134
i Did you mean "bar"?
150135

151136
# arg_match0() defuses argument
152137

153138
Code
154-
(expect_error(fn("foo")))
155-
Output
156-
<error/rlang_error>
139+
fn("foo")
140+
Condition <rlang_error>
157141
Error in `fn()`:
158142
! `arg` must be one of "bar" or "baz", not "foo".
159143
Code
160-
(expect_error(arg_match0("foo", c("bar", "baz"))))
161-
Output
162-
<error/rlang_error>
144+
arg_match0("foo", c("bar", "baz"))
145+
Condition <rlang_error>
163146
Error:
164147
! `"foo"` must be one of "bar" or "baz", not "foo".
165148

166149
# check_exclusive works
167150

168151
Code
169-
(expect_error(f()))
170-
Output
171-
<error/rlang_error>
152+
f()
153+
Condition <rlang_error>
172154
Error in `check_exclusive()`:
173155
! Must supply at least two arguments.
174156
Code
175-
(expect_error(g()))
176-
Output
177-
<error/rlang_error>
157+
g()
158+
Condition <rlang_error>
178159
Error in `check_exclusive()`:
179160
! Must supply at least two arguments.
180161
Code
181-
(expect_error(h()))
182-
Output
183-
<error/rlang_error>
162+
h()
163+
Condition <rlang_error>
184164
Error in `check_exclusive()`:
185165
! Must supply at least two arguments.
186166

187167
---
188168

189169
Code
190-
(expect_error(f()))
191-
Output
192-
<error/rlang_error>
170+
f()
171+
Condition <rlang_error>
193172
Error in `f()`:
194173
! One of `foo` or `bar` must be supplied.
195174

196175
---
197176

198177
Code
199178
# All arguments supplied
200-
(expect_error(g(foo, bar, baz)))
201-
Output
202-
<error/rlang_error>
179+
g(foo, bar, baz)
180+
Condition <rlang_error>
203181
Error in `g()`:
204182
! Exactly one of `foo`, `bar`, or `baz` must be supplied.
205183
Code
206184
# Some arguments supplied
207-
(expect_error(g(foo, bar)))
208-
Output
209-
<error/rlang_error>
185+
g(foo, bar)
186+
Condition <rlang_error>
210187
Error in `g()`:
211188
! Exactly one of `foo`, `bar`, or `baz` must be supplied.
212189
x `foo` and `bar` were supplied together.
213190

214191
# arg_match() mentions correct call if wrong type is supplied (#1388)
215192

216193
Code
217-
(expect_error(f(1)))
218-
Output
219-
<error/rlang_error>
194+
f(1)
195+
Condition <rlang_error>
220196
Error in `f()`:
221197
! `my_arg` must be a string or character vector.
222198
Code
223-
(expect_error(g(1)))
224-
Output
225-
<error/rlang_error>
199+
g(1)
200+
Condition <rlang_error>
226201
Error in `g()`:
227202
! `my_arg` must be a character vector, not the number 1.
228203

@@ -253,21 +228,18 @@
253228
# arg_match() supports `NA` (#1519)
254229

255230
Code
256-
(expect_error(f(NA)))
257-
Output
258-
<error/rlang_error>
231+
f(NA)
232+
Condition <rlang_error>
259233
Error in `f()`:
260234
! `x` must be a character vector, not `NA`.
261235
Code
262-
(expect_error(f(na_chr)))
263-
Output
264-
<error/rlang_error>
236+
f(na_chr)
237+
Condition <rlang_error>
265238
Error in `f()`:
266239
! `x` must be a single string, not a character `NA`.
267240
Code
268-
(expect_error(f(chr())))
269-
Output
270-
<error/rlang_error>
241+
f(chr())
242+
Condition <rlang_error>
271243
Error in `f()`:
272244
! `x` must be length 1, not length 0
273245

tests/testthat/_snaps/attr.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# inputs must be valid
22

33
Code
4-
(expect_error(set_names(environment())))
5-
Output
6-
<error/rlang_error>
4+
set_names(environment())
5+
Condition <rlang_error>
76
Error in `set_names()`:
87
! `x` must be a vector
98
Code
10-
(expect_error(set_names(1:10, letters[1:4])))
11-
Output
12-
<error/rlang_error>
9+
set_names(1:10, letters[1:4])
10+
Condition <rlang_error>
1311
Error in `set_names()`:
1412
! The size of `nm` (4) must be compatible with the size of `x` (10).
1513

tests/testthat/_snaps/c-api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
# re-encoding fails purposefully with any bytes
2323

2424
Code
25-
(expect_error(r_obj_encode_utf8(bytes)))
26-
Output
27-
<simpleError in r_obj_encode_utf8(bytes): translating strings with "bytes" encoding is not allowed>
25+
r_obj_encode_utf8(bytes)
26+
Condition <simpleError>
27+
Error in `r_obj_encode_utf8()`:
28+
! translating strings with "bytes" encoding is not allowed
2829

2930
---
3031

tests/testthat/_snaps/cnd-handlers.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# try_fetch() checks inputs
22

33
Code
4-
(expect_error(try_fetch(NULL, function(...) NULL)))
5-
Output
6-
<error/rlang_error>
4+
try_fetch(NULL, function(...) NULL)
5+
Condition <rlang_error>
76
Error in `try_fetch()`:
87
! `...` must be named with condition classes.
98

tests/testthat/_snaps/cnd-message.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,16 @@
209209
# parent errors prints with bullets in all cases
210210

211211
Code
212-
(expect_error(f(TRUE)))
213-
Output
214-
<error/rlang_error>
212+
f(TRUE)
213+
Condition <rlang_error>
215214
Error in `f()`:
216215
! Wrapper
217216
Caused by error in `f()`:
218217
! Header
219218
i Bullet
220219
Code
221-
(expect_error(f(FALSE)))
222-
Output
223-
<error/rlang_error>
220+
f(FALSE)
221+
Condition <rlang_error>
224222
Error in `f()`:
225223
! Wrapper
226224
Caused by error in `f()`:

0 commit comments

Comments
 (0)