Skip to content

Commit

Permalink
A couple more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 9, 2024
1 parent 6c29b52 commit e05bc0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
27 changes: 18 additions & 9 deletions tests/testthat/_snaps/config.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# config_pluck_character generates informative error

Code
config_pluck_character(pkg, "x")
Condition
Error:
! x must be a character vector, not the number 1.
i Edit _pkgdown.yml to fix the problem.

# config_pluck_string generates informative error

Code
config_pluck_string(pkg, "x")
Condition
Error:
! x must be a string, not the number 1.
i Edit _pkgdown.yml to fix the problem.

# config_check_list gives informative errors

Code
Expand All @@ -14,12 +32,3 @@
1 missing component: "z".
i Edit _pkgdown.yml to fix the problem.

# config_pluck_character generates informative error

Code
config_pluck_character(pkg, "x")
Condition
Error:
! x must be a character vector, not the number 1.
i Edit _pkgdown.yml to fix the problem.

8 changes: 7 additions & 1 deletion tests/testthat/test-config.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@

test_that("config_pluck_character coerces empty values to character", {
pkg <- local_pkgdown_site(meta = list(x = NULL))
pkg <- local_pkgdown_site(meta = list(x = NULL, y = list()))
expect_equal(config_pluck_character(pkg, "x"), character())
expect_equal(config_pluck_character(pkg, "y"), character())
expect_equal(config_pluck_character(pkg, "z"), character())
})

test_that("config_pluck_character generates informative error", {
pkg <- local_pkgdown_site(meta = list(x = 1))
expect_snapshot(config_pluck_character(pkg, "x"), error = TRUE)
})

test_that("config_pluck_string generates informative error", {
pkg <- local_pkgdown_site(meta = list(x = 1))
expect_snapshot(config_pluck_string(pkg, "x"), error = TRUE)
})

# checkers --------------------------------------------------------------------

test_that("config_check_list() returns list if ok", {
Expand Down

0 comments on commit e05bc0d

Please sign in to comment.