Skip to content

Commit 5d41f0e

Browse files
committed
allow variant error messages
1 parent edda7e4 commit 5d41f0e

File tree

7 files changed

+22
-41
lines changed

7 files changed

+22
-41
lines changed

tests/testthat/_snaps/4.0/theme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# modifying theme element properties with + operator works
2+
3+
Code
4+
theme_grey() + "asdf"
5+
Condition
6+
Error in `method(+, list(ggplot2::theme, class_any))`:
7+
! Can't add `"asdf"` to a theme object.
8+

tests/testthat/_snaps/4.4/theme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# modifying theme element properties with + operator works
2+
3+
Code
4+
theme_grey() + "asdf"
5+
Condition
6+
Error:
7+
! Can't add `"asdf"` to a theme object.
8+

tests/testthat/_snaps/error.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/testthat/_snaps/theme.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
# modifying theme element properties with + operator works
2-
3-
Code
4-
theme_grey() + "asdf"
5-
Condition
6-
Error:
7-
! Can't add `"asdf"` to a theme object.
8-
9-
# replacing theme elements with %+replace% operator works
10-
11-
Code
12-
theme_grey() + "asdf"
13-
Condition
14-
Error:
15-
! Can't add `"asdf"` to a theme object.
16-
171
# theme validation happens at build stage
182

193
The `text` theme element must be a <element_text> object.

tests/testthat/test-error.R

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/testthat/test-plot.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_that("ggplot() throws informative errors", {
55
})
66

77
test_that("construction have user friendly errors", {
8+
skip_if(getRversion() < "4.3.0")
89
expect_snapshot_error(+ geom_point())
910
expect_snapshot_error(geom_point() + geom_bar())
1011
expect_snapshot_error(ggplot() + 1)

tests/testthat/test-theme.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ test_that("modifying theme element properties with + operator works", {
4949
t <- theme_grey() + theme()
5050
expect_identical(t, theme_grey())
5151

52-
expect_snapshot(theme_grey() + "asdf", error = TRUE)
52+
expect_snapshot(
53+
theme_grey() + "asdf",
54+
error = TRUE,
55+
variant = substr(as.character(getRversion()), start = 1, stop = 3)
56+
)
5357
})
5458

5559
test_that("adding theme object to ggplot object with + operator works", {
@@ -114,8 +118,6 @@ test_that("replacing theme elements with %+replace% operator works", {
114118
# Adding empty theme() has no effect
115119
t <- theme_grey() %+replace% theme()
116120
expect_identical(t, theme_grey())
117-
118-
expect_snapshot(theme_grey() + "asdf", error = TRUE)
119121
})
120122

121123
test_that("calculating theme element inheritance works", {

0 commit comments

Comments
 (0)