From a40ff535a732bd1b798457f2fb746cfe2dd483f7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Wed, 29 Mar 2023 20:02:25 +0200 Subject: [PATCH 1/2] Add type check to `theme_set()` --- R/theme-current.R | 1 + tests/testthat/test-theme.R | 1 + 2 files changed, 2 insertions(+) diff --git a/R/theme-current.R b/R/theme-current.R index 396b53e95b..b56b2e1651 100644 --- a/R/theme-current.R +++ b/R/theme-current.R @@ -90,6 +90,7 @@ theme_get <- function() { #' @param new new theme (a list of theme elements) #' @export theme_set <- function(new) { + check_object(new, is.theme, "a {.cls theme} object") old <- ggplot_global$theme_current ggplot_global$theme_current <- new invisible(old) diff --git a/tests/testthat/test-theme.R b/tests/testthat/test-theme.R index 3d64894b15..5ec9792457 100644 --- a/tests/testthat/test-theme.R +++ b/tests/testthat/test-theme.R @@ -264,6 +264,7 @@ test_that("incorrect theme specifications throw meaningful errors", { expect_snapshot_error(calc_element("line", theme(line = element_rect()))) register_theme_elements(element_tree = list(test = el_def("element_rect"))) expect_snapshot_error(calc_element("test", theme_gray() + theme(test = element_rect()))) + expect_snapshot_error(theme_set("foo")) }) test_that("element tree can be modified", { From acda81cb522067e16a49629901c98f3dc3b15362 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:22:41 +0200 Subject: [PATCH 2/2] Include test snapshot --- tests/testthat/_snaps/theme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testthat/_snaps/theme.md b/tests/testthat/_snaps/theme.md index 6fd9ed6eb3..0fe584926a 100644 --- a/tests/testthat/_snaps/theme.md +++ b/tests/testthat/_snaps/theme.md @@ -20,6 +20,10 @@ Theme element `test` has "NULL" property without default: fill, colour, linewidth, and linetype +--- + + `new` must be a object, not the string "foo". + # element tree can be modified The `blablabla` theme element is not defined in the element hierarchy.