Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use expect_snapshot(error = TRUE) instead of expect_error() #6150

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/testthat/_snaps/aes-setting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# aesthetic parameters match length of data

Code
set_colours(rep("red", 2))
Condition
Error in `geom_point()`:
! Problem while setting up geom aesthetics.
i Error occurred in the 1st layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (5).
x Fix the following mappings: `colour`.

---

Code
set_colours(rep("red", 3))
Condition
Error in `geom_point()`:
! Problem while setting up geom aesthetics.
i Error occurred in the 1st layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (5).
x Fix the following mappings: `colour`.

---

Code
set_colours(rep("red", 4))
Condition
Error in `geom_point()`:
! Problem while setting up geom aesthetics.
i Error occurred in the 1st layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (5).
x Fix the following mappings: `colour`.

11 changes: 11 additions & 0 deletions tests/testthat/_snaps/aes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# aes evaluated in environment where plot created

Code
get_layer_data(p)
Condition
Error in `geom_point()`:
! Problem while computing aesthetics.
i Error occurred in the 1st layer.
Caused by error:
! object 'foo' not found

# aes evaluation fails with unknown input

Unknown input: <environment>
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/coord-.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@

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

# check coord limits errors only on bad inputs

Code
check_coord_limits(xlim(1, 2))
Condition
Error:
! `xlim(1, 2)` must be a vector of length 2, not a <ScaleContinuousPosition> object.

---

Code
check_coord_limits(1:3)
Condition
Error:
! `1:3` must be a vector of length 2, not an integer vector of length 3.

27 changes: 27 additions & 0 deletions tests/testthat/_snaps/empty-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# layers with empty data are silently omitted with facet_wrap

Code
get_layer_data(d)
Condition
Error in `combine_vars()`:
! Faceting variables must have at least one value.

# layers with empty data are silently omitted with facet_grid

Code
get_layer_data(d)
Condition
Error in `combine_vars()`:
! Faceting variables must have at least one value.

# empty data overrides plot defaults

Code
get_layer_data(d)
Condition
Error in `geom_point()`:
! Problem while computing aesthetics.
i Error occurred in the 2nd layer.
Caused by error:
! object 'wt' not found

33 changes: 33 additions & 0 deletions tests/testthat/_snaps/facet-.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# facets reject aes()

Code
facet_wrap(aes(foo))
Condition
Error in `validate_facets()`:
! Please use `vars()` to supply facet variables.

---

Code
facet_grid(aes(foo))
Condition
Error in `validate_facets()`:
! Please use `vars()` to supply facet variables.

# facet_grid() fails if passed both a formula and a vars()

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

# at least one combination must exist in combine_vars()

Code
combine_vars(list(df), vars = vars(letter = letter))
Condition
Error in `combine_vars()`:
! Faceting variables must have at least one value.

# combine_vars() generates the correct combinations

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

Faceting variables must have at least one value.

# eval_facet() is tolerant for missing columns (#2963)

Code
eval_facet(quo(no_such_variable * x), data_frame(foo = 1), possible_columns = c(
"x"))
Condition
Error:
! object 'no_such_variable' not found

# validate_facets() provide meaningful errors

Please use `vars()` to supply facet variables.
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/facet-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# labeller() dispatches labellers

Code
ggplotGrob(p3)
Condition
Error in `resolve_labeller()`:
! Cannot supply both `rows` and `cols` to `facet_wrap()`.

---

Code
ggplotGrob(p5)
Condition
Error in `labeller()`:
! Conflict between `.cols` and `cyl`.

150 changes: 150 additions & 0 deletions tests/testthat/_snaps/fortify.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,153 @@
`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.
i Did you accidentally pass `aes()` to the `data` argument?

# fortify.default can handle healthy data-frame-like objects

Code
fortify(X)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` must return an <integer> of length 2.

---

Code
fortify(array(1:60, 5:3))
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` must return an <integer> of length 2.

---

Code
fortify(cbind(X, Y, Z, deparse.level = 0))
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `colnames(data)` must return a <character> of length `ncol(data)`.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `dim.foo()`:
! oops!

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` must return an <integer> of length 2.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` must return an <integer> of length 2.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` can't have `NA`s or negative values.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `dim(data)` can't have `NA`s or negative values.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `dimnames(x)[[2L]]`:
! subscript out of bounds

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `colnames(data)` must return a <character> of length `ncol(data)`.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.prevalidate_data_frame_like_object()`:
! `colnames(data)` must return a <character> of length `ncol(data)`.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `as.data.frame.foo()`:
! oops!

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.postvalidate_data_frame_like_object()`:
! `as.data.frame(data)` must return a <data.frame>.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.postvalidate_data_frame_like_object()`:
! `as.data.frame(data)` must preserve dimensions.

---

Code
fortify(object)
Condition
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, or a valid <data.frame>-like object coercible by `as.data.frame()`.
Caused by error in `.postvalidate_data_frame_like_object()`:
! `as.data.frame(data)` must preserve column names.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/geom-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
Caused by error in `draw_panel()`:
! `geom_path()` can't have varying colour, linewidth, and/or alpha along the line when linetype isn't solid.

# stairstep() exists with error when an invalid `direction` is given

Code
stairstep(df, direction = "invalid")
Condition
Error in `stairstep()`:
! `direction` must be one of "hv", "vh", or "mid", not "invalid".

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/geom-rect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# geom_rect can derive corners

Code
GeomRect$setup_data(test, NULL)
Condition
Error in `resolve_rect()`:
! `geom_rect()` requires two of the following aesthetics: xmin, xmax, x, or width.
i Currently, x is present.

12 changes: 12 additions & 0 deletions tests/testthat/_snaps/geom-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@
Both `position` and `nudge_x`/`nudge_y` are supplied.
i Only use one approach to alter the position.

# geom_text() rejects exotic units

Code
ggplotGrob(p + geom_text(size = 10, size.unit = "npc"))
Condition
Error in `geom_text()`:
! Problem while converting geom to grob.
i Error occurred in the 1st layer.
Caused by error in `resolve_text_unit()`:
! `unit` must be one of "mm", "pt", "cm", "in", or "pc", not "npc".
i Did you mean "pc"?

Loading
Loading