Skip to content

Commit

Permalink
Tweak other messages + call + put slow tests first
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Mar 15, 2024
1 parent 26842c7 commit 0d691c8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Config/Needs/website: usethis, servr
Config/potools/style: explicit
Config/testthat/edition: 3
Config/testthat/parallel: true
Config/testthat/start-first: build-articles, build-reference
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Expand Down
15 changes: 9 additions & 6 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data_home <- function(pkg = ".") {
}


data_home_sidebar <- function(pkg = ".") {
data_home_sidebar <- function(pkg = ".", call = caller_env()) {

pkg <- as_pkgdown(pkg)
if (isFALSE(pkg$meta$home$sidebar))
Expand All @@ -75,7 +75,7 @@ data_home_sidebar <- function(pkg = ".") {
"Can't locate {.file {rel_html_path}}.",
x = paste0(msg_fld, " is misconfigured.")
),
call = caller_env()
call = call
)


Expand Down Expand Up @@ -114,15 +114,17 @@ data_home_sidebar <- function(pkg = ".") {
components,
names(components),
data_home_component,
pkg = pkg
pkg = pkg,
call = call
) %>%
set_names(names(components))
)

check_yaml_has(
setdiff(sidebar_structure, names(sidebar_components)),
where = c("home", "sidebar", "components"),
pkg = pkg
pkg = pkg,
call = call
)

sidebar_final_components <- purrr::compact(
Expand All @@ -138,12 +140,13 @@ default_sidebar_structure <- function() {
c("links", "license", "community", "citation", "authors", "dev")
}

data_home_component <- function(component, component_name, pkg) {
data_home_component <- function(component, component_name, pkg, call = caller_env()) {

check_yaml_has(
setdiff(c("title", "text"), names(component)),
where = c("home", "sidebar", "components", component_name),
pkg = pkg
pkg = pkg,
call = call
)

sidebar_section(
Expand Down
12 changes: 7 additions & 5 deletions R/utils-yaml.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
check_yaml_has <- function(missing, where, pkg) {
check_yaml_has <- function(missing, where, pkg, call = caller_env()) {
if (length(missing) == 0) {
return()
}

missing_components <- lapply(missing, function(x) c(where, x))
msg_flds <- pkgdown_field(pkg, missing_components, fmt = TRUE, cfg = TRUE)
msg_flds <- pkgdown_field(pkg, missing_components, fmt = FALSE, cfg = FALSE)

cli::cli_abort(
paste0("Can't find {cli::qty(missing)} component{?s} ", msg_flds, "."),
call = caller_env()
cli::cli_abort(c(
"Can't find {cli::qty(missing)} component{?s} {.field {msg_flds}}.",
i = "Edit {pkgdown_config_href({pkg$src_path})} to define {cli::qty(missing)} {?it/them}."
),
call = call
)
}

Expand Down
22 changes: 12 additions & 10 deletions tests/testthat/_snaps/build-home-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@
Code
data_home_sidebar(pkg)
Condition
Error in `data_home_sidebar()`:
! Can't find component home.sidebar.components.fancy in _pkgdown.yml.
Error:
! Can't find component home.sidebar.components.fancy.
i Edit _pkgdown.yml to define it.

---

Code
data_home_sidebar(pkg)
Condition
Error in `data_home_sidebar()`:
! Can't find components home.sidebar.components.fancy in _pkgdown.yml.
Can't find components home.sidebar.components.cool in _pkgdown.yml.
Error:
! Can't find components home.sidebar.components.fancy and home.sidebar.components.cool.
i Edit _pkgdown.yml to define them.

---

Expand All @@ -94,8 +95,9 @@
Error in `purrr::map2()`:
i In index: 1.
i With name: fancy.
Caused by error in `.f()`:
! Can't find component home.sidebar.components.fancy.title in _pkgdown.yml.
Caused by error:
! Can't find component home.sidebar.components.fancy.title.
i Edit _pkgdown.yml to define it.

---

Expand All @@ -105,7 +107,7 @@
Error in `purrr::map2()`:
i In index: 1.
i With name: fancy.
Caused by error in `.f()`:
! Can't find components home.sidebar.components.fancy.title in _pkgdown.yml.
Can't find components home.sidebar.components.fancy.text in _pkgdown.yml.
Caused by error:
! Can't find components home.sidebar.components.fancy.title and home.sidebar.components.fancy.text.
i Edit _pkgdown.yml to define them.

7 changes: 4 additions & 3 deletions tests/testthat/_snaps/utils-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
check_yaml_has("x", where = "a", pkg = pkg)
Condition
Error:
! Can't find component a.x in _pkgdown.yml.
! Can't find component a.x.
i Edit _pkgdown.yml to define it.
Code
check_yaml_has(c("x", "y"), where = "a", pkg = pkg)
Condition
Error:
! Can't find components a.x in _pkgdown.yml.
Can't find components a.y in _pkgdown.yml.
! Can't find components a.x and a.y.
i Edit _pkgdown.yml to define them.

0 comments on commit 0d691c8

Please sign in to comment.