From d5f14e4d2dcf26a094cb152e6d9e15dd185c8793 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 22 May 2024 12:21:38 -0500 Subject: [PATCH] Test (and fix) theme errors --- R/theme.R | 5 +---- tests/testthat/_snaps/theme.md | 21 +++++++++++++++++++++ tests/testthat/test-theme.R | 12 ++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/_snaps/theme.md create mode 100644 tests/testthat/test-theme.R diff --git a/R/theme.R b/R/theme.R index 87964b1b2..a5e4e89fd 100644 --- a/R/theme.R +++ b/R/theme.R @@ -131,10 +131,7 @@ check_theme <- function(theme, } config_abort( error_pkg, - c( - "{.field error_path} uses theme {.val {theme}}", - i = "Valid themes are: {.val highlight_styles()}" - ), + "{.field {error_path}} uses theme {.val {theme}}", call = error_call ) } diff --git a/tests/testthat/_snaps/theme.md b/tests/testthat/_snaps/theme.md new file mode 100644 index 000000000..818b32d33 --- /dev/null +++ b/tests/testthat/_snaps/theme.md @@ -0,0 +1,21 @@ +# validations yaml specification + + Code + build_bslib_(template = list(theme = 1, bootstrap = 5)) + Condition + Error in `bs_theme_rules()`: + ! template.theme must be a string, not the number 1. + i Edit _pkgdown.yml to fix the problem. + Code + build_bslib_(template = list(theme = "fruit", bootstrap = 5)) + Condition + Error in `build_bslib_()`: + ! template.theme uses theme "fruit" + i Edit _pkgdown.yml to fix the problem. + Code + build_bslib_(template = list(`theme-dark` = "fruit", bootstrap = 5)) + Condition + Error in `build_bslib_()`: + ! template.theme-dark uses theme "fruit" + i Edit _pkgdown.yml to fix the problem. + diff --git a/tests/testthat/test-theme.R b/tests/testthat/test-theme.R new file mode 100644 index 000000000..408560ef2 --- /dev/null +++ b/tests/testthat/test-theme.R @@ -0,0 +1,12 @@ +test_that("validations yaml specification", { + build_bslib_ <- function(...) { + pkg <- local_pkgdown_site(meta = list(...)) + build_bslib(pkg) + } + + expect_snapshot(error = TRUE, { + build_bslib_(template = list(theme = 1, bootstrap = 5)) + build_bslib_(template = list(theme = "fruit", bootstrap = 5)) + build_bslib_(template = list(`theme-dark` = "fruit", bootstrap = 5)) + }) +})