Skip to content

Commit b747212

Browse files
authored
Use expect_snapshot(error = TRUE) instead of expect_error() (#6150)
* replace `expect_error()` by `expect_snapshot(error = TRUE)` * censor machine dependent paths in snapshots * commit snapshots * skip gnarly snapshots
1 parent c3083c7 commit b747212

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+857
-118
lines changed

tests/testthat/_snaps/aes-setting.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# aesthetic parameters match length of data
2+
3+
Code
4+
set_colours(rep("red", 2))
5+
Condition
6+
Error in `geom_point()`:
7+
! Problem while setting up geom aesthetics.
8+
i Error occurred in the 1st layer.
9+
Caused by error in `check_aesthetics()`:
10+
! Aesthetics must be either length 1 or the same as the data (5).
11+
x Fix the following mappings: `colour`.
12+
13+
---
14+
15+
Code
16+
set_colours(rep("red", 3))
17+
Condition
18+
Error in `geom_point()`:
19+
! Problem while setting up geom aesthetics.
20+
i Error occurred in the 1st layer.
21+
Caused by error in `check_aesthetics()`:
22+
! Aesthetics must be either length 1 or the same as the data (5).
23+
x Fix the following mappings: `colour`.
24+
25+
---
26+
27+
Code
28+
set_colours(rep("red", 4))
29+
Condition
30+
Error in `geom_point()`:
31+
! Problem while setting up geom aesthetics.
32+
i Error occurred in the 1st layer.
33+
Caused by error in `check_aesthetics()`:
34+
! Aesthetics must be either length 1 or the same as the data (5).
35+
x Fix the following mappings: `colour`.
36+

tests/testthat/_snaps/aes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# accessing an undefined variable results in an error
2+
3+
Code
4+
get_layer_data(p)
5+
Condition
6+
Error in `geom_point()`:
7+
! Problem while computing aesthetics.
8+
i Error occurred in the 1st layer.
9+
Caused by error:
10+
! object 'foo' not found
11+
112
# aes evaluation fails with unknown input
213

314
Unknown input: <environment>

tests/testthat/_snaps/coord-.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@
1818

1919
`coord()` has not implemented a `range()` method.
2020

21+
# check coord limits errors only on bad inputs
22+
23+
Code
24+
check_coord_limits(xlim(1, 2))
25+
Condition
26+
Error:
27+
! `xlim(1, 2)` must be a vector of length 2, not a <ScaleContinuousPosition> object.
28+
29+
---
30+
31+
Code
32+
check_coord_limits(1:3)
33+
Condition
34+
Error:
35+
! `1:3` must be a vector of length 2, not an integer vector of length 3.
36+

tests/testthat/_snaps/empty-data.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# layers with empty data are silently omitted with facet_wrap
2+
3+
Code
4+
get_layer_data(d)
5+
Condition
6+
Error in `combine_vars()`:
7+
! Faceting variables must have at least one value.
8+
9+
# layers with empty data are silently omitted with facet_grid
10+
11+
Code
12+
get_layer_data(d)
13+
Condition
14+
Error in `combine_vars()`:
15+
! Faceting variables must have at least one value.
16+
17+
# Should error when totally empty data frame because there's no x and y
18+
19+
Code
20+
get_layer_data(d)
21+
Condition
22+
Error in `geom_point()`:
23+
! Problem while computing aesthetics.
24+
i Error occurred in the 2nd layer.
25+
Caused by error:
26+
! object 'wt' not found
27+

tests/testthat/_snaps/facet-.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# facets reject aes()
2+
3+
Code
4+
facet_wrap(aes(foo))
5+
Condition
6+
Error in `validate_facets()`:
7+
! Please use `vars()` to supply facet variables.
8+
9+
---
10+
11+
Code
12+
facet_grid(aes(foo))
13+
Condition
14+
Error in `validate_facets()`:
15+
! Please use `vars()` to supply facet variables.
16+
117
# facet_grid() fails if passed both a formula and a vars()
218

319
`rows` must be `NULL` or a `vars()` list if `cols` is a `vars()` list.
@@ -30,6 +46,14 @@
3046
x Plot is missing `letter`
3147
Layer is missing `letter`
3248

49+
# at least one combination must exist in combine_vars()
50+
51+
Code
52+
combine_vars(list(df), vars = vars(letter = letter))
53+
Condition
54+
Error in `combine_vars()`:
55+
! Faceting variables must have at least one value.
56+
3357
# combine_vars() generates the correct combinations
3458

3559
At least one layer must contain all faceting variables: `b` and `c`
@@ -40,6 +64,15 @@
4064

4165
Faceting variables must have at least one value.
4266

67+
# eval_facet() is tolerant for missing columns (#2963)
68+
69+
Code
70+
eval_facet(quo(no_such_variable * x), data_frame(foo = 1), possible_columns = c(
71+
"x"))
72+
Condition
73+
Error:
74+
! object 'no_such_variable' not found
75+
4376
# validate_facets() provide meaningful errors
4477

4578
Please use `vars()` to supply facet variables.

tests/testthat/_snaps/facet-labels.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# labeller() dispatches labellers
2+
3+
Code
4+
ggplotGrob(p3)
5+
Condition
6+
Error in `resolve_labeller()`:
7+
! Cannot supply both `rows` and `cols` to `facet_wrap()`.
8+
9+
---
10+
11+
Code
12+
ggplotGrob(p5)
13+
Condition
14+
Error in `labeller()`:
15+
! Conflict between `.cols` and `cyl`.
16+

tests/testthat/_snaps/fortify.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,153 @@
33
`data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`, not a <uneval> object.
44
i Did you accidentally pass `aes()` to the `data` argument?
55

6+
# fortify.default can handle healthy data-frame-like objects
7+
8+
Code
9+
fortify(X)
10+
Condition
11+
Error in `fortify()`:
12+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
13+
Caused by error in `.prevalidate_data_frame_like_object()`:
14+
! `dim(data)` must return an <integer> of length 2.
15+
16+
---
17+
18+
Code
19+
fortify(array(1:60, 5:3))
20+
Condition
21+
Error in `fortify()`:
22+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
23+
Caused by error in `.prevalidate_data_frame_like_object()`:
24+
! `dim(data)` must return an <integer> of length 2.
25+
26+
---
27+
28+
Code
29+
fortify(cbind(X, Y, Z, deparse.level = 0))
30+
Condition
31+
Error in `fortify()`:
32+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
33+
Caused by error in `.prevalidate_data_frame_like_object()`:
34+
! `colnames(data)` must return a <character> of length `ncol(data)`.
35+
36+
---
37+
38+
Code
39+
fortify(object)
40+
Condition
41+
Error in `fortify()`:
42+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
43+
Caused by error in `dim.foo()`:
44+
! oops!
45+
46+
---
47+
48+
Code
49+
fortify(object)
50+
Condition
51+
Error in `fortify()`:
52+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
53+
Caused by error in `.prevalidate_data_frame_like_object()`:
54+
! `dim(data)` must return an <integer> of length 2.
55+
56+
---
57+
58+
Code
59+
fortify(object)
60+
Condition
61+
Error in `fortify()`:
62+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
63+
Caused by error in `.prevalidate_data_frame_like_object()`:
64+
! `dim(data)` must return an <integer> of length 2.
65+
66+
---
67+
68+
Code
69+
fortify(object)
70+
Condition
71+
Error in `fortify()`:
72+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
73+
Caused by error in `.prevalidate_data_frame_like_object()`:
74+
! `dim(data)` can't have `NA`s or negative values.
75+
76+
---
77+
78+
Code
79+
fortify(object)
80+
Condition
81+
Error in `fortify()`:
82+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
83+
Caused by error in `.prevalidate_data_frame_like_object()`:
84+
! `dim(data)` can't have `NA`s or negative values.
85+
86+
---
87+
88+
Code
89+
fortify(object)
90+
Condition
91+
Error in `fortify()`:
92+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
93+
Caused by error in `dimnames(x)[[2L]]`:
94+
! subscript out of bounds
95+
96+
---
97+
98+
Code
99+
fortify(object)
100+
Condition
101+
Error in `fortify()`:
102+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
103+
Caused by error in `.prevalidate_data_frame_like_object()`:
104+
! `colnames(data)` must return a <character> of length `ncol(data)`.
105+
106+
---
107+
108+
Code
109+
fortify(object)
110+
Condition
111+
Error in `fortify()`:
112+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
113+
Caused by error in `.prevalidate_data_frame_like_object()`:
114+
! `colnames(data)` must return a <character> of length `ncol(data)`.
115+
116+
---
117+
118+
Code
119+
fortify(object)
120+
Condition
121+
Error in `fortify()`:
122+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
123+
Caused by error in `as.data.frame.foo()`:
124+
! oops!
125+
126+
---
127+
128+
Code
129+
fortify(object)
130+
Condition
131+
Error in `fortify()`:
132+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
133+
Caused by error in `.postvalidate_data_frame_like_object()`:
134+
! `as.data.frame(data)` must return a <data.frame>.
135+
136+
---
137+
138+
Code
139+
fortify(object)
140+
Condition
141+
Error in `fortify()`:
142+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
143+
Caused by error in `.postvalidate_data_frame_like_object()`:
144+
! `as.data.frame(data)` must preserve dimensions.
145+
146+
---
147+
148+
Code
149+
fortify(object)
150+
Condition
151+
Error in `fortify()`:
152+
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
153+
Caused by error in `.postvalidate_data_frame_like_object()`:
154+
! `as.data.frame(data)` must preserve column names.
155+

tests/testthat/_snaps/geom-path.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@
55
Caused by error in `draw_panel()`:
66
! `geom_path()` can't have varying colour, linewidth, and/or alpha along the line when linetype isn't solid.
77

8+
# stairstep() exists with error when an invalid `direction` is given
9+
10+
Code
11+
stairstep(df, direction = "invalid")
12+
Condition
13+
Error in `stairstep()`:
14+
! `direction` must be one of "hv", "vh", or "mid", not "invalid".
15+

tests/testthat/_snaps/geom-rect.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# geom_rect can derive corners
2+
3+
Code
4+
GeomRect$setup_data(test, NULL)
5+
Condition
6+
Error in `resolve_rect()`:
7+
! `geom_rect()` requires two of the following aesthetics: xmin, xmax, x, or width.
8+
i Currently, x is present.
9+

tests/testthat/_snaps/geom-text.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@
33
Both `position` and `nudge_x`/`nudge_y` are supplied.
44
i Only use one approach to alter the position.
55

6+
# geom_text() rejects exotic units
7+
8+
Code
9+
ggplotGrob(p + geom_text(size = 10, size.unit = "npc"))
10+
Condition
11+
Error in `geom_text()`:
12+
! Problem while converting geom to grob.
13+
i Error occurred in the 1st layer.
14+
Caused by error in `resolve_text_unit()`:
15+
! `unit` must be one of "mm", "pt", "cm", "in", or "pc", not "npc".
16+
i Did you mean "pc"?
17+

0 commit comments

Comments
 (0)