Skip to content

Commit

Permalink
No longer need the check_path hack as this approach will not requir…
Browse files Browse the repository at this point in the history
…e testing different `_pkgdown.yml` error messages.
  • Loading branch information
olivroy committed May 19, 2024
1 parent 04067b9 commit 4661e5b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
9 changes: 2 additions & 7 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,8 @@ pkgdown_config_path <- function(path) {
)
}

read_meta <- function(path, check_path = TRUE, call = caller_env()) {
if (check_path) {
# check_path = FALSE can be used to supply a direct path to
# read_meta instead of a pkgdown object.
path <- pkgdown_config_path(path)
}

read_meta <- function(path, call = caller_env()) {
path <- pkgdown_config_path(path)
if (is.null(path)) {
yaml <- list()
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# read_meta() errors gracefully if _pkgdown.yml failed to parse

Code
read_meta(file, check_path = FALSE)
as_pkgdown(test_path("assets/bad-yaml"))
Condition
Error:
Error in `as_pkgdown()`:
x Could not parse the config file.
! Parser error: while parsing a block mapping at line 1, column 1 did not find expected key at line 9, column 3
i Edit 'assets/bad-yaml/_pkgdown.yml' to fix the problem.
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/assets/bad-yaml/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Package: kittens
Version: 1.0.0
Title: A test package
Description: A longer statement about the package.
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
person("RStudio", role = c("cph", "fnd"))
)
RoxygenNote: 6.0.1
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
6 changes: 1 addition & 5 deletions tests/testthat/test-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ test_that("titles don't get autolinked code", {
})

test_that("read_meta() errors gracefully if _pkgdown.yml failed to parse", {
file <- test_path("assets", "bad-yaml", "_pkgdown.yml")
expect_snapshot(
error = TRUE,
read_meta(
file,
check_path = FALSE
)
as_pkgdown(test_path("assets/bad-yaml"))
)
})

0 comments on commit 4661e5b

Please sign in to comment.