From 69df4a282ddfb52aedea695c1a8a4bfc7aa17358 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sat, 25 Nov 2023 19:57:51 -0700 Subject: [PATCH 01/20] Use cli functions Part of #2116 --- R/build-articles.R | 17 ++-- R/build-favicons.R | 34 ++++--- R/build-github.R | 4 +- R/build-home-authors.R | 2 +- R/build-home-index.R | 16 ++-- R/build-home-md.R | 2 +- R/build-home.R | 2 +- R/build-news.R | 10 +- R/build-redirects.R | 6 +- R/build-reference.R | 6 +- R/build-search-docs.R | 4 +- R/build-tutorials.R | 2 +- R/build.R | 13 +-- R/check.R | 2 +- R/clean.R | 1 + R/deploy-site.R | 31 ++++--- R/figure.R | 6 +- R/init.R | 4 +- R/markdown.R | 8 +- R/package.R | 20 ++-- R/preview.R | 2 +- R/rd-example.R | 29 +++--- R/rd-html.R | 15 +-- R/render.R | 46 ++++------ R/rmarkdown.R | 12 +-- R/sitrep.R | 6 +- R/templates.R | 4 +- R/test.R | 6 +- R/theme.R | 10 +- R/topics-external.R | 3 +- R/topics.R | 18 ++-- R/usage.R | 12 ++- R/utils-fs.R | 10 +- R/utils-yaml.R | 10 +- R/utils.R | 35 ++----- man/test-dont.Rd | 2 +- man/test-output-styles.Rd | 4 +- tests/testthat/_snaps/build-articles.md | 12 ++- tests/testthat/_snaps/build-favicons.new.md | 9 ++ .../testthat/_snaps/build-home-authors.new.md | 27 ++++++ tests/testthat/_snaps/build-home-index.new.md | 92 +++++++++++++++++++ tests/testthat/_snaps/build-home.new.md | 15 +++ tests/testthat/_snaps/check.new.md | 25 +++++ 43 files changed, 365 insertions(+), 229 deletions(-) create mode 100644 tests/testthat/_snaps/build-favicons.new.md create mode 100644 tests/testthat/_snaps/build-home-authors.new.md create mode 100644 tests/testthat/_snaps/build-home-index.new.md create mode 100644 tests/testthat/_snaps/build-home.new.md create mode 100644 tests/testthat/_snaps/check.new.md diff --git a/R/build-articles.R b/R/build-articles.R index 32c60612d..b0e6240e4 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -177,7 +177,7 @@ build_articles <- function(pkg = ".", return(invisible()) } - rule("Building articles") + cli::cli_h2("Building articles") build_articles_index(pkg) purrr::walk( @@ -207,7 +207,7 @@ build_article <- function(name, # allow code sharing with building of the index. vig <- match(name, pkg$vignettes$name) if (is.na(vig)) { - stop("Can't find article called ", src_path(name), call. = FALSE) + cli::cli_abort("Can't find article {ui_path(name)}") } input <- pkg$vignettes$file_in[vig] @@ -368,12 +368,8 @@ data_articles_index <- function(pkg = ".") { missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package)) if (length(missing) > 0) { - abort( - paste0( - "Vignettes missing from index: ", - paste(missing, collapse = ", ") - ), - call. = FALSE + cli::cli_abort( + "Vignette{?s} missing from index: {missing}" ) } @@ -385,7 +381,9 @@ data_articles_index <- function(pkg = ".") { data_articles_index_section <- function(section, pkg) { if (!set_contains(names(section), c("title", "contents"))) { - abort("Section must have components `title`, `contents`") + cli::cli_abort( + "Section must have components {.field title, contents}" + ) } # Match topics against any aliases @@ -424,7 +422,6 @@ default_articles_index <- function(pkg = ".") { return(NULL) } - print_yaml(list( list( title = tr_("All vignettes"), diff --git a/R/build-favicons.R b/R/build-favicons.R index f1e9fda82..3245b3e9d 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -19,20 +19,23 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { rlang::check_installed("openssl") pkg <- as_pkgdown(pkg) - rule("Building favicons") + cli::cli_rule("Building favicons") logo_path <- find_logo(pkg$src_path) if (is.null(logo_path)) { - stop("Can't find package logo PNG or SVG to build favicons.", call. = FALSE) + cli::cli_abort("Can't find package logo PNG or SVG to build favicons.") } if (has_favicons(pkg) && !overwrite) { - message("Favicons already exist in `pkgdown/`. Set `overwrite = TRUE` to re-create.") + cli::cli_inform(c( + "Favicons already exist in {.path pkgdown}", + "i" = "Set {.var overwrite = TRUE} to re-create." + )) return(invisible()) } - message("Building favicons with realfavicongenerator.net...") + cli::cli_inform("Building favicons with {.url https://realfavicongenerator.net} ...") logo <- readBin(logo_path, what = "raw", n = fs::file_info(logo_path)$size) @@ -66,17 +69,18 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { quiet = TRUE ) if (httr::http_error(resp)) { - stop("API request failed.", call. = FALSE) + cli::cli_abort("API request failed.") } content <- httr::content(resp) result <- content$favicon_generation_result if (!identical(result$result$status, "success")) { - stop( - "API request failed. ", " - Please submit bug report to ", - call. = FALSE + cli::cli_abort( + c( + "API request failed.", + "i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}" + ) ) } @@ -93,10 +97,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { utils::unzip(tmp, exdir = path(pkg$src_path, "pkgdown", "favicon")) }, warning = function(e) { - abort("Your logo file couldn't be processed and may be corrupt.", parent = e) + cli::cli_abort("Your logo file couldn't be processed and may be corrupt.") }, error = function(e) { - abort("Your logo file couldn't be processed and may be corrupt.", parent = e) + cli::cli_abort("Your logo file couldn't be processed and may be corrupt.") }) invisible() @@ -107,10 +111,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { #' @inheritParams build_favicons #' @export build_favicon <- function(pkg, overwrite) { - message( - "`build_favicon()` is deprecated as of pkgdown 1.4.0. ", - "Please use `build_favicons()` instead." - ) + cli::cli_warn(c( + "{.fun build_favicon} is deprecated as of pkgdown 1.4.0. ", + "i" = "Please use {.fun build_favicons} instead." + )) build_favicons(pkg, overwrite) } diff --git a/R/build-github.R b/R/build-github.R index 1aff9055a..76111e896 100644 --- a/R/build-github.R +++ b/R/build-github.R @@ -25,7 +25,7 @@ build_site_github_pages <- function(pkg = ".", pkg <- as_pkgdown(pkg, override = list(destination = dest_dir)) if (clean) { - rule("Cleaning files from old site", line = 1) + cli::cli_rule("Cleaning files from old site") clean_site(pkg) } @@ -36,7 +36,7 @@ build_site_github_pages <- function(pkg = ".", } build_github_pages <- function(pkg = ".") { - rule("Extra files for GitHub pages") + cli::cli_rule("Extra files for GitHub pages") pkg <- as_pkgdown(pkg) # Add .nojekyll since site is static HTML diff --git a/R/build-home-authors.R b/R/build-home-authors.R index dd1763ad9..79fbdf72e 100644 --- a/R/build-home-authors.R +++ b/R/build-home-authors.R @@ -187,7 +187,7 @@ role_lookup <- function(abbr) { out <- unname(roles[abbr]) if (any(is.na(out))) { missing <- paste0("'", abbr[is.na(out)], "'", collapse = ", ") - warn(paste0("Unknown MARC role abbreviation ", missing)) + cli::cli_alert_warning("Unknown MARC role abbreviation{?s}: {missing}") out[is.na(out)] <- abbr[is.na(out)] } out diff --git a/R/build-home-index.R b/R/build-home-index.R index 3c39aca2a..d98249a30 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -64,12 +64,8 @@ data_home_sidebar <- function(pkg = ".") { if (length(html_path)) { if (!file.exists(html_path)) { - abort( - sprintf( - "Can't find file '%s' specified by %s.", - pkg$meta$home$sidebar$html, - pkgdown_field(pkg, c("home", "sidebar", "html")) - ) + cli::cli_abort( + "Can't find file {.file {html_path}} specified by {pkgdown_field(pkg, c('home', 'sidebar', 'html'))}" ) } return(read_file(html_path)) @@ -215,10 +211,10 @@ check_missing_images <- function(pkg, src_path, dst_path) { exists <- fs::file_exists(path(pkg$dst_path, rel_path)) if (any(!exists)) { - paths <- encodeString(rel_src[!exists], quote = "'") - warn(c( - paste0("Missing images in '", src_path, "': ", paste0(paths, collapse = ", ")), - i = "pkgdown can only use images in 'man/figures' and 'vignettes'" + paths <- rel_src[!exists] + cli::cli_warn(c( + "Missing images in {.file {src_path}}: {.file {paths}}", + "i" = "pkgdown can only use images in {.file man/figures} and {.file vignettes}" )) } } diff --git a/R/build-home-md.R b/R/build-home-md.R index 38c9d461e..04e9a60b0 100644 --- a/R/build-home-md.R +++ b/R/build-home-md.R @@ -22,7 +22,7 @@ build_home_md <- function(pkg) { } render_md <- function(pkg, filename) { - cat_line("Reading ", src_path(path_rel(filename, pkg$src_path))) + cli::cli_alert_info("Reading {src_path(path_rel(filename, pkg$src_path))}") body <- markdown_body(filename, strip_header = TRUE) path <- path_ext_set(basename(filename), "html") diff --git a/R/build-home.R b/R/build-home.R index c987490e9..e287bc929 100644 --- a/R/build-home.R +++ b/R/build-home.R @@ -31,7 +31,7 @@ build_home <- function(pkg = ".", quiet = TRUE) { pkg <- section_init(pkg, depth = 0L, override = override) - rule("Building home") + cli::cli_h2("Building home") dir_create(pkg$dst_path) build_citation_authors(pkg) diff --git a/R/build-news.R b/R/build-news.R index 27a0fac7a..614b0929c 100644 --- a/R/build-news.R +++ b/R/build-news.R @@ -78,7 +78,7 @@ build_news <- function(pkg = ".", if (!has_news(pkg$src_path)) return() - rule("Building news") + cli::cli_h2("Building news") dir_create(path(pkg$dst_path, "news")) switch(news_style(pkg$meta), @@ -151,7 +151,7 @@ data_news <- function(pkg = list()) { sections <- xml2::xml_find_all(xml, "./body/div") footnotes <- has_class(sections, "footnotes") if (any(footnotes)) { - warn("Footnotes in NEWS.md are not currently supported") + cli::cli_warn("Footnotes in NEWS.md are not currently supported") } sections <- sections[!footnotes] @@ -160,10 +160,10 @@ data_news <- function(pkg = list()) { xml2::xml_name() ulevels <- unique(levels) if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) { - abort(c( + cli::cli_abort(c( "Invalid NEWS.md: inconsistent use of section headings.", - i = "Top-level headings must be either all

or all

.", - i = "See ?build_news for more details." + "i" = "Top-level headings must be either all

or all

.", + "i" = "See {.help pkgdown::build_news} for more details." )) } if (ulevels == "h1") { diff --git a/R/build-redirects.R b/R/build-redirects.R index 408ff09f0..f8e15f582 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -11,9 +11,9 @@ build_redirects <- function(pkg = ".", return(invisible()) } - rule("Building redirects") + cli::cli_h2("Building redirects") if (is.null(pkg$meta$url)) { - abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url"))) + cli::cli_abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url"))) } purrr::iwalk( @@ -25,7 +25,7 @@ build_redirects <- function(pkg = ".", build_redirect <- function(entry, index, pkg) { if (!is.character(entry) || length(entry) != 2) { - abort( + cli::cli_abort( sprintf( "Entry %s in %s must be a character vector of length 2.", index, diff --git a/R/build-reference.R b/R/build-reference.R index add462c13..d6aa69d8e 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -162,11 +162,11 @@ build_reference <- function(pkg = ".", pkg <- section_init(pkg, depth = 1L, override = override) if (!missing(document)) { - warning("`document` is deprecated. Please use `devel` instead.", call. = FALSE) + cli::cli_warn("{.var document}is deprecated. Please use {.var devel} instead.") devel <- document } - rule("Building function reference") + cli::cli_h2("Building function reference") build_reference_index(pkg) copy_figures(pkg) @@ -274,7 +274,7 @@ build_reference_topic <- function(topic, if (lazy && !out_of_date(in_path, out_path)) return(invisible()) - cat_line("Reading ", src_path("man", topic$file_in)) + cli::cli_alert_info("Reading {src_path(path('man', topic$file_in))}") data <- withCallingHandlers( data_reference_topic( diff --git a/R/build-search-docs.R b/R/build-search-docs.R index cb61ed127..6dab99c40 100644 --- a/R/build-search-docs.R +++ b/R/build-search-docs.R @@ -45,7 +45,7 @@ build_sitemap <- function(pkg = ".") { } xml_path <- path(pkg$dst_path, "sitemap.xml") - cat_line("Writing ", dst_path(path_rel(xml_path, pkg$dst_path))) + cli::cli_alert_info("Writing {dst_path(path_rel(xml_path, pkg$dst_path))}") xml2::write_xml(doc, file = xml_path) @@ -86,7 +86,7 @@ url_node <- function(url) { build_search <- function(pkg = ".", override = list()) { pkg <- section_init(pkg, depth = 1L, override = override) - rule("Building search index") + cli::cli_alert("Building search index") search_index <- build_search_index(pkg) jsonlite::write_json( search_index, diff --git a/R/build-tutorials.R b/R/build-tutorials.R index 8138c23cd..caeacdfaf 100644 --- a/R/build-tutorials.R +++ b/R/build-tutorials.R @@ -35,7 +35,7 @@ build_tutorials <- function(pkg = ".", override = list(), preview = NA) { return(invisible()) } - rule("Building tutorials") + cli::cli_h2("Building tutorials") dir_create(path(pkg$dst_path, "tutorials")) data <- purrr::transpose(tutorials) diff --git a/R/build.R b/R/build.R index a44a0a99a..188c3afc7 100644 --- a/R/build.R +++ b/R/build.R @@ -328,13 +328,13 @@ build_site <- function(pkg = ".", pkg <- as_pkgdown(pkg, override = override) if (!missing(document)) { - warning("`document` is deprecated. Please use `devel` instead.", call. = FALSE) + cli::cli_warn("{.var document} is deprecated. Please use {.var devel} instead.") devel <- document } if (install) { withr::local_temp_libpaths() - rule("Installing package into temporary library") + cli::cli_h2("Installing package {.pkg {pkg$package}} into temporary library") # Keep source, so that e.g. pillar can show the source code # of its functions in its articles withr::with_options( @@ -404,6 +404,7 @@ build_site_external <- function(pkg = ".", timeout = getOption('pkgdown.timeout', Inf) ) + cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.") preview_site(pkg, preview = preview) invisible() } @@ -420,9 +421,9 @@ build_site_local <- function(pkg = ".", pkg <- section_init(pkg, depth = 0, override = override) - rule("Building pkgdown site", line = "=") - cat_line("Reading from: ", src_path(path_abs(pkg$src_path))) - cat_line("Writing to: ", dst_path(path_abs(pkg$dst_path))) + cli::cli_h1("Building pkgdown site for {.pkg {pkg$package}}") + cli::cli_alert("Reading from: {src_path(path_abs(pkg$src_path))}") + cli::cli_alert("Writing to: {dst_path(path_abs(pkg$dst_path))}") init_site(pkg) @@ -447,6 +448,6 @@ build_site_local <- function(pkg = ".", build_search(pkg, override = override) } - rule("DONE", line = "=") + cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.") preview_site(pkg, preview = preview) } diff --git a/R/check.R b/R/check.R index 0cfb38a05..92334b69b 100644 --- a/R/check.R +++ b/R/check.R @@ -12,6 +12,6 @@ check_pkgdown <- function(pkg = ".") { data_articles_index(pkg) data_reference_index(pkg) - inform("No problems found") + cli::cli_alert_success("No problems found in {.file _pkgdown.yml}") } diff --git a/R/clean.R b/R/clean.R index d70d02ad9..19f15dd7c 100644 --- a/R/clean.R +++ b/R/clean.R @@ -16,5 +16,6 @@ clean_site <- function(pkg = ".") { dir_delete(top_level[is_dir]) file_delete(top_level[!is_dir]) + cli::cli_alert_success("Site cleaned for {.pkg {pkg$package}} (emptied {.path {pkg$dst_path}})") invisible(TRUE) } diff --git a/R/deploy-site.R b/R/deploy-site.R index fab5d892c..266c7cad0 100644 --- a/R/deploy-site.R +++ b/R/deploy-site.R @@ -43,31 +43,31 @@ deploy_site_github <- function( repo_slug = Sys.getenv("TRAVIS_REPO_SLUG", "")) { rlang::check_installed("openssl") if (!nzchar(tarball)) { - stop("No built tarball detected, please provide the location of one with `tarball`", call. = FALSE) + cli::cli_abort("No built tarball detected, please provide the location of one with {.var tarball}") } if (!nzchar(ssh_id)) { - stop("No deploy key found, please setup with `travis::use_travis_deploy()`", call. = FALSE) + cli::cli_abort("No deploy key found, please setup with {.fn travis::use_travis_deploy}") } if (!nzchar(repo_slug)) { - stop("No repo detected, please supply one with `repo_slug`", call. = FALSE) + cli::cli_abort("No repo detected, please supply one with {.var repo_slug}") } - rule("Deploying site", line = 2) + cli::cli_rule("Deploying site to GitHub") if (install) { - rule("Installing package", line = 1) + cli::cli_inform("Installing package") callr::rcmd("INSTALL", tarball, show = verbose, fail_on_status = TRUE) } ssh_id_file <- "~/.ssh/id_rsa" - rule("Setting up SSH id", line = 1) - cat_line("Copying private key to: ", ssh_id_file) + cli::cli_alert_info("Setting up SSH id") + cli::cli_alert_info("Copying private key to {.file ssh_id_file}") write_lines(rawToChar(openssl::base64_decode(ssh_id)), ssh_id_file) - cat_line("Setting private key permissions to 0600") + cli::cli_alert_info("Setting private key permissions to 0600") fs::file_chmod(ssh_id_file, "0600") - cat_line("Setting remote to use the ssh url") + cli::cli_alert_info("Setting remote to use the ssh url") git("remote", "set-url", "origin", sprintf("git@%s:%s.git", host, repo_slug)) @@ -79,7 +79,7 @@ deploy_site_github <- function( ... ) - rule("Deploy completed", line = 2) + cli::cli_alert_success("Deploy completed") } #' Build and deploy a site locally @@ -158,13 +158,14 @@ deploy_to_branch <- function(pkg = ".", git_has_remote_branch <- function(remote, branch) { has_remote_branch <- git("ls-remote", "--quiet", "--exit-code", remote, branch, echo = FALSE, echo_cmd = FALSE, error_on_status = FALSE)$status == 0 } + git_current_branch <- function() { branch <- git("rev-parse", "--abbrev-ref", "HEAD", echo = FALSE, echo_cmd = FALSE)$stdout sub("\n$", "", branch) } github_worktree_add <- function(dir, remote, branch) { - rule("Adding worktree", line = 1) + cli::cli_alert_info("Adding worktree") git("worktree", "add", "--track", "-B", branch, @@ -174,7 +175,7 @@ github_worktree_add <- function(dir, remote, branch) { } github_worktree_remove <- function(dir) { - rule("Removing worktree", line = 1) + cli::cli_alert_info("Removing worktree") git("worktree", "remove", dir) } @@ -182,13 +183,13 @@ github_push <- function(dir, commit_message, remote, branch) { # force execution before changing working directory force(commit_message) - rule("Commiting updated site", line = 1) + cli::cli_alert_info("Commiting updated site") withr::with_dir(dir, { git("add", "-A", ".") git("commit", "--allow-empty", "-m", commit_message) - rule("Deploying to GitHub Pages", line = 1) + cli::cli_alert("Deploying to GitHub Pages") git("remote", "-v") git("push", "--force", remote, paste0("HEAD:", branch)) }) @@ -201,7 +202,7 @@ git <- function(..., echo_cmd = TRUE, echo = TRUE, error_on_status = TRUE) { construct_commit_message <- function(pkg, commit = ci_commit_sha()) { pkg <- as_pkgdown(pkg) - sprintf("Built site for %s: %s@%s", pkg$package, pkg$version, substr(commit, 1, 7)) + cli::cli_alert_success(sprintf("Built site for %s: %s@%s", pkg$package, pkg$version, substr(commit, 1, 7))) } ci_commit_sha <- function() { diff --git a/R/figure.R b/R/figure.R index 280ae73a4..f55ae4e32 100644 --- a/R/figure.R +++ b/R/figure.R @@ -136,12 +136,12 @@ match_fun <- function(x) { f <- eval(e, globalenv()) if (!is.function(f)) { - stop("`x` must evaluate to a function", call. = FALSE) + cli::cli_abort("{.var x} must evaluate to a function") } f } else { - stop("`x` must be a function or string", call. = FALSE) + cli::cli_abort("{.var x} must be a function or string") } } @@ -157,6 +157,6 @@ fun_name <- function(x) { } else if (is_call(expr, "::")) { as.character(expr[[3]]) } else { - stop("Unknown input", call. = FALSE) + cli::cli_abort("Unknown input") } } diff --git a/R/init.R b/R/init.R index bff37086a..eb411975d 100644 --- a/R/init.R +++ b/R/init.R @@ -24,10 +24,10 @@ init_site <- function(pkg = ".") { pkg <- as_pkgdown(pkg) if (is_non_pkgdown_site(pkg$dst_path)) { - stop(dst_path(pkg$dst_path), " is non-empty and not built by pkgdown", call. = FALSE) + cli::cli_abort("{.file {pkg$dst_path}} is non-empty and not built by pkgdown") } - rule("Initialising site") + cli::cli_h2("Initialising site") dir_create(pkg$dst_path) copy_assets(pkg) diff --git a/R/markdown.R b/R/markdown.R index c0ce0b7dd..2c8189a9e 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -16,12 +16,8 @@ markdown_text_inline <- function(text, where = "", ...) { children <- xml2::xml_children(xml2::xml_find_first(html, ".//body")) if (length(children) > 1) { - abort( - sprintf( - "Can't use a block element in %s, need an inline element: \n%s", - where, - text - ) + cli::cli_abort( + "Can't use a block element in {.var {where}}, need an inline element: {.var {text}}", ) } diff --git a/R/package.R b/R/package.R index 82c9c83f6..0f06e3401 100644 --- a/R/package.R +++ b/R/package.R @@ -13,7 +13,7 @@ as_pkgdown <- function(pkg = ".", override = list()) { } if (!dir_exists(pkg)) { - stop("`pkg` is not an existing directory", call. = FALSE) + cli::cli_abort("{.file {pkg}} is not an existing directory") } desc <- read_desc(pkg) @@ -89,7 +89,7 @@ is_pkgdown <- function(x) inherits(x, "pkgdown") read_desc <- function(path = ".") { path <- path(path, "DESCRIPTION") if (!file_exists(path)) { - stop("Can't find DESCRIPTION", call. = FALSE) + cli::cli_abort("Can't find {.file DESCRIPTION}") } desc::description$new(path) } @@ -100,16 +100,13 @@ check_bootstrap_version <- function(version, pkg = list()) { } else if (version %in% c(3, 5)) { version } else if (version == 4) { - warn("`bootstrap: 4` no longer supported; using `bootstrap: 5` instead") + cli::cli_warn("{.var bootstrap: 4} no longer supported, using {.var bootstrap: 5} instead") 5 } else { - abort(c( + field <- pkgdown_field(pkg, c("template", "bootstrap")) + cli::cli_abort(c( "Boostrap version must be 3 or 5.", - x = sprintf( - "You specified a value of %s in %s.", - version, - pkgdown_field(pkg, c("template", "bootstrap")) - ) + "x" = "You specified a value of {.var {version}} in {.var {field}}" )) } } @@ -290,12 +287,11 @@ check_unique_article_paths <- function(file_in, file_out) { same_out_bullets <- purrr::map_chr(file_out_dup, function(f_out) { src_files <- src_path(file_in[which(file_out == f_out)]) src_files <- paste(src_files, collapse = " and ") - sprintf("%s both create %s", src_files, dst_path(f_out)) }) names(same_out_bullets) <- rep_len("x", length(same_out_bullets)) - rlang::abort(c( - "Rendered articles must have unique names. Rename or relocate one of the following source files:", + cli::cli_abort(c( + "Rendered articles must have unique names. Rename or relocate:", same_out_bullets )) } diff --git a/R/preview.R b/R/preview.R index 7129d5ce4..f4e7fc9d6 100644 --- a/R/preview.R +++ b/R/preview.R @@ -11,7 +11,7 @@ preview_site <- function(pkg = ".", path = ".", preview = NA) { } if (preview) { - rule("Previewing site") + cli::cli_alert("Previewing site") utils::browseURL(path(pkg$dst_path, path, "index.html")) } diff --git a/R/rd-example.R b/R/rd-example.R index e1fd10a7a..d3f1e8566 100644 --- a/R/rd-example.R +++ b/R/rd-example.R @@ -29,7 +29,7 @@ run_examples <- function(x, code <- flatten_ex(x, run_dont_run = run_dont_run) if (!can_parse(code)) { - warning("Failed to parse example for topic '", topic, "'", call. = FALSE) + cli::cli_warn("Failed to parse example for topic {.var {topic}}") return("") } @@ -48,13 +48,13 @@ process_conditional_examples <- function(rd) { grepl("# examplesIf$", x[[1]]) })) if (length(which_exif) == 0) return(rd) - if (length(which_exif) %% 2 != 0) stop("@examplesIf error, not closed?") + if (length(which_exif) %% 2 != 0) cli::cli_abort("@examplesIf error, not closed?") remove <- integer() modes <- c("begin", "end") for (idx in which_exif) { if (rd[[idx]] != "}) # examplesIf") { # Start of @examplesIf - if (modes[1] == "end") stop("@examplesIf error, not closed?") + if (modes[1] == "end") cli::cli_abort("@examplesIf error, not closed?") cond_expr <- parse(text = paste0(rd[[idx]], "\n})"))[[1]][[2]] cond <- eval(cond_expr) if (isTRUE(cond)) { @@ -64,10 +64,8 @@ process_conditional_examples <- function(rd) { is_false <- cond_expr_str == "FALSE" if (!is_false) { new_cond <- paste0("if (FALSE) { # ", cond_expr_str) - warning( - "@examplesIf condition `", - cond_expr_str, - "` is FALSE" + cli::cli_warn( + "@examplesIf condition {.var cond_expr_str} FALSE" ) } else { new_cond <- "if (FALSE) {" @@ -76,7 +74,7 @@ process_conditional_examples <- function(rd) { } } else { # End of @examplesIf - if (modes[1] == "begin") stop("@examplesIf error, closed twice?") + if (modes[1] == "begin") cli::cli_abort("@examplesIf error, closed twice?") if (isTRUE(cond)) { remove <- c(remove, idx, idx + 1L) } else { @@ -110,11 +108,12 @@ as_example.TEXT <- as_example.RCODE #' @export as_example.COMMENT <- function(x, run_dont_run = FALSE) { if (grepl("^%[^ ]*%", x)) { - warning( - "In the examples, ", unclass(x), "\n", - "is an Rd comment: did you mean ", gsub("%", "\\\\%", x), " ?", - call. = FALSE - ) + meant <- gsub("%", "\\\\%", x) + xun <- unclass(x) + cli::cli_warn(c( + "In the examples, {.var {xun}} is an Rd comment", + "x" = "did you mean {.var {meant}}?" + )) } "" } @@ -155,8 +154,8 @@ block_tag_to_comment <- function(tag, x, run_dont_run = FALSE) { #' @export as_example.tag <- function(x, run_dont_run = FALSE) { - warning("Unknown tag: ", paste(class(x), collapse = "/"), call. = FALSE) - "" + untag <- paste(class(x), collapse = "/") + cli::cli_warn("Unknown tag: {.var {untag}}") } #' @export diff --git a/R/rd-html.R b/R/rd-html.R index 6e00c3b93..03a404c67 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -229,7 +229,7 @@ as_html.tag_Sexpr <- function(x, ...) { text = as.character(res), rd = flatten_text(rd_text(as.character(res))), hide = "", - stop("\\Sexpr{result=", results, "} not yet supported", call. = FALSE) + cli::cli_abort("\\Sexpr{result=", results, "} not yet supported", call. = FALSE) ) } @@ -510,8 +510,7 @@ as_html.tag <- function(x, ...) { if (identical(class(x), "tag")) { flatten_text(x, ...) } else { - message("Unknown tag: ", paste(class(x), collapse = "/")) - "" + cli::cli_inform("Unknown tag: ", paste(class(x), collapse = "/")) } } @@ -566,10 +565,12 @@ parse_opts <- function(string) { } stop_bad_tag <- function(tag, msg = NULL) { - abort(c( - paste0("Failed to parse \\", tag, "{}."), - i = msg - )) + bad_tag <- paste0("\\\\", tag, "{}") + msg_abort <- 'Failed to parse tag {.var {bad_tag}}.' + if (!is.null(msg)) { + msg_abort <- c(msg_abort, "x" = msg) + } + cli::cli_abort(msg_abort) } is_newline <- function(x, trim = FALSE) { diff --git a/R/render.R b/R/render.R index fefb96988..c01e44bdc 100644 --- a/R/render.R +++ b/R/render.R @@ -148,47 +148,41 @@ data_open_graph <- function(pkg = ".") { check_open_graph <- function(og) { if (!is.list(og)) { - abort(paste("`opengraph` must be a list, not", friendly_type_of(og))) + fog <- friendly_type_of(og) + cli::cli_abort("{.var opengraph} must be a list, not {.var fog}") } supported_fields <- c("image", "twitter") unsupported_fields <- setdiff(names(og), supported_fields) if (length(unsupported_fields)) { - warn(paste0( - "Unsupported `opengraph` field(s): ", - paste(unsupported_fields, collapse = ", ") - )) + cli::cli_warn( + "Unsupported `opengraph` field{?s}: {unsupported_fields}." + ) } if ("twitter" %in% names(og)) { if (is.character(og$twitter) && length(og$twitter) == 1 && grepl("^@", og$twitter)) { - abort(paste( - "The `opengraph: twitter` option must be a list. Did you mean this?", - "opengraph:", - " twitter:", - paste(" creator:", og$twitter), - sep = "\n" - )) + cli::cli_abort( + "The `opengraph: twitter` option must be a list." + ) } if (!is.list(og$twitter)) { - abort("The `opengraph: twitter` option must be a list.") + cli::cli_abort("The `opengraph: twitter` option must be a list.") } if (is.null(og$twitter$creator) && is.null(og$twitter$site)) { - abort( - "The `opengraph: twitter` option must include either 'creator' or 'site'." + cli::cli_abort( + "{.var opengraph: twitter} must include either 'creator' or 'site'." ) } } if ("image" %in% names(og)) { if (is.character(og$image) && length(og$image) == 1) { - abort(paste( - "The `opengraph: image` option must be a list. Did you mean this?", - "opengraph", - " image:", - paste(" src:", og$image), - sep = "\n" - )) + cli::cli_abort( + "The {.var opengraph: image} option must be a list." + ) } if (!is.list(og$image)) { - abort("The `opengraph: image` option must be a list.") + cli::cli_abort( + "The {.var opengraph: image} option must be a list." + ) } } og[intersect(supported_fields, names(og))] @@ -208,7 +202,7 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE) if (check && !made_by_pkgdown(full_path)) { if (!quiet) { - message("Skipping '", path, "': not generated by pkgdown") + cli::cli_inform("Skipping {.file {{path}}: not generated by pkgdown") } return(FALSE) } @@ -221,9 +215,9 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE) } if (!quiet) { - href <- paste0("ide:run:pkgdown::preview_page('", path_rel(full_path, pkg$dst_path), "')") - cat_line("Writing ", cli::style_hyperlink(dst_path(path), href)) + cli::cli_alert_info("Writing {dst_path(path)}") } + write_lines(contents, path = full_path) TRUE } diff --git a/R/rmarkdown.R b/R/rmarkdown.R index f13241862..d2ee63fa0 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -7,10 +7,10 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet output_path <- path_abs(output, pkg$dst_path) if (!file_exists(input_path)) { - stop("Can't find ", src_path(input), call. = FALSE) + cli::cli_abort("Can't find {.file {src_path(input)}") } - cat_line("Reading ", src_path(input)) + cli::cli_alert_info("Reading {src_path(input)}") digest <- file_digest(output_path) args <- list( @@ -38,10 +38,10 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ) ), error = function(cnd) { - rule("RMarkdown error") + cli::cli_rule("RMarkdown error") cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) - rule() - abort("Failed to render RMarkdown", parent = cnd) + cli::cli_rule() + cli::cli_abort("Failed to render RMarkdown") } ) @@ -55,7 +55,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet } if (digest != file_digest(output_path)) { href <- paste0("ide:run:pkgdown::preview_page('", path_rel(output_path, pkg$dst_path), "')") - cat_line("Writing ", cli::style_hyperlink(dst_path(output), href)) + cli::cli_alert_info("Writing {cli::style_hyperlink(dst_path(output), href)}") } # Copy over images needed by the document diff --git a/R/sitrep.R b/R/sitrep.R index ca123c8cd..973d53a16 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -16,14 +16,14 @@ pkgdown_sitrep <- function(pkg = ".") { pkg_dir <- pkg pkg <- as_pkgdown(pkg_dir) if (is.null(pkg$meta[["url"]])) { - cat(sprintf("* %s not configured.", pkgdown_field(pkg, "url"))) + cli::cli_alert_warning(sprintf("%s is not configured.", pkgdown_field(pkg, "url"))) } else { urls <- desc::desc(pkg_dir)$get_urls() urls <- sub("/$", "", urls) if (!pkg$meta[["url"]] %in% urls) { - cat("* URL missing from the DESCRIPTION URL field.") + cli::cli_alert_warning("URL is missing in the DESCRIPTION URL field.") } else { - cat("All good :-)") + cli::cli_alert_success("pkgdown situation report is all clear") } } diff --git a/R/templates.R b/R/templates.R index 02376ff73..0ef590160 100644 --- a/R/templates.R +++ b/R/templates.R @@ -6,7 +6,7 @@ find_template <- function(type, name, ext = ".html", pkg = ".") { existing <- paths[file_exists(paths)] if (length(existing) == 0) { - abort(paste0("Can't find template for ", type, "-", name, ".")) + cli::cli_abort(paste0("Can't find template for ", type, "-", name, ".")) } existing[[1]] } @@ -43,7 +43,7 @@ templates_dir <- function(pkg = list()) { if (!is.null(template$path)) { # Directory specified in yaml doesn't exist, so eagerly error if (!dir_exists(template$path)) { - abort(paste0("Can not find templates path ", src_path(template$path))) + cli::cli_abort("Can't find templates path: {src_path(template$path)}") } path_abs(template$path, start = pkg$src_path) } else if (!is.null(template$package)) { diff --git a/R/test.R b/R/test.R index 800de5117..50a0f19ff 100644 --- a/R/test.R +++ b/R/test.R @@ -89,7 +89,7 @@ NULL #' @family tests #' @examples #' \dontrun{ -#' stop("This is an error!", call. = FALSE) +#' cli::cli_abort("This is an error!") #' } #' #' # Inline \donttest is silently ommitted @@ -149,8 +149,8 @@ NULL #' a #' #' cat("This some text!\n") -#' message("This is a message!") -#' warning("This is a warning!") +#' cli::cli_inform("This is a message!") +#' cli::cli_warn("This is a warning!") #' #' # This is a multi-line block #' { diff --git a/R/theme.R b/R/theme.R index 197180281..a4232cfc9 100644 --- a/R/theme.R +++ b/R/theme.R @@ -12,7 +12,7 @@ build_bslib <- function(pkg = ".") { data_deps <- function(pkg, depth) { if (!file.exists(data_deps_path(pkg))) { - abort("Run pkgdown::init_site() first.") + cli::cli_abort("Run {.fn pkgdown::init_site} first.") } deps_path <- paste0(up_path(depth), "deps") @@ -56,9 +56,9 @@ bs_theme_rules <- function(pkg) { theme <- purrr::pluck(pkg, "meta", "template", "theme", .default = "arrow-light") theme_path <- path_pkgdown("highlight-styles", paste0(theme, ".scss")) if (!file_exists(theme_path)) { - abort(c( - paste0("Unknown theme '", theme, "'"), - i = paste0("Valid themes are: ", paste0(highlight_styles(), collapse = ", ")) + cli::cli_abort(c( + "Unknown theme: {.var {theme}}", + i = "Valid themes are: {highlight_styles()}" )) } paths <- c(paths, theme_path) @@ -101,7 +101,7 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { } else if (bootswatch_theme %in% bslib::bootswatch_themes(bs_version)) { bootswatch_theme } else { - abort( + cli::cli_abort( sprintf( "Can't find Bootswatch theme '%s' (%s) for Bootstrap version '%s' (%s).", bootswatch_theme, diff --git a/R/topics-external.R b/R/topics-external.R index b51091992..312f0afa9 100644 --- a/R/topics-external.R +++ b/R/topics-external.R @@ -29,7 +29,8 @@ get_rd_from_help <- function(package, alias) { help <- utils::help((alias), (package)) if (length(help) == 0) { - abort(sprintf("Could not find documentation for %s::%s", package, alias)) + fun <- paste0(package, "::", alias) + cli::cli_abort("Could not find documentation for {.fn fun}.") return() } diff --git a/R/topics.R b/R/topics.R index e7ffb1a51..cbbe8cd81 100644 --- a/R/topics.R +++ b/R/topics.R @@ -10,7 +10,7 @@ select_topics <- function(match_strings, topics, check = FALSE) { # If none of the specified topics have a match, return no topics if (purrr::every(indexes, is_empty)) { if (check) { - abort("No topics matched in '_pkgdown.yml'. No topics selected.") + cli::cli_abort("No topics matched in '_pkgdown.yml'. No topics selected.") } return(integer()) } @@ -51,7 +51,7 @@ all_sign <- function(x, text) { } } - stop("Must be all negative or all positive: ", text, call. = FALSE) + cli::cli_abort("Must be all negative or all positive: {.var {text}}") } match_env <- function(topics) { @@ -161,7 +161,7 @@ match_eval <- function(string, env) { tryCatch( eval(expr, env), error = function(e) { - topic_must("be a known selector function", string, parent = e) + topic_must("be a known selector function", string) } ) } else { @@ -169,14 +169,12 @@ match_eval <- function(string, env) { } } -topic_must <- function(message, topic, ..., call = NULL) { - abort( +topic_must <- function(message, topic) { + cli::cli_abort( c( - paste0("In '_pkgdown.yml', topic must ", message), - x = paste0("Not ", encodeString(topic, quote = "'")) - ), - ..., - call = call + paste0("In {.file _pkgdown.yml}, topic must ", message), + "x" = paste0("Not {.var {topic}}") + ) ) } diff --git a/R/usage.R b/R/usage.R index bec8fd162..8e9b2488c 100644 --- a/R/usage.R +++ b/R/usage.R @@ -28,7 +28,10 @@ parse_usage <- function(x) { parse_exprs(r) }, error = function(e) { - warning("Failed to parse usage:\n", r, call. = FALSE, immediate. = TRUE) + cli::cli_warn(c( + "Failed to parse usage:", + "x" = "{.var {r}}" + )) list() } ) @@ -83,7 +86,8 @@ usage_type <- function(x) { out } else { - stop("Unknown type: ", typeof(x), " (in ", as.character(x), ")", call. = FALSE) + untype <- paste0(typeof(x), " (in ", as.character(x), ")") + cli::cli_abort("Unknown type: {.var {untype}}") } } @@ -127,7 +131,7 @@ fun_info <- function(fun) { name = call_name(fun) ) } else { - stop("Unknown call: ", as.character(x[[1]])) + cli::cli_abort(paste0("Unknown call: ", as.character(x[[1]]))) } } else { list( @@ -158,7 +162,7 @@ usage_code.NULL <- function(x) character() #' @export usage_code.tag <- function(x) { if (!identical(class(x), "tag")) { - stop("Undefined tag in usage ", class(x)[[1]], call. = FALSE) + cli::cli_abort(paste0("Undefined tag in usage ", class(x)[[1]])) } paste0(purrr::flatten_chr(purrr::map(x, usage_code)), collapse = "") } diff --git a/R/utils-fs.R b/R/utils-fs.R index 05f48890c..f938f1ad8 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -41,10 +41,10 @@ file_copy_to <- function(pkg, eq <- purrr::map2_lgl(from_paths, to_paths, file_equal) if (any(!eq)) { - cat_line( - "Copying ", src_path(path_rel(from_paths[!eq], pkg$src_path)), - " to ", dst_path(path_rel(to_paths[!eq], pkg$dst_path)) - ) + cli::cli_alert_info(c( + "Copying {src_path(path_rel(from_paths[!eq], pkg$src_path))}", + " to {dst_path(path_rel(to_paths[!eq], pkg$dst_path))}" + )) } file_copy(from_paths[!eq], to_paths[!eq], overwrite = overwrite) @@ -55,7 +55,7 @@ out_of_date <- function(source, target) { return(TRUE) if (!file_exists(source)) { - stop("'", source, "' does not exist", call. = FALSE) + cli::cli_abort("{.fn {source}} does not exist") } file.info(source)$mtime > file.info(target)$mtime diff --git a/R/utils-yaml.R b/R/utils-yaml.R index 1c21bc19f..1a2dcc16c 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -6,10 +6,9 @@ check_yaml_has <- function(missing, where, pkg) { missing_components <- lapply(missing, function(x) c(where, x)) missing_fields <- pkgdown_fields(pkg, missing_components) - abort(paste0( - "Can't find component", if (length(missing) > 1) "s", " ", - missing_fields, "." - )) + cli::cli_abort( + "Can't find components {missing_fields}." + ) } yaml_character <- function(pkg, where) { @@ -20,7 +19,8 @@ yaml_character <- function(pkg, where) { } else if (is.character(x)) { x } else { - abort(paste0(pkgdown_field(pkg, where), " must be a character vector")) + fld <- pkgdown_field(pkg, where) + cli::cli_abort("{.var {fld}} must be a character vector") } } diff --git a/R/utils.R b/R/utils.R index 6ace99a97..290748126 100644 --- a/R/utils.R +++ b/R/utils.R @@ -59,36 +59,13 @@ devtools_meta <- function(x) { # CLI --------------------------------------------------------------------- -dst_path <- function(...) { - cli::col_blue(encodeString(path(...), quote = "'")) -} - -src_path <- function(...) { - cli::col_green(encodeString(path(...), quote = "'")) -} - -cat_line <- function(...) { - cat(paste0(..., "\n"), sep = "") -} - -rule <- function(x = NULL, line = "-") { - width <- getOption("width") - - if (!is.null(x)) { - prefix <- paste0(line, line, " ") - suffix <- " " - } else { - prefix <- "" - suffix <- "" - x <- "" - } - - line_length <- width - nchar(x) - nchar(prefix) - nchar(suffix) - # protect against negative values which can result in narrow terminals - line_length <- max(0, line_length) - cat_line(prefix, cli::style_bold(x), suffix, strrep(line, line_length)) -} +dst_path <- cli::combine_ansi_styles( + cli::style_bold, cli::col_cyan +) +src_path <- cli::combine_ansi_styles( + cli::style_bold, cli::col_green +) skip_if_no_pandoc <- function(version = "1.12.3") { testthat::skip_if_not(rmarkdown::pandoc_available(version)) diff --git a/man/test-dont.Rd b/man/test-dont.Rd index dbcfb7959..6f23fc3cc 100644 --- a/man/test-dont.Rd +++ b/man/test-dont.Rd @@ -8,7 +8,7 @@ Test case: don't } \examples{ \dontrun{ - stop("This is an error!", call. = FALSE) + cli::cli_abort("This is an error!") } # Inline \donttest is silently ommitted diff --git a/man/test-output-styles.Rd b/man/test-output-styles.Rd index e7655192f..118a229ae 100644 --- a/man/test-output-styles.Rd +++ b/man/test-output-styles.Rd @@ -13,8 +13,8 @@ a <- 1:100 a cat("This some text!\n") -message("This is a message!") -warning("This is a warning!") +cli::cli_inform("This is a message!") +cli::cli_warn("This is a warning!") # This is a multi-line block { diff --git a/tests/testthat/_snaps/build-articles.md b/tests/testthat/_snaps/build-articles.md index 807792066..c3626334b 100644 --- a/tests/testthat/_snaps/build-articles.md +++ b/tests/testthat/_snaps/build-articles.md @@ -2,11 +2,13 @@ Code build_articles(pkg) - Output - -- Building articles ----------------------------------------------------------- - Writing 'articles/index.html' - Reading 'vignettes/html-vignette.Rmd' - Writing 'articles/html-vignette.html' + Message + + -- Building articles -- + + i Writing articles/index.html + i Reading vignettes/html-vignette.Rmd + i Writing articles/html-vignette.html Condition Warning: Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' diff --git a/tests/testthat/_snaps/build-favicons.new.md b/tests/testthat/_snaps/build-favicons.new.md new file mode 100644 index 000000000..c1426593b --- /dev/null +++ b/tests/testthat/_snaps/build-favicons.new.md @@ -0,0 +1,9 @@ +# existing logo generates message + + Code + build_favicons(pkg) + Message + -- Building favicons ----------------------------------------------------------- + Favicons already exist in 'pkgdown' + i Set `overwrite = TRUE` to re-create. + diff --git a/tests/testthat/_snaps/build-home-authors.new.md b/tests/testthat/_snaps/build-home-authors.new.md new file mode 100644 index 000000000..5de8ba248 --- /dev/null +++ b/tests/testthat/_snaps/build-home-authors.new.md @@ -0,0 +1,27 @@ +# data_home_sidebar_authors() works with text + + Code + cat(data_home_sidebar_authors(pkg)) + Output +
+

Developers

+
    +
  • yay
  • +
  • Hadley Wickham
    + Author, maintainer
  • +
  • RStudio
    + Copyright holder, funder
  • +
  • cool
  • +
  • More about authors...
  • +
+
+ +# role has multiple fallbacks + + Code + role_lookup("unknown") + Message + ! Unknown MARC role abbreviation: 'unknown' + Output + [1] "unknown" + diff --git a/tests/testthat/_snaps/build-home-index.new.md b/tests/testthat/_snaps/build-home-index.new.md new file mode 100644 index 000000000..875903a65 --- /dev/null +++ b/tests/testthat/_snaps/build-home-index.new.md @@ -0,0 +1,92 @@ +# data_home_sidebar() works by default + + Code + cat(data_home_sidebar(pkg)) + Output +
+

License

+ +
+ + +
+

Citation

+ +
+ +
+

Developers

+
    +
  • Hadley Wickham
    + Author, maintainer
  • +
  • RStudio
    + Copyright holder, funder
  • +
+
+ +
+

Dev Status

+
    +
  • placeholder
  • +
+
+ +--- + +
+

Developers

+ +
+ +# data_home_sidebar() errors well when no HTML file + + Can't find file 'html_path' specified by home.sidebar.html in _pkgdown.yml + +# data_home_sidebar() can get a custom markdown formatted component + +
+

Fancy section

+
    +
  • How cool is pkgdown?!

  • +
+
+ +# data_home_sidebar() can add a README + +
+

Table of contents

+
    +
  • +
+
+ +# data_home_sidebar() outputs informative error messages + + Can't find component home.sidebar.components.fancy in _pkgdown.yml. + +--- + + Can't find component home.sidebar.components.fancy, home.sidebar.components.cool in _pkgdown.yml. + +--- + + i In index: 1. + i With name: fancy. + Caused by error in `check_yaml_has()`: + ! Can't find component home.sidebar.components.fancy.title in _pkgdown.yml. + +--- + + i In index: 1. + i With name: fancy. + Caused by error in `check_yaml_has()`: + ! Can't find component home.sidebar.components.fancy.title, home.sidebar.components.fancy.text in _pkgdown.yml. + diff --git a/tests/testthat/_snaps/build-home.new.md b/tests/testthat/_snaps/build-home.new.md new file mode 100644 index 000000000..028a3674e --- /dev/null +++ b/tests/testthat/_snaps/build-home.new.md @@ -0,0 +1,15 @@ +# warns about missing images + + Code + build_home(pkg) + Message + -- Building home --------------------------------------------------------------- + Output + Writing {path} + Condition + Warning: + Missing images in `src_path`: ''foo.png'' + i pkgdown can only use images in 'man/figures' and 'vignettes' + Output + Writing {path} + diff --git a/tests/testthat/_snaps/check.new.md b/tests/testthat/_snaps/check.new.md new file mode 100644 index 000000000..410b2ac2b --- /dev/null +++ b/tests/testthat/_snaps/check.new.md @@ -0,0 +1,25 @@ +# fails if reference index incomplete + + Code + check_pkgdown(pkg) + Condition + Error in `check_missing_topics()`: + ! All topics must be included in reference index + x Missing topics: ? + i Either add to _pkgdown.yml or use @keywords internal + +# fails if article index incomplete + + Code + check_pkgdown(pkg) + Condition + Error in `data_articles_index()`: + ! Vignettes missing from index: articles/nested and width + +# informs if everything is ok + + Code + check_pkgdown(pkg) + Message + No problems found + From 61a09cd031cbe53517311290b6126458c3530584 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sat, 25 Nov 2023 20:33:21 -0700 Subject: [PATCH 02/20] convert a few more rules to h2 --- R/build-articles.R | 2 +- R/build-favicons.R | 2 +- R/build-github.R | 4 ++-- R/deploy-site.R | 2 +- R/rmarkdown.R | 3 +-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/R/build-articles.R b/R/build-articles.R index b0e6240e4..5e5fe5aad 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -207,7 +207,7 @@ build_article <- function(name, # allow code sharing with building of the index. vig <- match(name, pkg$vignettes$name) if (is.na(vig)) { - cli::cli_abort("Can't find article {ui_path(name)}") + cli::cli_abort("Can't find article {.file {name}}") } input <- pkg$vignettes$file_in[vig] diff --git a/R/build-favicons.R b/R/build-favicons.R index 3245b3e9d..ceda69acf 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -19,7 +19,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { rlang::check_installed("openssl") pkg <- as_pkgdown(pkg) - cli::cli_rule("Building favicons") + cli::cli_h2("Building favicons") logo_path <- find_logo(pkg$src_path) diff --git a/R/build-github.R b/R/build-github.R index 76111e896..ac33b9836 100644 --- a/R/build-github.R +++ b/R/build-github.R @@ -25,7 +25,7 @@ build_site_github_pages <- function(pkg = ".", pkg <- as_pkgdown(pkg, override = list(destination = dest_dir)) if (clean) { - cli::cli_rule("Cleaning files from old site") + cli::cli_h2("Cleaning files from old site") clean_site(pkg) } @@ -36,7 +36,7 @@ build_site_github_pages <- function(pkg = ".", } build_github_pages <- function(pkg = ".") { - cli::cli_rule("Extra files for GitHub pages") + cli::cli_h2("Extra files for GitHub pages") pkg <- as_pkgdown(pkg) # Add .nojekyll since site is static HTML diff --git a/R/deploy-site.R b/R/deploy-site.R index 266c7cad0..6bb67e40b 100644 --- a/R/deploy-site.R +++ b/R/deploy-site.R @@ -54,7 +54,7 @@ deploy_site_github <- function( cli::cli_abort("No repo detected, please supply one with {.var repo_slug}") } - cli::cli_rule("Deploying site to GitHub") + cli::cli_alert("Deploying site to GitHub") if (install) { cli::cli_inform("Installing package") callr::rcmd("INSTALL", tarball, show = verbose, fail_on_status = TRUE) diff --git a/R/rmarkdown.R b/R/rmarkdown.R index d2ee63fa0..9aa4d49b4 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -38,9 +38,8 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ) ), error = function(cnd) { - cli::cli_rule("RMarkdown error") + cli::cli_h2("RMarkdown error") cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) - cli::cli_rule() cli::cli_abort("Failed to render RMarkdown") } ) From 26cbffb01a9d994d4b7b5e5a68d88820e2250793 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 06:33:43 -0700 Subject: [PATCH 03/20] tweaks to improve sitrep --- R/build-redirects.R | 6 +----- R/deploy-site.R | 4 ++-- R/sitrep.R | 31 +++++++++++++++++++++---------- R/utils-fs.R | 6 ++++++ R/utils-yaml.R | 8 ++++---- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/R/build-redirects.R b/R/build-redirects.R index f8e15f582..9e7307af4 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -26,11 +26,7 @@ build_redirects <- function(pkg = ".", build_redirect <- function(entry, index, pkg) { if (!is.character(entry) || length(entry) != 2) { cli::cli_abort( - sprintf( - "Entry %s in %s must be a character vector of length 2.", - index, - pkgdown_field(pkg, "redirects") - ) + "Entry {.emph index} in {pkgdown_field(pkg, 'redirects')} must be a character vector of length 2.", ) } diff --git a/R/deploy-site.R b/R/deploy-site.R index 6bb67e40b..22d5f5ff9 100644 --- a/R/deploy-site.R +++ b/R/deploy-site.R @@ -201,8 +201,8 @@ git <- function(..., echo_cmd = TRUE, echo = TRUE, error_on_status = TRUE) { construct_commit_message <- function(pkg, commit = ci_commit_sha()) { pkg <- as_pkgdown(pkg) - - cli::cli_alert_success(sprintf("Built site for %s: %s@%s", pkg$package, pkg$version, substr(commit, 1, 7))) + commit <- sprintf("%s@%s", pkg$version, substr(commit, 1, 7)) + cli::cli_alert_success("Built site for {cli::col_yellow(pkg$package)}: {.emph {cli::col_green(commit)}}") } ci_commit_sha <- function() { diff --git a/R/sitrep.R b/R/sitrep.R index 973d53a16..ebdcc9f71 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -13,18 +13,29 @@ #' @export #' pkgdown_sitrep <- function(pkg = ".") { - pkg_dir <- pkg - pkg <- as_pkgdown(pkg_dir) + pkg <- as_pkgdown(pkg) + warns <- c() + if (is.null(pkg$meta[["url"]])) { - cli::cli_alert_warning(sprintf("%s is not configured.", pkgdown_field(pkg, "url"))) + warns <- c(warns, "x" = "{pkgdown_field(pkg, 'url')} is not configured. See vignette {.vignette pkgdown::metatdata}.") + } + + desc_urls <- pkg$desc$get_urls() + desc_urls <- sub("/$", "", urls) + if (!pkg$meta[["url"]] %in% desc_urls) { + warns <- c(warns, "x" = "DESCRIPTION {.field URL} is empty.") + } + + if (length(warns) == 0) { + cli::cli_alert_success("pkgdown situation report: {.emph {cli::col_green('all clear')}}") + cli::cli_alert("{.emph Double-check the following URLs:}") + cli::cli_alert_info("{.file {pkgdown_config_relpath(pkg)}} contains URL {.url {pkg$meta['url']}}") + cli::cli_alert_info("{.file DESCRIPTION} contains URL{?s} {.url {desc_urls}}") } else { - urls <- desc::desc(pkg_dir)$get_urls() - urls <- sub("/$", "", urls) - if (!pkg$meta[["url"]] %in% urls) { - cli::cli_alert_warning("URL is missing in the DESCRIPTION URL field.") - } else { - cli::cli_alert_success("pkgdown situation report is all clear") - } + cli::cli_warn(c( + "pkgdown situation report: {.emph {cli::col_red('configuration error')}}", + warns + )) } invisible() diff --git a/R/utils-fs.R b/R/utils-fs.R index f938f1ad8..f33700036 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -100,3 +100,9 @@ path_package_pkgdown <- function(..., package, bs_version = NULL) { path_pkgdown <- function(...) { system_file(..., package = "pkgdown") } + +pkgdown_config_relpath <- function(pkg) { + pkg <- as_pkgdown(pkg) + config_path <- pkgdown_config_path(pkg$src_path) + fs::path_rel(config_path, pkg$src_path) +} diff --git a/R/utils-yaml.R b/R/utils-yaml.R index 1a2dcc16c..c5799abaf 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -7,7 +7,7 @@ check_yaml_has <- function(missing, where, pkg) { missing_fields <- pkgdown_fields(pkg, missing_components) cli::cli_abort( - "Can't find components {missing_fields}." + "Can't find components: {missing_fields}." ) } @@ -20,7 +20,7 @@ yaml_character <- function(pkg, where) { x } else { fld <- pkgdown_field(pkg, where) - cli::cli_abort("{.var {fld}} must be a character vector") + cli::cli_abort("{fld} must be a character vector") } } @@ -37,8 +37,8 @@ pkgdown_fields <- function(pkg, fields, join = ", ") { if (is.null(config_path)) { fields_str } else { - config <- src_path(fs::path_rel(config_path, pkg$src_path)) - paste0(fields_str, " in ", config) + config <- src_path(pkgdown_config_relpath(pkg)) + paste0('`', fields_str, "` in ", config) } } From 9e2a9e2bf27242eb62b765fbcd00596d8dc596fb Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 07:15:17 -0700 Subject: [PATCH 04/20] rmarkdown error tweaks --- R/rmarkdown.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/rmarkdown.R b/R/rmarkdown.R index 9aa4d49b4..be87e44c1 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -7,7 +7,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet output_path <- path_abs(output, pkg$dst_path) if (!file_exists(input_path)) { - cli::cli_abort("Can't find {.file {src_path(input)}") + cli::cli_abort("Can't find {src_path(input)") } cli::cli_alert_info("Reading {src_path(input)}") @@ -38,9 +38,10 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ) ), error = function(cnd) { - cli::cli_h2("RMarkdown error") - cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) - cli::cli_abort("Failed to render RMarkdown") + cli::cli_abort(c( + "Failed to render RMarkdown document", + "x" = cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) + )) } ) From 8eea32d372d334b68a5944e3f51c461dfe19e0e7 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 07:30:22 -0700 Subject: [PATCH 05/20] add link to check --- R/check.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check.R b/R/check.R index 92334b69b..49a1154df 100644 --- a/R/check.R +++ b/R/check.R @@ -12,6 +12,6 @@ check_pkgdown <- function(pkg = ".") { data_articles_index(pkg) data_reference_index(pkg) - cli::cli_alert_success("No problems found in {.file _pkgdown.yml}") + cli::cli_alert_success("No problems found in {.file {pkgdown_config_relpath(pkg)}}") } From f4170028213447c74100ee90a249f08ecd6ca4d7 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 08:28:01 -0700 Subject: [PATCH 06/20] bump cli version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0ee5912bc..ae63aff58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Depends: Imports: bslib (>= 0.3.1), callr (>= 3.7.3), - cli, + cli (>= 3.6.1), desc (>= 1.4.0), digest, downlit (>= 0.4.0), From 476428659cf8c8cc90552776c338e7854052cc52 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 12:08:05 -0700 Subject: [PATCH 07/20] update tests and snapshots for cli outputs need to check snapshots carefully --- R/build-home-authors.R | 10 +- R/build-home-index.R | 9 +- R/build-redirects.R | 2 +- R/build-reference-index.R | 30 +- R/package.R | 4 +- R/rd-example.R | 2 +- R/rd-html.R | 6 +- R/sitrep.R | 8 +- R/theme.R | 4 +- R/topics-external.R | 2 +- R/utils-yaml.R | 24 +- tests/testthat/_snaps/build-articles.md | 116 +++++++- tests/testthat/_snaps/build-favicons.md | 5 +- tests/testthat/_snaps/build-favicons.new.md | 9 - tests/testthat/_snaps/build-github.md | 5 + tests/testthat/_snaps/build-home-authors.md | 34 ++- .../testthat/_snaps/build-home-authors.new.md | 27 -- tests/testthat/_snaps/build-home-citation.md | 5 + tests/testthat/_snaps/build-home-index.md | 16 +- tests/testthat/_snaps/build-home-index.new.md | 92 ------ tests/testthat/_snaps/build-home.md | 54 +++- tests/testthat/_snaps/build-home.new.md | 15 - tests/testthat/_snaps/build-logo.md | 19 +- tests/testthat/_snaps/build-news.md | 82 +++++- .../testthat/_snaps/build-reference-index.md | 155 ++++++++-- tests/testthat/_snaps/build-reference.md | 191 ++++++++++++- tests/testthat/_snaps/build-search-docs.md | 45 +++ tests/testthat/_snaps/check.md | 79 ++++- tests/testthat/_snaps/check.new.md | 25 -- tests/testthat/_snaps/figure.md | 40 +++ tests/testthat/_snaps/init.md | 150 +++++++++- tests/testthat/_snaps/markdown.md | 5 +- tests/testthat/_snaps/package.md | 2 +- tests/testthat/_snaps/rd-example.md | 32 +++ tests/testthat/_snaps/rd-html.md | 270 +++++++++++++++++- tests/testthat/_snaps/render.md | 20 ++ tests/testthat/_snaps/rmarkdown.md | 109 ++++++- tests/testthat/_snaps/sitrep.md | 92 +++++- tests/testthat/_snaps/topics-external.md | 2 +- tests/testthat/_snaps/topics.md | 34 ++- tests/testthat/_snaps/utils-yaml.md | 70 ++++- tests/testthat/setup.R | 3 + tests/testthat/test-build-articles.R | 34 +-- tests/testthat/test-build-favicons.R | 2 +- tests/testthat/test-build-github.R | 2 +- tests/testthat/test-build-home-authors.R | 2 +- tests/testthat/test-build-home-citation.R | 2 +- tests/testthat/test-build-home-index.R | 2 +- tests/testthat/test-build-home.R | 10 +- tests/testthat/test-build-logo.R | 2 +- tests/testthat/test-build-news.R | 6 +- tests/testthat/test-build-reference-index.R | 12 +- tests/testthat/test-build-reference.R | 22 +- tests/testthat/test-build-search-docs.R | 18 +- tests/testthat/test-check.R | 6 +- tests/testthat/test-figure.R | 6 +- tests/testthat/test-init.R | 18 +- tests/testthat/test-rd-example.R | 9 +- tests/testthat/test-rd-html.R | 19 +- tests/testthat/test-render.R | 4 +- tests/testthat/test-rmarkdown.R | 10 +- tests/testthat/test-sitrep.R | 8 +- tests/testthat/test-utils-yaml.R | 10 +- 63 files changed, 1632 insertions(+), 476 deletions(-) delete mode 100644 tests/testthat/_snaps/build-favicons.new.md create mode 100644 tests/testthat/_snaps/build-github.md delete mode 100644 tests/testthat/_snaps/build-home-authors.new.md delete mode 100644 tests/testthat/_snaps/build-home-index.new.md delete mode 100644 tests/testthat/_snaps/build-home.new.md create mode 100644 tests/testthat/_snaps/build-search-docs.md delete mode 100644 tests/testthat/_snaps/check.new.md create mode 100644 tests/testthat/_snaps/figure.md create mode 100644 tests/testthat/_snaps/rd-example.md create mode 100644 tests/testthat/setup.R diff --git a/R/build-home-authors.R b/R/build-home-authors.R index 79fbdf72e..beb5dfb98 100644 --- a/R/build-home-authors.R +++ b/R/build-home-authors.R @@ -56,12 +56,12 @@ data_home_sidebar_authors <- function(pkg = ".") { bullets <- c( markdown_text_inline( pkg$meta$authors$sidebar$before, - pkgdown_field(pkg, c("authors", "sidebar", "before")) + pkgdown_field(c("authors", "sidebar", "before")) ), authors, markdown_text_inline( pkg$meta$authors$sidebar$after, - pkgdown_field(pkg, c("authors", "sidebar", "after")) + pkgdown_field(c("authors", "sidebar", "after")) ) ) @@ -96,7 +96,7 @@ author_name <- function(x, authors, pkg) { if (!is.null(author$html)) { name <- markdown_text_inline( author$html, - pkgdown_field(pkg, c("authors", name, "html")) + pkgdown_field(c("authors", name, "html")) ) } @@ -186,8 +186,8 @@ role_lookup <- function(abbr) { out <- unname(roles[abbr]) if (any(is.na(out))) { - missing <- paste0("'", abbr[is.na(out)], "'", collapse = ", ") - cli::cli_alert_warning("Unknown MARC role abbreviation{?s}: {missing}") + missing <- abbr[is.na(out)] + cli::cli_warn("Unknown MARC role abbreviation{?s}: {.field {missing}}") out[is.na(out)] <- abbr[is.na(out)] } out diff --git a/R/build-home-index.R b/R/build-home-index.R index d98249a30..f9d14daf8 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -64,9 +64,12 @@ data_home_sidebar <- function(pkg = ".") { if (length(html_path)) { if (!file.exists(html_path)) { - cli::cli_abort( - "Can't find file {.file {html_path}} specified by {pkgdown_field(pkg, c('home', 'sidebar', 'html'))}" - ) + rel_html_path <- fs::path_rel(html_path, pkg$src_path) + rel_config_path <- pkgdown_config_relpath(pkg) + cli::cli_abort(c( + "Can't locate {.file {rel_html_path}}", + "x" = "{.field {pkgdown_field(c('home', 'sidebar', 'html'))}} in {.file {rel_config_path}} is misconfigured" + )) } return(read_file(html_path)) } diff --git a/R/build-redirects.R b/R/build-redirects.R index 9e7307af4..30d1f843b 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -26,7 +26,7 @@ build_redirects <- function(pkg = ".", build_redirect <- function(entry, index, pkg) { if (!is.character(entry) || length(entry) != 2) { cli::cli_abort( - "Entry {.emph index} in {pkgdown_field(pkg, 'redirects')} must be a character vector of length 2.", + "Entry {.emph {index}} in {.field {pkgdown_field('redirects')}} must be a character vector of length 2.", ) } diff --git a/R/build-reference-index.R b/R/build-reference-index.R index d8e4df7e5..fc2173ed9 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -69,17 +69,10 @@ check_all_characters <- function(contents, index, pkg) { any_null <- any(null) if (any_null) { - abort( - c( - sprintf( - "Item %s in section %s in %s is empty.", - toString(which(null)), - index, - pkgdown_field(pkg, "reference") - ), - i = "Either delete the empty line or add a function name." - ) - ) + cli::cli_abort(c( + "Item {.field {which(null)}} in section {index} in {.field {pkgdown_field('reference')}} is empty.", + i = "Either delete the empty line or add a function name in {.file {pkgdown_config_relpath(pkg)}}." + )) } not_char <- !purrr::map_lgl(contents, is.character) @@ -89,17 +82,10 @@ check_all_characters <- function(contents, index, pkg) { return(invisible()) } - abort( - c( - sprintf( - "Item %s in section %s in %s must be a character.", - toString(which(not_char)), - index, - pkgdown_field(pkg, "reference") - ), - i = "You might need to add '' around e.g. - 'N' or - 'off'." - ) - ) + cli::cli_abort(c( + "Item {.field {which(not_char)}} in section {index} in {.field {pkgdown_field('reference')}} must be a character.", + i = "You might need to add '' around e.g. - 'N' or - 'off' in {.file {pkgdown_config_relpath(pkg)}}." + )) } diff --git a/R/package.R b/R/package.R index 0f06e3401..b80dc3cd3 100644 --- a/R/package.R +++ b/R/package.R @@ -103,10 +103,10 @@ check_bootstrap_version <- function(version, pkg = list()) { cli::cli_warn("{.var bootstrap: 4} no longer supported, using {.var bootstrap: 5} instead") 5 } else { - field <- pkgdown_field(pkg, c("template", "bootstrap")) + field <- pkgdown_field(c("template", "bootstrap")) cli::cli_abort(c( "Boostrap version must be 3 or 5.", - "x" = "You specified a value of {.var {version}} in {.var {field}}" + "x" = "You specified a value of {.var {version}} in {.field {field}}." )) } } diff --git a/R/rd-example.R b/R/rd-example.R index d3f1e8566..25180bd45 100644 --- a/R/rd-example.R +++ b/R/rd-example.R @@ -65,7 +65,7 @@ process_conditional_examples <- function(rd) { if (!is_false) { new_cond <- paste0("if (FALSE) { # ", cond_expr_str) cli::cli_warn( - "@examplesIf condition {.var cond_expr_str} FALSE" + "@examplesIf condition {.var cond_expr_str} is FALSE" ) } else { new_cond <- "if (FALSE) {" diff --git a/R/rd-html.R b/R/rd-html.R index 03a404c67..397fef055 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -130,7 +130,7 @@ as_html.tag_deqn <- function(x, ...) { as_html.tag_url <- function(x, ...) { if (length(x) != 1) { if (length(x) == 0) { - msg <- "Check for empty \\url{} tags." + msg <- "Check for empty \\url{{}} tags." } else { msg <- "This may be caused by a \\url tag that spans a line break." } @@ -229,7 +229,7 @@ as_html.tag_Sexpr <- function(x, ...) { text = as.character(res), rd = flatten_text(rd_text(as.character(res))), hide = "", - cli::cli_abort("\\Sexpr{result=", results, "} not yet supported", call. = FALSE) + cli::cli_abort("\\Sexpr{result=", results, "} not yet supported") ) } @@ -565,7 +565,7 @@ parse_opts <- function(string) { } stop_bad_tag <- function(tag, msg = NULL) { - bad_tag <- paste0("\\\\", tag, "{}") + bad_tag <- paste0("\\", tag, "{}") msg_abort <- 'Failed to parse tag {.var {bad_tag}}.' if (!is.null(msg)) { msg_abort <- c(msg_abort, "x" = msg) diff --git a/R/sitrep.R b/R/sitrep.R index ebdcc9f71..f88d9f039 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -17,13 +17,13 @@ pkgdown_sitrep <- function(pkg = ".") { warns <- c() if (is.null(pkg$meta[["url"]])) { - warns <- c(warns, "x" = "{pkgdown_field(pkg, 'url')} is not configured. See vignette {.vignette pkgdown::metatdata}.") + warns <- c(warns, "x" = "{pkgdown_field('url')} is not configured in {.file {pkgdown_config_relpath(pkg)}}. See vignette {.vignette pkgdown::metatdata}.") } desc_urls <- pkg$desc$get_urls() - desc_urls <- sub("/$", "", urls) - if (!pkg$meta[["url"]] %in% desc_urls) { - warns <- c(warns, "x" = "DESCRIPTION {.field URL} is empty.") + desc_urls <- sub("/$", "", desc_urls) + if (length(desc_urls) == 0 || !pkg$meta[["url"]] %in% desc_urls) { + warns <- c(warns, "x" = "{.file DESCRIPTION} {.field URL} is empty.") } if (length(warns) == 0) { diff --git a/R/theme.R b/R/theme.R index a4232cfc9..6d90e4d73 100644 --- a/R/theme.R +++ b/R/theme.R @@ -105,9 +105,9 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { sprintf( "Can't find Bootswatch theme '%s' (%s) for Bootstrap version '%s' (%s).", bootswatch_theme, - pkgdown_field(pkg, c("template", "bootswatch")), + pkgdown_field(c("template", "bootswatch")), bs_version, - pkgdown_field(pkg, c("template", "bootstrap")) + pkgdown_field(c("template", "bootstrap")) ) ) } diff --git a/R/topics-external.R b/R/topics-external.R index 312f0afa9..e0d6620a9 100644 --- a/R/topics-external.R +++ b/R/topics-external.R @@ -30,7 +30,7 @@ get_rd_from_help <- function(package, alias) { help <- utils::help((alias), (package)) if (length(help) == 0) { fun <- paste0(package, "::", alias) - cli::cli_abort("Could not find documentation for {.fn fun}.") + cli::cli_abort("Could not find documentation for {.fn {fun}}.") return() } diff --git a/R/utils-yaml.R b/R/utils-yaml.R index c5799abaf..04b6e5596 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -4,10 +4,10 @@ check_yaml_has <- function(missing, where, pkg) { } missing_components <- lapply(missing, function(x) c(where, x)) - missing_fields <- pkgdown_fields(pkg, missing_components) + missing_fields <- purrr::map_chr(missing_components, pkgdown_field) cli::cli_abort( - "Can't find components: {missing_fields}." + "Can't find {.field {missing_fields}} component{?s} in {.file {pkgdown_config_relpath(pkg)}}." ) } @@ -19,27 +19,13 @@ yaml_character <- function(pkg, where) { } else if (is.character(x)) { x } else { - fld <- pkgdown_field(pkg, where) + fld <- pkgdown_field(where) cli::cli_abort("{fld} must be a character vector") } } -pkgdown_field <- function(pkg, field) { - pkgdown_fields(pkg, list(field)) -} - -pkgdown_fields <- function(pkg, fields, join = ", ") { - fields <- purrr::map_chr(fields, ~ paste0(cli::style_bold(.x), collapse = ".")) - fields_str <- paste0(fields, collapse = join) - - config_path <- pkgdown_config_path(pkg$src_path) - - if (is.null(config_path)) { - fields_str - } else { - config <- src_path(pkgdown_config_relpath(pkg)) - paste0('`', fields_str, "` in ", config) - } +pkgdown_field <- function(fields) { + purrr::map_chr(list(fields), ~ paste0(.x, collapse = ".")) } # print helper ------------------------------------------------------------ diff --git a/tests/testthat/_snaps/build-articles.md b/tests/testthat/_snaps/build-articles.md index c3626334b..0488d2eb7 100644 --- a/tests/testthat/_snaps/build-articles.md +++ b/tests/testthat/_snaps/build-articles.md @@ -1,16 +1,116 @@ -# warns about missing images +# links to man/figures are automatically relocated + + Code + copy_figures(pkg) + +--- + + Code + build_articles(pkg, lazy = FALSE) + +# warns about missing images [plain] Code build_articles(pkg) - Message - - -- Building articles -- - - i Writing articles/index.html - i Reading vignettes/html-vignette.Rmd - i Writing articles/html-vignette.html Condition Warning: Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' i pkgdown can only use images in 'man/figures' and 'vignettes' +# warns about missing images [ansi] + + Code + build_articles(pkg) + Condition + Warning: + Missing images in vignettes/html-vignette.Rmd: foo.png + i pkgdown can only use images in man/figures and vignettes + +# warns about missing images [unicode] + + Code + build_articles(pkg) + Condition + Warning: + Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' + ℹ pkgdown can only use images in 'man/figures' and 'vignettes' + +# warns about missing images [fancy] + + Code + build_articles(pkg) + Condition + Warning: + Missing images in vignettes/html-vignette.Rmd: foo.png + ℹ pkgdown can only use images in man/figures and vignettes + +# articles don't include header-attrs.js script + + Code + path <- build_article("standard", pkg) + +# can build article that uses html_vignette + + Code + expect_error(build_article("html-vignette", pkg), NA) + +# can override html_document() options + + Code + path <- build_article("html-document", pkg) + +# html widgets get needed css/js + + Code + path <- build_article("widget", pkg) + +# can override options with _output.yml + + Code + path <- build_article("html-document", pkg) + +# can set width + + Code + path <- build_article("width", pkg) + +# finds external resources referenced by R code in the article html + + Code + path <- build_article("resources", pkg) + +# BS5 article laid out correctly with and without TOC + + Code + init_site(pkg) + +--- + + Code + toc_true_path <- build_article("standard", pkg) + +--- + + Code + toc_false_path <- build_article("toc-false", pkg) + +# articles in vignettes/articles/ are unnested into articles/ + + Code + path <- build_article("articles/nested", pkg) + +--- + + Code + build_redirects(pkg) + +# pkgdown deps are included only once in articles + + Code + init_site(pkg) + +--- + + Code + path <- build_article("html-deps", pkg) + diff --git a/tests/testthat/_snaps/build-favicons.md b/tests/testthat/_snaps/build-favicons.md index 8d68d02b0..21f970cf1 100644 --- a/tests/testthat/_snaps/build-favicons.md +++ b/tests/testthat/_snaps/build-favicons.md @@ -2,8 +2,7 @@ Code build_favicons(pkg) - Output - -- Building favicons ----------------------------------------------------------- Message - Favicons already exist in `pkgdown/`. Set `overwrite = TRUE` to re-create. + Favicons already exist in 'pkgdown' + i Set `overwrite = TRUE` to re-create. diff --git a/tests/testthat/_snaps/build-favicons.new.md b/tests/testthat/_snaps/build-favicons.new.md deleted file mode 100644 index c1426593b..000000000 --- a/tests/testthat/_snaps/build-favicons.new.md +++ /dev/null @@ -1,9 +0,0 @@ -# existing logo generates message - - Code - build_favicons(pkg) - Message - -- Building favicons ----------------------------------------------------------- - Favicons already exist in 'pkgdown' - i Set `overwrite = TRUE` to re-create. - diff --git a/tests/testthat/_snaps/build-github.md b/tests/testthat/_snaps/build-github.md new file mode 100644 index 000000000..461afc69a --- /dev/null +++ b/tests/testthat/_snaps/build-github.md @@ -0,0 +1,5 @@ +# a CNAME record is built if a url exists in metadata + + Code + build_github_pages(pkg) + diff --git a/tests/testthat/_snaps/build-home-authors.md b/tests/testthat/_snaps/build-home-authors.md index 46755f61b..c6429c32c 100644 --- a/tests/testthat/_snaps/build-home-authors.md +++ b/tests/testthat/_snaps/build-home-authors.md @@ -16,13 +16,43 @@ -# role has multiple fallbacks +# role has multiple fallbacks [plain] Code role_lookup("unknown") Condition Warning: - Unknown MARC role abbreviation 'unknown' + Unknown MARC role abbreviation: unknown + Output + [1] "unknown" + +# role has multiple fallbacks [ansi] + + Code + role_lookup("unknown") + Condition + Warning: + Unknown MARC role abbreviation: unknown + Output + [1] "unknown" + +# role has multiple fallbacks [unicode] + + Code + role_lookup("unknown") + Condition + Warning: + Unknown MARC role abbreviation: unknown + Output + [1] "unknown" + +# role has multiple fallbacks [fancy] + + Code + role_lookup("unknown") + Condition + Warning: + Unknown MARC role abbreviation: unknown Output [1] "unknown" diff --git a/tests/testthat/_snaps/build-home-authors.new.md b/tests/testthat/_snaps/build-home-authors.new.md deleted file mode 100644 index 5de8ba248..000000000 --- a/tests/testthat/_snaps/build-home-authors.new.md +++ /dev/null @@ -1,27 +0,0 @@ -# data_home_sidebar_authors() works with text - - Code - cat(data_home_sidebar_authors(pkg)) - Output -
-

Developers

-
    -
  • yay
  • -
  • Hadley Wickham
    - Author, maintainer
  • -
  • RStudio
    - Copyright holder, funder
  • -
  • cool
  • -
  • More about authors...
  • -
-
- -# role has multiple fallbacks - - Code - role_lookup("unknown") - Message - ! Unknown MARC role abbreviation: 'unknown' - Output - [1] "unknown" - diff --git a/tests/testthat/_snaps/build-home-citation.md b/tests/testthat/_snaps/build-home-citation.md index 220471332..7910dda4e 100644 --- a/tests/testthat/_snaps/build-home-citation.md +++ b/tests/testthat/_snaps/build-home-citation.md @@ -1,3 +1,8 @@ +# source link is added to citation page + + Code + build_home(pkg) + # multiple citations all have HTML and BibTeX formats [[1]] diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index 4e33fc563..37e018779 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -1,3 +1,8 @@ +# version formatting in preserved + + Code + init_site(pkg) + # data_home_sidebar() works by default Code @@ -48,7 +53,8 @@ # data_home_sidebar() errors well when no HTML file - Can't find file 'file.html' specified by home.sidebar.html in '_pkgdown.yml'. + Can't locate 'file.html' + x home.sidebar.html in '_pkgdown.yml' is misconfigured # data_home_sidebar() can get a custom markdown formatted component @@ -70,23 +76,23 @@ # data_home_sidebar() outputs informative error messages - Can't find component home.sidebar.components.fancy in '_pkgdown.yml'. + Can't find home.sidebar.components.fancy component in '_pkgdown.yml'. --- - Can't find components home.sidebar.components.fancy, home.sidebar.components.cool in '_pkgdown.yml'. + Can't find home.sidebar.components.fancy and home.sidebar.components.cool components in '_pkgdown.yml'. --- i In index: 1. i With name: fancy. Caused by error in `check_yaml_has()`: - ! Can't find component home.sidebar.components.fancy.title in '_pkgdown.yml'. + ! Can't find home.sidebar.components.fancy.title component in '_pkgdown.yml'. --- i In index: 1. i With name: fancy. Caused by error in `check_yaml_has()`: - ! Can't find components home.sidebar.components.fancy.title, home.sidebar.components.fancy.text in '_pkgdown.yml'. + ! Can't find home.sidebar.components.fancy.title and home.sidebar.components.fancy.text components in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/build-home-index.new.md b/tests/testthat/_snaps/build-home-index.new.md deleted file mode 100644 index 875903a65..000000000 --- a/tests/testthat/_snaps/build-home-index.new.md +++ /dev/null @@ -1,92 +0,0 @@ -# data_home_sidebar() works by default - - Code - cat(data_home_sidebar(pkg)) - Output -
-

License

- -
- - -
-

Citation

- -
- -
-

Developers

-
    -
  • Hadley Wickham
    - Author, maintainer
  • -
  • RStudio
    - Copyright holder, funder
  • -
-
- -
-

Dev Status

-
    -
  • placeholder
  • -
-
- ---- - -
-

Developers

- -
- -# data_home_sidebar() errors well when no HTML file - - Can't find file 'html_path' specified by home.sidebar.html in _pkgdown.yml - -# data_home_sidebar() can get a custom markdown formatted component - -
-

Fancy section

-
    -
  • How cool is pkgdown?!

  • -
-
- -# data_home_sidebar() can add a README - -
-

Table of contents

-
    -
  • -
-
- -# data_home_sidebar() outputs informative error messages - - Can't find component home.sidebar.components.fancy in _pkgdown.yml. - ---- - - Can't find component home.sidebar.components.fancy, home.sidebar.components.cool in _pkgdown.yml. - ---- - - i In index: 1. - i With name: fancy. - Caused by error in `check_yaml_has()`: - ! Can't find component home.sidebar.components.fancy.title in _pkgdown.yml. - ---- - - i In index: 1. - i With name: fancy. - Caused by error in `check_yaml_has()`: - ! Can't find component home.sidebar.components.fancy.title, home.sidebar.components.fancy.text in _pkgdown.yml. - diff --git a/tests/testthat/_snaps/build-home.md b/tests/testthat/_snaps/build-home.md index 022d951c2..e95c93c19 100644 --- a/tests/testthat/_snaps/build-home.md +++ b/tests/testthat/_snaps/build-home.md @@ -1,14 +1,56 @@ -# warns about missing images +# intermediate files cleaned up automatically + + Code + build_home(pkg) + +--- + + Code + build_home(pkg) + +# warns about missing images [plain] Code build_home(pkg) - Output - -- Building home --------------------------------------------------------------- - Writing 'authors.html' Condition Warning: Missing images in 'README.md': 'foo.png' i pkgdown can only use images in 'man/figures' and 'vignettes' - Output - Writing '404.html' + +# warns about missing images [ansi] + + Code + build_home(pkg) + Condition + Warning: + Missing images in README.md: foo.png + i pkgdown can only use images in man/figures and vignettes + +# warns about missing images [unicode] + + Code + build_home(pkg) + Condition + Warning: + Missing images in 'README.md': 'foo.png' + ℹ pkgdown can only use images in 'man/figures' and 'vignettes' + +# warns about missing images [fancy] + + Code + build_home(pkg) + Condition + Warning: + Missing images in README.md: foo.png + ℹ pkgdown can only use images in man/figures and vignettes + +# can build site even if no Authors@R present + + Code + build_home(pkg) + +# .github files are copied and linked + + Code + build_home(pkg) diff --git a/tests/testthat/_snaps/build-home.new.md b/tests/testthat/_snaps/build-home.new.md deleted file mode 100644 index 028a3674e..000000000 --- a/tests/testthat/_snaps/build-home.new.md +++ /dev/null @@ -1,15 +0,0 @@ -# warns about missing images - - Code - build_home(pkg) - Message - -- Building home --------------------------------------------------------------- - Output - Writing {path} - Condition - Warning: - Missing images in `src_path`: ''foo.png'' - i pkgdown can only use images in 'man/figures' and 'vignettes' - Output - Writing {path} - diff --git a/tests/testthat/_snaps/build-logo.md b/tests/testthat/_snaps/build-logo.md index 6064320d3..86a7316f9 100644 --- a/tests/testthat/_snaps/build-logo.md +++ b/tests/testthat/_snaps/build-logo.md @@ -1,7 +1,20 @@ -# can handle logo in subdir +# can handle logo in subdir [plain] + + Code + copy_logo(pkg) + +# can handle logo in subdir [ansi] + + Code + copy_logo(pkg) + +# can handle logo in subdir [unicode] + + Code + copy_logo(pkg) + +# can handle logo in subdir [fancy] Code copy_logo(pkg) - Output - Copying 'man/figures/logo.svg' to 'logo.svg' diff --git a/tests/testthat/_snaps/build-news.md b/tests/testthat/_snaps/build-news.md index 7317c2bec..504a4b369 100644 --- a/tests/testthat/_snaps/build-news.md +++ b/tests/testthat/_snaps/build-news.md @@ -14,15 +14,77 @@ 1 1.0.0.9000 dev testpackage-1009000 2 1.0.0 1.0 testpackage-100 -# multi-page news are rendered +# multi-page news are rendered [plain] - # A tibble: 4 x 3 - version page anchor - - 1 2.0 2.0 testpackage-20 - 2 1.1 1.1 testpackage-11 - 3 1.0.1 1.0 testpackage-101 - 4 1.0.0 1.0 testpackage-100 + Code + data_news(pkg)[c("version", "page", "anchor")] + Output + # A tibble: 4 x 3 + version page anchor + + 1 2.0 2.0 testpackage-20 + 2 1.1 1.1 testpackage-11 + 3 1.0.1 1.0 testpackage-101 + 4 1.0.0 1.0 testpackage-100 + +--- + + Code + build_news(pkg) + +# multi-page news are rendered [ansi] + + Code + data_news(pkg)[c("version", "page", "anchor")] + Output + # A tibble: 4 x 3 + version page anchor +    + 1 2.0 2.0 testpackage-20 + 2 1.1 1.1 testpackage-11 + 3 1.0.1 1.0 testpackage-101 + 4 1.0.0 1.0 testpackage-100 + +--- + + Code + build_news(pkg) + +# multi-page news are rendered [unicode] + + Code + data_news(pkg)[c("version", "page", "anchor")] + Output + # A tibble: 4 × 3 + version page anchor + + 1 2.0 2.0 testpackage-20 + 2 1.1 1.1 testpackage-11 + 3 1.0.1 1.0 testpackage-101 + 4 1.0.0 1.0 testpackage-100 + +--- + + Code + build_news(pkg) + +# multi-page news are rendered [fancy] + + Code + data_news(pkg)[c("version", "page", "anchor")] + Output + # A tibble: 4 × 3 + version page anchor +    + 1 2.0 2.0 testpackage-20 + 2 1.1 1.1 testpackage-11 + 3 1.0.1 1.0 testpackage-101 + 4 1.0.0 1.0 testpackage-100 + +--- + + Code + build_news(pkg) # news headings get class and release date @@ -43,13 +105,13 @@ Invalid NEWS.md: inconsistent use of section headings. i Top-level headings must be either all

or all

. - i See ?build_news for more details. + i See `?pkgdown::build_news()` for more details. # clear error for bad hierarchy - h3 Invalid NEWS.md: inconsistent use of section headings. i Top-level headings must be either all

or all

. - i See ?build_news for more details. + i See `?pkgdown::build_news()` for more details. # news can contain footnotes diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index d595dc877..aed65b432 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -59,31 +59,148 @@ i In index: 1. Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference in '_pkgdown.yml' is empty. - i Either delete the empty line or add a function name. + ! Item 2 in section 1 in reference is empty. + i Either delete the empty line or add a function name in '_pkgdown.yml'. -# errors well when a content entry is not a character +# errors well when a content entry is not a character [plain] - i In index: 1. - Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference in '_pkgdown.yml' must be a character. - i You might need to add '' around e.g. - 'N' or - 'off'. + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `check_all_characters()`: + ! Item 2 in section 1 in reference must be a character. + i You might need to add '' around e.g. - 'N' or - 'off' in '_pkgdown.yml'. -# errors well when a content entry refers to a not installed package +# errors well when a content entry is not a character [ansi] - i In index: 1. - Caused by error in `purrr::map2()`: - i In index: 1. - Caused by error in `.f()`: - ! The package "notapackage" is required as it's used in the reference index. + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `check_all_characters()`: + ! Item 2 in section 1 in reference must be a character. + i You might need to add '' around e.g. - 'N' or - 'off' in _pkgdown.yml. -# errors well when a content entry refers to a non existing function +# errors well when a content entry is not a character [unicode] - i In index: 1. - Caused by error in `purrr::map2()`: - i In index: 1. - Caused by error in `.f()`: - ! Could not find documentation for rlang::lala + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `check_all_characters()`: + ! Item 2 in section 1 in reference must be a character. + ℹ You might need to add '' around e.g. - 'N' or - 'off' in '_pkgdown.yml'. + +# errors well when a content entry is not a character [fancy] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `check_all_characters()`: + ! Item 2 in section 1 in reference must be a character. + ℹ You might need to add '' around e.g. - 'N' or - 'off' in _pkgdown.yml. + +# errors well when a content entry refers to a not installed package [plain] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `purrr::map2()`: + i In index: 1. + Caused by error in `.f()`: + ! The package "notapackage" is required as it's used in the reference index. + +# errors well when a content entry refers to a not installed package [ansi] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `purrr::map2()`: + i In index: 1. + Caused by error in `.f()`: + ! The package "notapackage" is required as it's used in the reference index. + +# errors well when a content entry refers to a not installed package [unicode] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `purrr::map2()`: + ℹ In index: 1. + Caused by error in `.f()`: + ! The package "notapackage" is required as it's used in the reference index. + +# errors well when a content entry refers to a not installed package [fancy] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `purrr::map2()`: + ℹ In index: 1. + Caused by error in `.f()`: + ! The package "notapackage" is required as it's used in the reference index. + +# errors well when a content entry refers to a non existing function [plain] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `purrr::map2()`: + i In index: 1. + Caused by error in `.f()`: + ! Could not find documentation for `rlang::lala()`. + +# errors well when a content entry refers to a non existing function [ansi] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + i In index: 1. + Caused by error in `purrr::map2()`: + i In index: 1. + Caused by error in `.f()`: + ! Could not find documentation for `rlang::lala()`. + +# errors well when a content entry refers to a non existing function [unicode] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `purrr::map2()`: + ℹ In index: 1. + Caused by error in `.f()`: + ! Could not find documentation for `rlang::lala()`. + +# errors well when a content entry refers to a non existing function [fancy] + + Code + build_reference_index(pkg) + Condition + Error in `map2()`: + ℹ In index: 1. + Caused by error in `purrr::map2()`: + ℹ In index: 1. + Caused by error in `.f()`: + ! Could not find documentation for `rlang::lala()`. # can use a topic from another package diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index 2190def0e..eff444709 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -1,11 +1,7 @@ -# parse failures include file name +# parse failures include file name [plain] Code build_reference(pkg) - Output - -- Building function reference ------------------------------------------------- - Writing 'reference/index.html' - Reading 'man/f.Rd' Condition Error in `purrr::map()`: i In index: 1. @@ -16,6 +12,187 @@ Caused by error in `purrr::map()`: i In index: 4. Caused by error in `stop_bad_tag()`: - ! Failed to parse \url{}. - i Check for empty \url{} tags. + ! Failed to parse tag `\url{}`. + x Check for empty \url{} tags. + +# parse failures include file name [ansi] + + Code + build_reference(pkg) + Condition + Error in `purrr::map()`: + i In index: 1. + i With name: f.Rd. + Caused by error in `.f()`: + ! Failed to parse Rd in f.Rd + In index: 4. + Caused by error in `purrr::map()`: + i In index: 4. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + x Check for empty \url{} tags. + +# parse failures include file name [unicode] + + Code + build_reference(pkg) + Condition + Error in `purrr::map()`: + ℹ In index: 1. + ℹ With name: f.Rd. + Caused by error in `.f()`: + ! Failed to parse Rd in f.Rd + In index: 4. + Caused by error in `purrr::map()`: + ℹ In index: 4. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ Check for empty \url{} tags. + +# parse failures include file name [fancy] + + Code + build_reference(pkg) + Condition + Error in `purrr::map()`: + ℹ In index: 1. + ℹ With name: f.Rd. + Caused by error in `.f()`: + ! Failed to parse Rd in f.Rd + In index: 4. + Caused by error in `purrr::map()`: + ℹ In index: 4. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ Check for empty \url{} tags. + +# test usage ok on rendered page [plain] + + Code + build_reference(pkg, topics = "c") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "c") + +# test usage ok on rendered page [ansi] + + Code + build_reference(pkg, topics = "c") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "c") + +# test usage ok on rendered page [unicode] + + Code + build_reference(pkg, topics = "c") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "c") + +# test usage ok on rendered page [fancy] + + Code + build_reference(pkg, topics = "c") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "c") + +# .Rd without usage doesn't get Usage section [plain] + + Code + build_reference(pkg, topics = "e") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "e") + +# .Rd without usage doesn't get Usage section [ansi] + + Code + build_reference(pkg, topics = "e") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "e") + +# .Rd without usage doesn't get Usage section [unicode] + + Code + build_reference(pkg, topics = "e") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "e") + +# .Rd without usage doesn't get Usage section [fancy] + + Code + build_reference(pkg, topics = "e") + +--- + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "e") + +# pkgdown html dependencies are suppressed from examples in references + + Code + init_site(pkg) + +--- + + Code + build_reference(pkg, topics = "a") diff --git a/tests/testthat/_snaps/build-search-docs.md b/tests/testthat/_snaps/build-search-docs.md new file mode 100644 index 000000000..d56d25c96 --- /dev/null +++ b/tests/testthat/_snaps/build-search-docs.md @@ -0,0 +1,45 @@ +# docsearch.json and sitemap.xml are valid + + Code + build_site(pkg, new_process = FALSE) + +# build_search() builds the expected search`.json with an URL + + Code + init_site(pkg) + +--- + + Code + build_news(pkg) + +--- + + Code + build_home(pkg) + +--- + + Code + build_sitemap(pkg) + +# build_search() builds the expected search.json with no URL + + Code + init_site(pkg) + +--- + + Code + build_news(pkg) + +--- + + Code + build_home(pkg) + +--- + + Code + build_sitemap(pkg) + diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index 0580cafd1..e75f065e3 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -1,4 +1,4 @@ -# fails if reference index incomplete +# fails if reference index incomplete [plain] Code check_pkgdown(pkg) @@ -8,18 +8,85 @@ x Missing topics: ? i Either add to _pkgdown.yml or use @keywords internal -# fails if article index incomplete +# fails if reference index incomplete [ansi] + + Code + check_pkgdown(pkg) + Condition + Error in `check_missing_topics()`: + ! All topics must be included in reference index + x Missing topics: ? + i Either add to _pkgdown.yml or use @keywords internal + +# fails if reference index incomplete [unicode] + + Code + check_pkgdown(pkg) + Condition + Error in `check_missing_topics()`: + ! All topics must be included in reference index + ✖ Missing topics: ? + ℹ Either add to _pkgdown.yml or use @keywords internal + +# fails if reference index incomplete [fancy] + + Code + check_pkgdown(pkg) + Condition + Error in `check_missing_topics()`: + ! All topics must be included in reference index + ✖ Missing topics: ? + ℹ Either add to _pkgdown.yml or use @keywords internal + +# fails if article index incomplete [plain] Code check_pkgdown(pkg) Condition Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested, width + ! Vignettes missing from index: articles/nested and width + +# fails if article index incomplete [ansi] + + Code + check_pkgdown(pkg) + Condition + Error in `data_articles_index()`: + ! Vignettes missing from index: articles/nested and width + +# fails if article index incomplete [unicode] + + Code + check_pkgdown(pkg) + Condition + Error in `data_articles_index()`: + ! Vignettes missing from index: articles/nested and width + +# fails if article index incomplete [fancy] + + Code + check_pkgdown(pkg) + Condition + Error in `data_articles_index()`: + ! Vignettes missing from index: articles/nested and width + +# informs if everything is ok [plain] + + Code + check_pkgdown(pkg) + +# informs if everything is ok [ansi] + + Code + check_pkgdown(pkg) + +# informs if everything is ok [unicode] + + Code + check_pkgdown(pkg) -# informs if everything is ok +# informs if everything is ok [fancy] Code check_pkgdown(pkg) - Message - No problems found diff --git a/tests/testthat/_snaps/check.new.md b/tests/testthat/_snaps/check.new.md deleted file mode 100644 index 410b2ac2b..000000000 --- a/tests/testthat/_snaps/check.new.md +++ /dev/null @@ -1,25 +0,0 @@ -# fails if reference index incomplete - - Code - check_pkgdown(pkg) - Condition - Error in `check_missing_topics()`: - ! All topics must be included in reference index - x Missing topics: ? - i Either add to _pkgdown.yml or use @keywords internal - -# fails if article index incomplete - - Code - check_pkgdown(pkg) - Condition - Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width - -# informs if everything is ok - - Code - check_pkgdown(pkg) - Message - No problems found - diff --git a/tests/testthat/_snaps/figure.md b/tests/testthat/_snaps/figure.md new file mode 100644 index 000000000..c6487fc6e --- /dev/null +++ b/tests/testthat/_snaps/figure.md @@ -0,0 +1,40 @@ +# can override defaults in _pkgdown.yml [plain] + + Code + build_reference(pkg, devel = FALSE) + +--- + + Code + build_articles(pkg) + +# can override defaults in _pkgdown.yml [ansi] + + Code + build_reference(pkg, devel = FALSE) + +--- + + Code + build_articles(pkg) + +# can override defaults in _pkgdown.yml [unicode] + + Code + build_reference(pkg, devel = FALSE) + +--- + + Code + build_articles(pkg) + +# can override defaults in _pkgdown.yml [fancy] + + Code + build_reference(pkg, devel = FALSE) + +--- + + Code + build_articles(pkg) + diff --git a/tests/testthat/_snaps/init.md b/tests/testthat/_snaps/init.md index 31a5e2518..efdf10d1a 100644 --- a/tests/testthat/_snaps/init.md +++ b/tests/testthat/_snaps/init.md @@ -1,12 +1,140 @@ -# site meta doesn't break unexpectedly - - pandoc: '{version}' - pkgdown: '{version}' - pkgdown_sha: '{sha}' - articles: {} - last_built: 2020-01-01T00:00Z - urls: - reference: http://test.org/reference - article: http://test.org/articles - +# extra.css and extra.js copied and linked [plain] + + Code + init_site(pkg) + +--- + + Code + build_home(pkg) + +# extra.css and extra.js copied and linked [ansi] + + Code + init_site(pkg) + +--- + + Code + build_home(pkg) + +# extra.css and extra.js copied and linked [unicode] + + Code + init_site(pkg) + +--- + + Code + build_home(pkg) + +# extra.css and extra.js copied and linked [fancy] + + Code + init_site(pkg) + +--- + + Code + build_home(pkg) + +# single extra.css correctly copied [plain] + + Code + init_site(pkg) + +# single extra.css correctly copied [ansi] + + Code + init_site(pkg) + +# single extra.css correctly copied [unicode] + + Code + init_site(pkg) + +# single extra.css correctly copied [fancy] + + Code + init_site(pkg) + +# asset subdirectories are copied [plain] + + Code + init_site(pkg) + +# asset subdirectories are copied [ansi] + + Code + init_site(pkg) + +# asset subdirectories are copied [unicode] + + Code + init_site(pkg) + +# asset subdirectories are copied [fancy] + + Code + init_site(pkg) + +# site meta doesn't break unexpectedly [plain] + + Code + yaml + Output + pandoc: '{version}' + pkgdown: '{version}' + pkgdown_sha: '{sha}' + articles: {} + last_built: 2020-01-01T00:00Z + urls: + reference: http://test.org/reference + article: http://test.org/articles + + +# site meta doesn't break unexpectedly [ansi] + + Code + yaml + Output + pandoc: '{version}' + pkgdown: '{version}' + pkgdown_sha: '{sha}' + articles: {} + last_built: 2020-01-01T00:00Z + urls: + reference: http://test.org/reference + article: http://test.org/articles + + +# site meta doesn't break unexpectedly [unicode] + + Code + yaml + Output + pandoc: '{version}' + pkgdown: '{version}' + pkgdown_sha: '{sha}' + articles: {} + last_built: 2020-01-01T00:00Z + urls: + reference: http://test.org/reference + article: http://test.org/articles + + +# site meta doesn't break unexpectedly [fancy] + + Code + yaml + Output + pandoc: '{version}' + pkgdown: '{version}' + pkgdown_sha: '{sha}' + articles: {} + last_built: 2020-01-01T00:00Z + urls: + reference: http://test.org/reference + article: http://test.org/articles + diff --git a/tests/testthat/_snaps/markdown.md b/tests/testthat/_snaps/markdown.md index 15d37dbfd..74d9b40c7 100644 --- a/tests/testthat/_snaps/markdown.md +++ b/tests/testthat/_snaps/markdown.md @@ -1,7 +1,4 @@ # markdown_text_inline() works with inline markdown - Can't use a block element in , need an inline element: - x - - y + Can't use a block element in ``, need an inline element: `x y` diff --git a/tests/testthat/_snaps/package.md b/tests/testthat/_snaps/package.md index a069241e7..1db0aa566 100644 --- a/tests/testthat/_snaps/package.md +++ b/tests/testthat/_snaps/package.md @@ -5,5 +5,5 @@ Condition Error in `check_bootstrap_version()`: ! Boostrap version must be 3 or 5. - x You specified a value of 1 in template.bootstrap. + x You specified a value of `1` in template.bootstrap. diff --git a/tests/testthat/_snaps/rd-example.md b/tests/testthat/_snaps/rd-example.md new file mode 100644 index 000000000..f88f1ccf5 --- /dev/null +++ b/tests/testthat/_snaps/rd-example.md @@ -0,0 +1,32 @@ +# @examplesIf [plain] + + Code + expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) + Condition + Warning: + @examplesIf condition `cond_expr_str` is FALSE + +# @examplesIf [ansi] + + Code + expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) + Condition + Warning: + @examplesIf condition `cond_expr_str` is FALSE + +# @examplesIf [unicode] + + Code + expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) + Condition + Warning: + @examplesIf condition `cond_expr_str` is FALSE + +# @examplesIf [fancy] + + Code + expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) + Condition + Warning: + @examplesIf condition `cond_expr_str` is FALSE + diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index bd153d0cb..b9fcbac86 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -1,7 +1,7 @@ -# subsection generates h3 +# subsection generates h3 [plain] Code - cat_line(rd2html("\\subsection{A}{B}")) + cli::cat_line(rd2html("\\subsection{A}{B}")) Output

A

@@ -11,7 +11,7 @@ --- Code - cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) + cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) Output

A

@@ -19,10 +19,112 @@

p2

-# nested subsection generates h4 +# subsection generates h3 [ansi] Code - cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) + cli::cat_line(rd2html("\\subsection{A}{B}")) + Output +
+

A

+

B

+
+ +--- + + Code + cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) + Output +
+

A

+

p1

+

p2

+
+ +# subsection generates h3 [unicode] + + Code + cli::cat_line(rd2html("\\subsection{A}{B}")) + Output +
+

A

+

B

+
+ +--- + + Code + cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) + Output +
+

A

+

p1

+

p2

+
+ +# subsection generates h3 [fancy] + + Code + cli::cat_line(rd2html("\\subsection{A}{B}")) + Output +
+

A

+

B

+
+ +--- + + Code + cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) + Output +
+

A

+

p1

+

p2

+
+ +# nested subsection generates h4 [plain] + + Code + cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) + Output +
+

H3

+
+

H4

+ +
+
+ +# nested subsection generates h4 [ansi] + + Code + cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) + Output +
+

H3

+
+

H4

+ +
+
+ +# nested subsection generates h4 [unicode] + + Code + cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) + Output +
+

H3

+
+

H4

+ +
+
+ +# nested subsection generates h4 [fancy] + + Code + cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) Output

H3

@@ -32,7 +134,47 @@
-# bad specs throw errors +# Sexprs with multiple args are parsed [plain] + + Code + rd2html("\\Sexpr[results=verbatim]{1}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `glue()`: + ! Expecting '}' + +# Sexprs with multiple args are parsed [ansi] + + Code + rd2html("\\Sexpr[results=verbatim]{1}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `glue()`: + ! Expecting '}' + +# Sexprs with multiple args are parsed [unicode] + + Code + rd2html("\\Sexpr[results=verbatim]{1}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `glue()`: + ! Expecting '}' + +# Sexprs with multiple args are parsed [fancy] + + Code + rd2html("\\Sexpr[results=verbatim]{1}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `glue()`: + ! Expecting '}' + +# bad specs throw errors [plain] Code rd2html("\\url{}") @@ -40,31 +182,133 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse \url{}. - i Check for empty \url{} tags. + ! Failed to parse tag `\url{}`. + x Check for empty \url{} tags. Code rd2html("\\url{a\nb}") Condition Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse \url{}. - i This may be caused by a \url tag that spans a line break. + ! Failed to parse tag `\url{}`. + x This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") Condition Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse \email{}. - i empty {} + ! Failed to parse tag `\email{}`. + x empty Code rd2html("\\linkS4class{}") Condition Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse \linkS4class{}. + ! Failed to parse tag `\linkS4class{}`. + +# bad specs throw errors [ansi] + + Code + rd2html("\\url{}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + x Check for empty \url{} tags. + Code + rd2html("\\url{a\nb}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + x This may be caused by a \url tag that spans a line break. + Code + rd2html("\\email{}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\email{}`. + x empty + Code + rd2html("\\linkS4class{}") + Condition + Error in `purrr::map_chr()`: + i In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\linkS4class{}`. + +# bad specs throw errors [unicode] + + Code + rd2html("\\url{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ Check for empty \url{} tags. + Code + rd2html("\\url{a\nb}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ This may be caused by a \url tag that spans a line break. + Code + rd2html("\\email{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\email{}`. + ✖ empty + Code + rd2html("\\linkS4class{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\linkS4class{}`. + +# bad specs throw errors [fancy] + + Code + rd2html("\\url{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ Check for empty \url{} tags. + Code + rd2html("\\url{a\nb}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\url{}`. + ✖ This may be caused by a \url tag that spans a line break. + Code + rd2html("\\email{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\email{}`. + ✖ empty + Code + rd2html("\\linkS4class{}") + Condition + Error in `purrr::map_chr()`: + ℹ In index: 1. + Caused by error in `stop_bad_tag()`: + ! Failed to parse tag `\linkS4class{}`. # \describe items can contain multiple paragraphs diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index 9886a9c8e..7fb106e7d 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -51,3 +51,23 @@ right:

Site built with pkgdown {version}.

+# can include text in header, before body, and after body [plain] + + Code + init_site(pkg) + +# can include text in header, before body, and after body [ansi] + + Code + init_site(pkg) + +# can include text in header, before body, and after body [unicode] + + Code + init_site(pkg) + +# can include text in header, before body, and after body [fancy] + + Code + init_site(pkg) + diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md index dfcebf315..5631a8c68 100644 --- a/tests/testthat/_snaps/rmarkdown.md +++ b/tests/testthat/_snaps/rmarkdown.md @@ -1,23 +1,108 @@ -# render_rmarkdown yields useful error +# render_rmarkdown copies image files in subdirectories [plain] + + Code + render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + +# render_rmarkdown copies image files in subdirectories [ansi] + + Code + render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + +# render_rmarkdown copies image files in subdirectories [unicode] + + Code + render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + +# render_rmarkdown copies image files in subdirectories [fancy] + + Code + render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + +# render_rmarkdown yields useful error [plain] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) Output - Reading 'assets/pandoc-fail.Rmd' - -- RMarkdown error ------------------------------------------------------------- [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. - -------------------------------------------------------------------------------- Condition - Error in `render_rmarkdown()`: - ! Failed to render RMarkdown - Caused by error: - ! in callr subprocess. - Caused by error: - ! pandoc document conversion failed with error 3 - -# render_rmarkdown styles ANSI escapes + Error in `value[[3L]]()`: + ! Failed to render RMarkdown document + +# render_rmarkdown yields useful error [ansi] + + Code + render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( + pandoc_args = "--fail-if-warnings")) + Output + [WARNING] Could not fetch resource path-to-image.png + Failing because there were warnings. + Condition + Error in `value[[3L]]()`: + ! Failed to render RMarkdown document + +# render_rmarkdown yields useful error [unicode] + + Code + render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( + pandoc_args = "--fail-if-warnings")) + Output + [WARNING] Could not fetch resource path-to-image.png + Failing because there were warnings. + Condition + Error in `value[[3L]]()`: + ! Failed to render RMarkdown document + +# render_rmarkdown yields useful error [fancy] + + Code + render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( + pandoc_args = "--fail-if-warnings")) + Output + [WARNING] Could not fetch resource path-to-image.png + Failing because there were warnings. + Condition + Error in `value[[3L]]()`: + ! Failed to render RMarkdown document + +# render_rmarkdown styles ANSI escapes [plain] + + Code + path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", + output = "test.html") + +--- + + #> X + +# render_rmarkdown styles ANSI escapes [ansi] + + Code + path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", + output = "test.html") + +--- + + #> X + +# render_rmarkdown styles ANSI escapes [unicode] + + Code + path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", + output = "test.html") + +--- + + #> X + +# render_rmarkdown styles ANSI escapes [fancy] + + Code + path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", + output = "test.html") + +--- #> X diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 330db5d0c..37cf72ac4 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -1,12 +1,96 @@ -# pkgdown_sitrep works +# pkgdown_sitrep works [plain] - * url in '_pkgdown.yml' not configured. + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + x url is not configured in '_pkgdown.yml'. See vignette `vignette(pkgdown::metatdata)`. + x 'DESCRIPTION' URL is empty. --- - * URL missing from the DESCRIPTION URL field. + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + x 'DESCRIPTION' URL is empty. --- - All good :-) + Code + pkgdown_sitrep(pkg) + +# pkgdown_sitrep works [ansi] + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + x url is not configured in _pkgdown.yml. See vignette `vignette(pkgdown::metatdata)`. + x DESCRIPTION URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + x DESCRIPTION URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) + +# pkgdown_sitrep works [unicode] + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + ✖ url is not configured in '_pkgdown.yml'. See vignette `vignette(pkgdown::metatdata)`. + ✖ 'DESCRIPTION' URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + ✖ 'DESCRIPTION' URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) + +# pkgdown_sitrep works [fancy] + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + ✖ url is not configured in _pkgdown.yml. See vignette `vignette(pkgdown::metatdata)`. + ✖ DESCRIPTION URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) + Condition + Warning: + pkgdown situation report: configuration error + ✖ DESCRIPTION URL is empty. + +--- + + Code + pkgdown_sitrep(pkg) diff --git a/tests/testthat/_snaps/topics-external.md b/tests/testthat/_snaps/topics-external.md index 6a2e8ed02..4584ff7d2 100644 --- a/tests/testthat/_snaps/topics-external.md +++ b/tests/testthat/_snaps/topics-external.md @@ -29,5 +29,5 @@ Error in `purrr::map2()`: i In index: 1. Caused by error in `.f()`: - ! Could not find documentation for base::doesntexist + ! Could not find documentation for `base::doesntexist()`. diff --git a/tests/testthat/_snaps/topics.md b/tests/testthat/_snaps/topics.md index 0a2c20ad1..db935a207 100644 --- a/tests/testthat/_snaps/topics.md +++ b/tests/testthat/_snaps/topics.md @@ -5,43 +5,41 @@ Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be valid R code - x Not 'x + ' + x Not `x + ` Code t <- select_topics("y", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not 'y' + x Not `y` Code t <- select_topics("paste(1)", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known selector function - x Not 'paste(1)' - Caused by error in `paste()`: - ! could not find function "paste" + x Not `paste(1)` Code t <- select_topics("starts_with", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not 'starts_with' + x Not `starts_with` Code t <- select_topics("1", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a string or function call - x Not '1' + x Not `1` Code t <- select_topics("starts_with('y')", topics, check = TRUE) Condition @@ -55,24 +53,24 @@ Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not 'a4' + x Not `a4` Code select_topics("c::a", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error: + Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not 'c::a' + x Not `c::a` # an unmatched selection generates a warning Code select_topics(c("a", "starts_with('unmatched')"), topics, check = TRUE) Condition - Error: + Error in `topic_must()`: ! In '_pkgdown.yml', topic must match a function or concept - x Not 'starts_with(\'unmatched\')' + x Not `starts_with('unmatched')` diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index 7573cb83f..80129eeb7 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -1,13 +1,49 @@ -# pkgdown_field(s) produces useful description +# pkgdown_field(s) produces useful description [plain] Code - pkgdown_field(pkg, c("a", "b")) + pkgdown_field(c("a", "b")) Output - [1] "a.b in '_pkgdown.yml'" + [1] "a.b" + +--- + + Code + check_yaml_has("x", where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x component in '_pkgdown.yml'. + Code + check_yaml_has(c("x", "y"), where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x and a.y components in '_pkgdown.yml'. + +# pkgdown_field(s) produces useful description [ansi] + Code - pkgdown_fields(pkg, list(c("a", "b"), "c")) + pkgdown_field(c("a", "b")) Output - [1] "a.b, c in '_pkgdown.yml'" + [1] "a.b" + +--- + + Code + check_yaml_has("x", where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x component in _pkgdown.yml. + Code + check_yaml_has(c("x", "y"), where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x and a.y components in _pkgdown.yml. + +# pkgdown_field(s) produces useful description [unicode] + + Code + pkgdown_field(c("a", "b")) + Output + [1] "a.b" --- @@ -15,10 +51,30 @@ check_yaml_has("x", where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find component a.x in '_pkgdown.yml'. + ! Can't find a.x component in '_pkgdown.yml'. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find components a.x, a.y in '_pkgdown.yml'. + ! Can't find a.x and a.y components in '_pkgdown.yml'. + +# pkgdown_field(s) produces useful description [fancy] + + Code + pkgdown_field(c("a", "b")) + Output + [1] "a.b" + +--- + + Code + check_yaml_has("x", where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x component in _pkgdown.yml. + Code + check_yaml_has(c("x", "y"), where = "a", pkg = pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find a.x and a.y components in _pkgdown.yml. diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 000000000..75010f6ee --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,3 @@ +# suppress cli messages in interactive testthat output +# https://github.com/r-lib/cli/issues/434 +options(cli.default_handler = function(...) { }) diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 250af53d3..3701091ce 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -10,8 +10,8 @@ test_that("links to man/figures are automatically relocated", { skip_on_cran() pkg <- local_pkgdown_site(test_path("assets/man-figures")) - expect_output(copy_figures(pkg)) - expect_output(build_articles(pkg, lazy = FALSE)) + expect_snapshot(copy_figures(pkg)) + expect_snapshot(build_articles(pkg, lazy = FALSE)) html <- xml2::read_html(path(pkg$dst_path, "articles", "kitten.html")) src <- xpath_attr(html, "//img", "src") @@ -26,7 +26,7 @@ test_that("links to man/figures are automatically relocated", { expect_false(dir_exists(path(pkg$dst_path, "man"))) }) -test_that("warns about missing images", { +cli::test_that_cli("warns about missing images", { pkg <- local_pkgdown_site(test_path("assets/bad-images")) expect_snapshot(build_articles(pkg)) }) @@ -35,7 +35,7 @@ test_that("articles don't include header-attrs.js script", { pkg <- as_pkgdown(test_path("assets/articles")) withr::defer(clean_site(pkg)) - expect_output(path <- build_article("standard", pkg)) + expect_snapshot(path <- build_article("standard", pkg)) html <- xml2::read_html(path) js <- xpath_attr(html, ".//body//script", "src") @@ -48,12 +48,12 @@ test_that("can build article that uses html_vignette", { pkg <- local_pkgdown_site(test_path("assets/articles")) # theme is not set since html_vignette doesn't support it - expect_output(expect_error(build_article("html-vignette", pkg), NA)) + expect_snapshot(expect_error(build_article("html-vignette", pkg), NA)) }) test_that("can override html_document() options", { pkg <- local_pkgdown_site(test_path("assets/articles")) - expect_output(path <- build_article("html-document", pkg)) + expect_snapshot(path <- build_article("html-document", pkg)) # Check that number_sections is respected html <- xml2::read_html(path) @@ -69,7 +69,7 @@ test_that("can override html_document() options", { test_that("html widgets get needed css/js", { pkg <- local_pkgdown_site(test_path("assets/articles")) - expect_output(path <- build_article("widget", pkg)) + expect_snapshot(path <- build_article("widget", pkg)) html <- xml2::read_html(path) css <- xpath_attr(html, ".//body//link", "href") @@ -81,7 +81,7 @@ test_that("html widgets get needed css/js", { test_that("can override options with _output.yml", { pkg <- local_pkgdown_site(test_path("assets/articles")) - expect_output(path <- build_article("html-document", pkg)) + expect_snapshot(path <- build_article("html-document", pkg)) # Check that number_sections is respected html <- xml2::read_html(path) @@ -94,7 +94,7 @@ test_that("can set width", { width: 50 ") - expect_output(path <- build_article("width", pkg)) + expect_snapshot(path <- build_article("width", pkg)) html <- xml2::read_html(path) expect_equal(xpath_text(html, ".//pre")[[2]], "## [1] 50") }) @@ -104,7 +104,7 @@ test_that("finds external resources referenced by R code in the article html", { skip_on_cran() pkg <- local_pkgdown_site(test_path("assets", "articles-resources")) - expect_output(path <- build_article("resources", pkg)) + expect_snapshot(path <- build_article("resources", pkg)) # ensure that we the HTML references `` directly expect_equal( @@ -124,9 +124,9 @@ test_that("BS5 article laid out correctly with and without TOC", { bootstrap: 5 ") - expect_output(init_site(pkg)) - expect_output(toc_true_path <- build_article("standard", pkg)) - expect_output(toc_false_path <- build_article("toc-false", pkg)) + expect_snapshot(init_site(pkg)) + expect_snapshot(toc_true_path <- build_article("standard", pkg)) + expect_snapshot(toc_false_path <- build_article("toc-false", pkg)) toc_true <- xml2::read_html(toc_true_path) toc_false <- xml2::read_html(toc_false_path) @@ -145,7 +145,7 @@ test_that("articles in vignettes/articles/ are unnested into articles/", { skip_on_cran() pkg <- local_pkgdown_site(test_path("assets/articles")) - expect_output(path <- build_article("articles/nested", pkg)) + expect_snapshot(path <- build_article("articles/nested", pkg)) expect_equal( normalizePath(path), @@ -154,7 +154,7 @@ test_that("articles in vignettes/articles/ are unnested into articles/", { # Check automatic redirect from articles/articles/foo.html -> articles/foo.html pkg$meta$url <- "https://example.com" - expect_output(build_redirects(pkg)) + expect_snapshot(build_redirects(pkg)) # Check that the redirect file exists in /articles/articles/ redirect_path <- path(pkg$dst_path, "articles", "articles", "nested.html") @@ -175,8 +175,8 @@ test_that("pkgdown deps are included only once in articles", { bootstrap: 5 ") - expect_output(init_site(pkg)) - expect_output(path <- build_article("html-deps", pkg)) + expect_snapshot(init_site(pkg)) + expect_snapshot(path <- build_article("html-deps", pkg)) html <- xml2::read_html(path) diff --git a/tests/testthat/test-build-favicons.R b/tests/testthat/test-build-favicons.R index 4990401fd..dbc1cea90 100644 --- a/tests/testthat/test-build-favicons.R +++ b/tests/testthat/test-build-favicons.R @@ -2,7 +2,7 @@ test_that("missing logo generates message", { pkg <- local_pkgdown_site(test_path("assets/site-empty")) expect_error( - expect_output(build_favicons(pkg)), + expect_snapshot(build_favicons(pkg)), "Can't find package logo" ) }) diff --git a/tests/testthat/test-build-github.R b/tests/testthat/test-build-github.R index 23dd0e5dc..bbb90ddd1 100644 --- a/tests/testthat/test-build-github.R +++ b/tests/testthat/test-build-github.R @@ -2,7 +2,7 @@ test_that("a CNAME record is built if a url exists in metadata", { pkg <- local_pkgdown_site(test_path("assets/cname")) dir_create(path(pkg$dst_path, "docs")) - expect_output(build_github_pages(pkg)) + expect_snapshot(build_github_pages(pkg)) expect_equal(read_lines(path(pkg$dst_path, "CNAME")), "testpackage.r-lib.org") }) diff --git a/tests/testthat/test-build-home-authors.R b/tests/testthat/test-build-home-authors.R index 0eb6cd332..a6c2445b8 100644 --- a/tests/testthat/test-build-home-authors.R +++ b/tests/testthat/test-build-home-authors.R @@ -55,7 +55,7 @@ test_that("data_home_sidebar_authors() works with text", { expect_snapshot(cat(data_home_sidebar_authors(pkg))) }) -test_that("role has multiple fallbacks", { +cli::test_that_cli("role has multiple fallbacks", { expect_equal(role_lookup("cre"), "maintainer") expect_equal(role_lookup("res"), "researcher") expect_snapshot(role_lookup("unknown")) diff --git a/tests/testthat/test-build-home-citation.R b/tests/testthat/test-build-home-citation.R index d3ae147e9..cf369c151 100644 --- a/tests/testthat/test-build-home-citation.R +++ b/tests/testthat/test-build-home-citation.R @@ -23,7 +23,7 @@ test_that("create_meta can read DESCRIPTION with an Encoding", { test_that("source link is added to citation page", { pkg <- local_pkgdown_site(test_path("assets/site-citation/encoding-UTF-8")) - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) lines <- read_lines(path(pkg$dst_path, "authors.html")) expect_true(any(grepl("inst/CITATION", lines))) diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index 141547a69..b2e1b6e9c 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -12,7 +12,7 @@ test_that("version formatting in preserved", { pkg <- local_pkgdown_site(test_path("assets/version-formatting")) expect_equal(pkg$version, "1.0.0-9000") - expect_output(init_site(pkg)) + expect_snapshot(init_site(pkg)) build_home_index(pkg, quiet = TRUE) index <- read_lines(path(pkg$dst_path, "index.html")) expect_true(any(grepl("1.0.0-9000", index, fixed = TRUE))) diff --git a/tests/testthat/test-build-home.R b/tests/testthat/test-build-home.R index 4299e6e61..4bf483e2c 100644 --- a/tests/testthat/test-build-home.R +++ b/tests/testthat/test-build-home.R @@ -4,7 +4,7 @@ test_that("intermediate files cleaned up automatically", { skip_if_no_pandoc() pkg <- local_pkgdown_site(test_path("assets/home-index-rmd")) - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) expect_setequal(dir(pkg$src_path), c("DESCRIPTION", "index.Rmd")) }) @@ -13,7 +13,7 @@ test_that("intermediate files cleaned up automatically", { skip_if_no_pandoc() pkg <- local_pkgdown_site(test_path("assets/home-readme-rmd")) - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) expect_setequal( dir(pkg$src_path), @@ -21,7 +21,7 @@ test_that("intermediate files cleaned up automatically", { ) }) -test_that("warns about missing images", { +cli::test_that_cli("warns about missing images", { pkg <- local_pkgdown_site(test_path("assets/bad-images")) expect_snapshot(build_home(pkg)) }) @@ -30,7 +30,7 @@ test_that("can build site even if no Authors@R present", { skip_if_no_pandoc() pkg <- local_pkgdown_site(test_path("assets/home-old-skool")) - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) }) # .github files ----------------------------------------------------------- @@ -42,7 +42,7 @@ test_that(".github files are copied and linked", { skip_if_not(dir_exists(test_path("assets/site-dot-github/.github"))) pkg <- local_pkgdown_site(test_path("assets/site-dot-github")) - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) lines <- read_lines(path(pkg$dst_path, "index.html")) expect_true(any(grepl('href="CODE_OF_CONDUCT.html"', lines))) diff --git a/tests/testthat/test-build-logo.R b/tests/testthat/test-build-logo.R index b0d027bdc..8737b0b11 100644 --- a/tests/testthat/test-build-logo.R +++ b/tests/testthat/test-build-logo.R @@ -1,4 +1,4 @@ -test_that("can handle logo in subdir", { +cli::test_that_cli("can handle logo in subdir", { src <- withr::local_tempdir() dst <- withr::local_tempdir() diff --git a/tests/testthat/test-build-news.R b/tests/testthat/test-build-news.R index 64fe95269..15921fa45 100644 --- a/tests/testthat/test-build-news.R +++ b/tests/testthat/test-build-news.R @@ -24,7 +24,7 @@ test_that("data_news works as expected for h1 & h2", { }) -test_that("multi-page news are rendered", { +cli::test_that_cli("multi-page news are rendered", { skip_if_no_pandoc() pkg <- local_pkgdown_site(meta = " @@ -45,8 +45,8 @@ test_that("multi-page news are rendered", { "* second thing" )) - expect_snapshot_output(data_news(pkg)[c("version", "page", "anchor")]) - expect_output(build_news(pkg)) + expect_snapshot(data_news(pkg)[c("version", "page", "anchor")]) + expect_snapshot(build_news(pkg)) # test that index links are correct lines <- read_lines(path(pkg$dst_path, "news", "index.html")) diff --git a/tests/testthat/test-build-reference-index.R b/tests/testthat/test-build-reference-index.R index 562a02c88..5806e28e1 100644 --- a/tests/testthat/test-build-reference-index.R +++ b/tests/testthat/test-build-reference-index.R @@ -72,27 +72,27 @@ test_that("errors well when a content entry is empty", { expect_snapshot_error(build_reference_index(pkg)) }) -test_that("errors well when a content entry is not a character", { +cli::test_that_cli("errors well when a content entry is not a character", { meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - aname\n - N") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) - expect_snapshot_error(build_reference_index(pkg)) + expect_snapshot(build_reference_index(pkg), error = TRUE) }) -test_that("errors well when a content entry refers to a not installed package", { +cli::test_that_cli("errors well when a content entry refers to a not installed package", { skip_if_not_installed("cli", "3.1.0") meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - notapackage::lala") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) - expect_snapshot_error(build_reference_index(pkg)) + expect_snapshot(build_reference_index(pkg), error = TRUE) }) -test_that("errors well when a content entry refers to a non existing function", { +cli::test_that_cli("errors well when a content entry refers to a non existing function", { meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - rlang::lala") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) - expect_snapshot_error(build_reference_index(pkg)) + expect_snapshot(build_reference_index(pkg), error = TRUE) }) test_that("can exclude topics", { diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index 029065c4f..de81ebe25 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -1,4 +1,4 @@ -test_that("parse failures include file name", { +cli::test_that_cli("parse failures include file name", { skip_if_not(getRversion() >= "4.0.0") pkg <- local_pkgdown_site("assets/reference-fail") expect_snapshot(build_reference(pkg), error = TRUE) @@ -30,9 +30,9 @@ test_that("examples_env sets width", { }) -test_that("test usage ok on rendered page", { +cli::test_that_cli("test usage ok on rendered page", { pkg <- local_pkgdown_site(test_path("assets/reference")) - expect_output(build_reference(pkg, topics = "c")) + expect_snapshot(build_reference(pkg, topics = "c")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) expect_equal(xpath_text(html, "//div[@id='ref-usage']", trim = TRUE), "c()") clean_site(pkg) @@ -41,16 +41,16 @@ test_that("test usage ok on rendered page", { template: bootstrap: 5 ") - expect_output(init_site(pkg)) - expect_output(build_reference(pkg, topics = "c")) + expect_snapshot(init_site(pkg)) + expect_snapshot(build_reference(pkg, topics = "c")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) # tweak_anchors() moves id into

expect_equal(xpath_text(html, "//div[h2[@id='ref-usage']]/div", trim = TRUE), "c()") }) -test_that(".Rd without usage doesn't get Usage section", { +cli::test_that_cli(".Rd without usage doesn't get Usage section", { pkg <- local_pkgdown_site(test_path("assets/reference")) - expect_output(build_reference(pkg, topics = "e")) + expect_snapshot(build_reference(pkg, topics = "e")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "e.html")) expect_equal(xpath_length(html, "//div[@id='ref-usage']"), 0) clean_site(pkg) @@ -59,8 +59,8 @@ test_that(".Rd without usage doesn't get Usage section", { template: bootstrap: 5 ") - expect_output(init_site(pkg)) - expect_output(build_reference(pkg, topics = "e")) + expect_snapshot(init_site(pkg)) + expect_snapshot(build_reference(pkg, topics = "e")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "e.html")) # tweak_anchors() moves id into

expect_equal(xpath_length(html, "//div[h2[@id='ref-usage']]"), 0) @@ -68,8 +68,8 @@ test_that(".Rd without usage doesn't get Usage section", { test_that("pkgdown html dependencies are suppressed from examples in references", { pkg <- local_pkgdown_site(test_path("assets/reference-html-dep")) - expect_output(init_site(pkg)) - expect_output(build_reference(pkg, topics = "a")) + expect_snapshot(init_site(pkg)) + expect_snapshot(build_reference(pkg, topics = "a")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "a.html")) # jquery is only loaded once, even though it's included by an example diff --git a/tests/testthat/test-build-search-docs.R b/tests/testthat/test-build-search-docs.R index f39b4f1f6..4fa477cda 100644 --- a/tests/testthat/test-build-search-docs.R +++ b/tests/testthat/test-build-search-docs.R @@ -1,7 +1,7 @@ test_that("docsearch.json and sitemap.xml are valid", { pkg <- local_pkgdown_site(test_path("assets/search-site")) - expect_output(build_site(pkg, new_process = FALSE)) + expect_snapshot(build_site(pkg, new_process = FALSE)) json <- path(pkg$dst_path, "docsearch.json") expect_true(jsonlite::validate(read_lines(json))) @@ -21,10 +21,10 @@ test_that("build_search() builds the expected search`.json with an URL", { mode: devel ') - expect_output(init_site(pkg)) - expect_output(build_news(pkg)) - expect_output(build_home(pkg)) - expect_output(build_sitemap(pkg)) + expect_snapshot(init_site(pkg)) + expect_snapshot(build_news(pkg)) + expect_snapshot(build_home(pkg)) + expect_snapshot(build_sitemap(pkg)) json_path <- withr::local_tempfile() jsonlite::write_json(build_search_index(pkg), json_path, pretty = TRUE) @@ -41,10 +41,10 @@ test_that("build_search() builds the expected search.json with no URL", { mode: devel ') - expect_output(init_site(pkg)) - expect_output(build_news(pkg)) - expect_output(build_home(pkg)) - expect_output(build_sitemap(pkg)) + expect_snapshot(init_site(pkg)) + expect_snapshot(build_news(pkg)) + expect_snapshot(build_home(pkg)) + expect_snapshot(build_sitemap(pkg)) json_path <- withr::local_tempfile() jsonlite::write_json(build_search_index(pkg), json_path, pretty = TRUE) diff --git a/tests/testthat/test-check.R b/tests/testthat/test-check.R index 8dcfc6cfb..796ddf33e 100644 --- a/tests/testthat/test-check.R +++ b/tests/testthat/test-check.R @@ -1,4 +1,4 @@ -test_that("fails if reference index incomplete", { +cli::test_that_cli("fails if reference index incomplete", { pkg <- local_pkgdown_site(test_path("assets/reference"), meta = " reference: - title: Title @@ -8,7 +8,7 @@ test_that("fails if reference index incomplete", { }) -test_that("fails if article index incomplete", { +cli::test_that_cli("fails if article index incomplete", { pkg <- local_pkgdown_site(test_path("assets/articles"), meta = " articles: - title: Title @@ -17,7 +17,7 @@ test_that("fails if article index incomplete", { expect_snapshot(check_pkgdown(pkg), error = TRUE) }) -test_that("informs if everything is ok", { +cli::test_that_cli("informs if everything is ok", { pkg <- local_pkgdown_site(test_path("assets/reference")) expect_snapshot(check_pkgdown(pkg)) }) diff --git a/tests/testthat/test-figure.R b/tests/testthat/test-figure.R index 5be80c383..0ac81796b 100644 --- a/tests/testthat/test-figure.R +++ b/tests/testthat/test-figure.R @@ -1,4 +1,4 @@ -test_that("can override defaults in _pkgdown.yml", { +cli::test_that_cli("can override defaults in _pkgdown.yml", { skip_if_no_pandoc() withr::local_temp_libpaths() @@ -6,11 +6,11 @@ test_that("can override defaults in _pkgdown.yml", { callr::rcmd("INSTALL", pkg$src_path, show = FALSE, fail_on_status = TRUE) - expect_output(build_reference(pkg, devel = FALSE)) + expect_snapshot(build_reference(pkg, devel = FALSE)) img <- path_file(dir_ls(path(pkg$dst_path, "reference"), glob = "*.jpg")) expect_setequal(img, c("figure-1.jpg", "figure-2.jpg")) - expect_output(build_articles(pkg)) + expect_snapshot(build_articles(pkg)) img <- path_file(dir_ls(path(pkg$dst_path, "articles"), glob = "*.jpg", recurse = TRUE)) expect_equal(img, "unnamed-chunk-1-1.jpg") }) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 9f4a9cc91..c1595c6e0 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -1,13 +1,13 @@ -test_that("extra.css and extra.js copied and linked", { +cli::test_that_cli("extra.css and extra.js copied and linked", { pkg <- local_pkgdown_site(test_path("assets/init-extra-2")) - expect_output(init_site(pkg)) + expect_snapshot(init_site(pkg)) expect_true(file_exists(path(pkg$dst_path, "extra.css"))) expect_true(file_exists(path(pkg$dst_path, "extra.js"))) skip_if_no_pandoc() # Now check they actually get used . - expect_output(build_home(pkg)) + expect_snapshot(build_home(pkg)) html <- xml2::read_html(path(pkg$dst_path, "index.html")) paths <- xpath_attr(html, ".//link", "href") @@ -15,22 +15,22 @@ test_that("extra.css and extra.js copied and linked", { expect_true("extra.css" %in% paths) }) -test_that("single extra.css correctly copied", { +cli::test_that_cli("single extra.css correctly copied", { pkg <- local_pkgdown_site(test_path("assets/init-extra-1")) - expect_output(init_site(pkg)) + expect_snapshot(init_site(pkg)) expect_true(file_exists(path(pkg$dst_path, "extra.css"))) }) -test_that("asset subdirectories are copied", { +cli::test_that_cli("asset subdirectories are copied", { pkg <- local_pkgdown_site(test_path("assets/init-asset-subdirs")) - expect_output(init_site(pkg)) + expect_snapshot(init_site(pkg)) expect_true(file_exists(path(pkg$dst_path, "subdir1", "file1.txt"))) expect_true(file_exists(path(pkg$dst_path, "subdir1", "subdir2", "file2.txt"))) }) -test_that("site meta doesn't break unexpectedly", { +cli::test_that_cli("site meta doesn't break unexpectedly", { pkgdown <- as_pkgdown(test_path("assets/reference")) # null out components that will vary @@ -40,5 +40,5 @@ test_that("site meta doesn't break unexpectedly", { yaml$pandoc <- "{version}" yaml$last_built <- timestamp(as.POSIXct("2020-01-01", tz = "UTC")) - expect_snapshot_output(yaml) + expect_snapshot(yaml) }) diff --git a/tests/testthat/test-rd-example.R b/tests/testthat/test-rd-example.R index c53cd7511..229d900e6 100644 --- a/tests/testthat/test-rd-example.R +++ b/tests/testthat/test-rd-example.R @@ -51,7 +51,7 @@ test_that("extracts conditions from if", { expect_equal(rd2ex("\\ifelse{latex}{1 + 2}{3 + 4}"), "3 + 4") }) -test_that("@examplesIf", { +cli::test_that_cli("@examplesIf", { rd <- paste0( "\\dontshow{if (1 == 0) (if (getRversion() >= \"3.4\") withAutoprint else force)(\\{ # examplesIf}\n", "answer <- 43\n", @@ -88,8 +88,7 @@ test_that("@examplesIf", { "answer <- 43", "}" ) - expect_no_error(expect_warning( - expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)), - "is FALSE" - )) + expect_snapshot( + expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) + ) }) diff --git a/tests/testthat/test-rd-html.R b/tests/testthat/test-rd-html.R index 98a240729..f98d7acf3 100644 --- a/tests/testthat/test-rd-html.R +++ b/tests/testthat/test-rd-html.R @@ -24,11 +24,12 @@ test_that("simple wrappers work as expected", { expect_equal(rd2html("\\strong{\\emph{x}}"), "x") }) -test_that("subsection generates h3", { - expect_snapshot(cat_line(rd2html("\\subsection{A}{B}"))) +cli::test_that_cli("subsection generates h3", { + expect_snapshot(cli::cat_line(rd2html("\\subsection{A}{B}"))) }) -test_that("subsection generates h3", { - expect_snapshot(cat_line(rd2html("\\subsection{A}{ + +cli::test_that_cli("subsection generates h3", { + expect_snapshot(cli::cat_line(rd2html("\\subsection{A}{ p1 p2 @@ -44,8 +45,8 @@ test_that("subsection generates generated anchor", { expect_equal(xpath_attr(html, ".//a", "href"), "#a") }) -test_that("nested subsection generates h4", { - expect_snapshot(cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}"))) +cli::test_that_cli("nested subsection generates h4", { + expect_snapshot(cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}"))) }) test_that("if generates html", { @@ -170,9 +171,9 @@ test_that("Sexprs with multiple args are parsed", { expect_equal(rd2html("\\Sexpr[results=hide,stage=build]{1}"), character()) }) -test_that("Sexprs with multiple args are parsed", { +cli::test_that_cli("Sexprs with multiple args are parsed", { local_context_eval() - expect_error(rd2html("\\Sexpr[results=verbatim]{1}"), "not yet supported") + expect_snapshot(rd2html("\\Sexpr[results=verbatim]{1}"), error = TRUE) }) test_that("Sexprs in file share environment", { @@ -277,7 +278,7 @@ test_that("link to non-existing functions return label", { expect_equal(rd2html("\\linkS4class{TEST}"), "TEST") }) -test_that("bad specs throw errors", { +cli::test_that_cli("bad specs throw errors", { expect_snapshot(error = TRUE, { rd2html("\\url{}") rd2html("\\url{a\nb}") diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 77e5316b2..13aceb748 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -12,7 +12,7 @@ test_that("capture data_template()", { expect_snapshot_output(data) }) -test_that("can include text in header, before body, and after body", { +cli::test_that_cli("can include text in header, before body, and after body", { pkg <- local_pkgdown_site(test_path("assets/site-empty"), ' template: includes: @@ -34,7 +34,7 @@ test_that("can include text in header, before body, and after body", { ) pkg$bs_version <- 5 - expect_output(init_site(pkg)) + expect_snapshot(init_site(pkg)) html <- render_page_html(pkg, "title-body") expect_equal( xpath_text(html, ".//test"), diff --git a/tests/testthat/test-rmarkdown.R b/tests/testthat/test-rmarkdown.R index c0ffe732d..4bee49382 100644 --- a/tests/testthat/test-rmarkdown.R +++ b/tests/testthat/test-rmarkdown.R @@ -1,9 +1,9 @@ -test_that("render_rmarkdown copies image files in subdirectories", { +cli::test_that_cli("render_rmarkdown copies image files in subdirectories", { skip_if_no_pandoc() tmp <- dir_create(file_temp()) pkg <- list(src_path = test_path("."), dst_path = tmp, bs_version = 3) - expect_output( + expect_snapshot( render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") ) expect_equal( @@ -12,7 +12,7 @@ test_that("render_rmarkdown copies image files in subdirectories", { ) }) -test_that("render_rmarkdown yields useful error", { +cli::test_that_cli("render_rmarkdown yields useful error", { skip_on_cran() # fragile due to pandoc dependency skip_if_no_pandoc("2.18") @@ -25,12 +25,12 @@ test_that("render_rmarkdown yields useful error", { }) }) -test_that("render_rmarkdown styles ANSI escapes", { +cli::test_that_cli("render_rmarkdown styles ANSI escapes", { skip_if_no_pandoc() tmp <- dir_create(file_temp()) pkg <- list(src_path = test_path("."), dst_path = tmp, bs_version = 5) - expect_output({ + expect_snapshot({ path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", output = "test.html" diff --git a/tests/testthat/test-sitrep.R b/tests/testthat/test-sitrep.R index bae4e8d7f..a488ae565 100644 --- a/tests/testthat/test-sitrep.R +++ b/tests/testthat/test-sitrep.R @@ -1,11 +1,11 @@ -test_that("pkgdown_sitrep works", { +cli::test_that_cli("pkgdown_sitrep works", { # URL not in the pkgdown config pkg <- test_path("assets/figure") - expect_snapshot_output(pkgdown_sitrep(pkg)) + expect_snapshot(pkgdown_sitrep(pkg)) # URL only in the pkgdown config pkg <- test_path("assets/cname") - expect_snapshot_output(pkgdown_sitrep(pkg)) + expect_snapshot(pkgdown_sitrep(pkg)) # URL everywhere pkg <- test_path("assets/open-graph") - expect_snapshot_output(pkgdown_sitrep(pkg)) + expect_snapshot(pkgdown_sitrep(pkg)) }) diff --git a/tests/testthat/test-utils-yaml.R b/tests/testthat/test-utils-yaml.R index ebf8d2d7a..23646d227 100644 --- a/tests/testthat/test-utils-yaml.R +++ b/tests/testthat/test-utils-yaml.R @@ -1,16 +1,10 @@ -test_that("pkgdown_field(s) produces useful description", { +cli::test_that_cli("pkgdown_field(s) produces useful description", { pkg <- local_pkgdown_site() file_touch(file.path(pkg$src_path, "_pkgdown.yml")) expect_snapshot({ - pkgdown_field(pkg, c("a", "b")) - pkgdown_fields(pkg, list(c("a", "b"), "c")) + pkgdown_field(c("a", "b")) }) -}) - -test_that("pkgdown_field(s) produces useful description", { - pkg <- local_pkgdown_site() - file_touch(file.path(pkg$src_path, "_pkgdown.yml")) expect_snapshot(error = TRUE, { check_yaml_has("x", where = "a", pkg = pkg) From 84605c44b98eb5f885bb2276084b7039fc92c7d1 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 13:49:45 -0700 Subject: [PATCH 08/20] improve rmarkdown rendering error --- R/build-redirects.R | 2 +- R/rmarkdown.R | 3 ++- tests/testthat/_snaps/rmarkdown.md | 20 ++++++++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/R/build-redirects.R b/R/build-redirects.R index 30d1f843b..6375445da 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -13,7 +13,7 @@ build_redirects <- function(pkg = ".", cli::cli_h2("Building redirects") if (is.null(pkg$meta$url)) { - cli::cli_abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url"))) + cli::cli_abort("{.field {pkgdown_field('url')}} in {.file {pkgdown_config_relpath(pkg)}} required to generate redirects") } purrr::iwalk( diff --git a/R/rmarkdown.R b/R/rmarkdown.R index be87e44c1..da558faf9 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -40,7 +40,8 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet error = function(cnd) { cli::cli_abort(c( "Failed to render RMarkdown document", - "x" = cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) + "x" = cnd$parent$message, + "x" = cnd$stderr )) } ) diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md index 5631a8c68..c2d273c59 100644 --- a/tests/testthat/_snaps/rmarkdown.md +++ b/tests/testthat/_snaps/rmarkdown.md @@ -23,48 +23,44 @@ Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) - Output - [WARNING] Could not fetch resource path-to-image.png - Failing because there were warnings. Condition Error in `value[[3L]]()`: ! Failed to render RMarkdown document + x pandoc document conversion failed with error 3 + x [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. # render_rmarkdown yields useful error [ansi] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) - Output - [WARNING] Could not fetch resource path-to-image.png - Failing because there were warnings. Condition Error in `value[[3L]]()`: ! Failed to render RMarkdown document + x pandoc document conversion failed with error 3 + x [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. # render_rmarkdown yields useful error [unicode] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) - Output - [WARNING] Could not fetch resource path-to-image.png - Failing because there were warnings. Condition Error in `value[[3L]]()`: ! Failed to render RMarkdown document + ✖ pandoc document conversion failed with error 3 + ✖ [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. # render_rmarkdown yields useful error [fancy] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) - Output - [WARNING] Could not fetch resource path-to-image.png - Failing because there were warnings. Condition Error in `value[[3L]]()`: ! Failed to render RMarkdown document + ✖ pandoc document conversion failed with error 3 + ✖ [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. # render_rmarkdown styles ANSI escapes [plain] From 869d9c7cf66b6a442b99b5004324477249c9762d Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 16:05:45 -0700 Subject: [PATCH 09/20] fix rd test --- R/rd-html.R | 2 +- tests/testthat/_snaps/rd-html.md | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/R/rd-html.R b/R/rd-html.R index 397fef055..a3d46c021 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -229,7 +229,7 @@ as_html.tag_Sexpr <- function(x, ...) { text = as.character(res), rd = flatten_text(rd_text(as.character(res))), hide = "", - cli::cli_abort("\\Sexpr{result=", results, "} not yet supported") + cli::cli_abort("\\\\Sexpr{{result={results}}} not yet supported") ) } diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index b9fcbac86..1a7e5612f 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -141,8 +141,8 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `glue()`: - ! Expecting '}' + Caused by error in `.f()`: + ! \\Sexpr{result=verbatim} not yet supported # Sexprs with multiple args are parsed [ansi] @@ -151,8 +151,8 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `glue()`: - ! Expecting '}' + Caused by error in `.f()`: + ! \\Sexpr{result=verbatim} not yet supported # Sexprs with multiple args are parsed [unicode] @@ -161,8 +161,8 @@ Condition Error in `purrr::map_chr()`: ℹ In index: 1. - Caused by error in `glue()`: - ! Expecting '}' + Caused by error in `.f()`: + ! \\Sexpr{result=verbatim} not yet supported # Sexprs with multiple args are parsed [fancy] @@ -171,8 +171,8 @@ Condition Error in `purrr::map_chr()`: ℹ In index: 1. - Caused by error in `glue()`: - ! Expecting '}' + Caused by error in `.f()`: + ! \\Sexpr{result=verbatim} not yet supported # bad specs throw errors [plain] From fd791dd214b9f5af84ea041d3622c868ae86cf1f Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 16:05:59 -0700 Subject: [PATCH 10/20] Add news bullet --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f353ab075..c39a678cd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Use [cli](https://github.com/r-lib/cli) to provide interactive feedback. * Preserve Markdown code blocks with class rmd from roxygen2 docs (@salim-b, #2298). * Avoid unwanted linebreaks from parsing `DESCRIPTION` (@salim-b, #2247). * Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302) From e33830aa8c27710ae890f87c2b4b5f3564d58c1a Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Sun, 26 Nov 2023 16:32:20 -0700 Subject: [PATCH 11/20] skip test on old r versions --- tests/testthat/test-rd-html.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-rd-html.R b/tests/testthat/test-rd-html.R index f98d7acf3..1ebb705f6 100644 --- a/tests/testthat/test-rd-html.R +++ b/tests/testthat/test-rd-html.R @@ -172,6 +172,7 @@ test_that("Sexprs with multiple args are parsed", { }) cli::test_that_cli("Sexprs with multiple args are parsed", { + skip_if_not(getRversion() >= "4.0.0") local_context_eval() expect_snapshot(rd2html("\\Sexpr[results=verbatim]{1}"), error = TRUE) }) From 0b1f01536b93e37cbdfbc86e86f024b2653f9c7e Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Mon, 27 Nov 2023 06:40:18 -0700 Subject: [PATCH 12/20] tweak a few outputs and update snaps --- R/build-reference.R | 2 +- R/package.R | 2 +- R/rd-example.R | 10 ++++---- R/rd-html.R | 2 +- R/render.R | 12 ++++----- R/templates.R | 3 ++- R/theme.R | 13 +++++----- R/topics.R | 11 +++++--- R/usage.R | 6 ++--- tests/testthat/_snaps/build-reference.md | 8 +++--- tests/testthat/_snaps/package.md | 2 +- tests/testthat/_snaps/rd-example.md | 8 +++--- tests/testthat/_snaps/rd-html.md | 32 ++++++++++++------------ tests/testthat/_snaps/render.md | 3 ++- tests/testthat/_snaps/topics.md | 16 ++++++------ tests/testthat/test-render.R | 7 +++--- 16 files changed, 72 insertions(+), 65 deletions(-) diff --git a/R/build-reference.R b/R/build-reference.R index d6aa69d8e..6925260ac 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -162,7 +162,7 @@ build_reference <- function(pkg = ".", pkg <- section_init(pkg, depth = 1L, override = override) if (!missing(document)) { - cli::cli_warn("{.var document}is deprecated. Please use {.var devel} instead.") + cli::cli_warn("{.var document} is deprecated. Please use {.var devel} instead.") devel <- document } diff --git a/R/package.R b/R/package.R index b80dc3cd3..90e7f241b 100644 --- a/R/package.R +++ b/R/package.R @@ -106,7 +106,7 @@ check_bootstrap_version <- function(version, pkg = list()) { field <- pkgdown_field(c("template", "bootstrap")) cli::cli_abort(c( "Boostrap version must be 3 or 5.", - "x" = "You specified a value of {.var {version}} in {.field {field}}." + "x" = "You specified a value of {.val {version}} in {.field {field}}." )) } } diff --git a/R/rd-example.R b/R/rd-example.R index 25180bd45..4c025ab8d 100644 --- a/R/rd-example.R +++ b/R/rd-example.R @@ -29,7 +29,7 @@ run_examples <- function(x, code <- flatten_ex(x, run_dont_run = run_dont_run) if (!can_parse(code)) { - cli::cli_warn("Failed to parse example for topic {.var {topic}}") + cli::cli_warn("Failed to parse example for topic {.val {topic}}") return("") } @@ -65,7 +65,7 @@ process_conditional_examples <- function(rd) { if (!is_false) { new_cond <- paste0("if (FALSE) { # ", cond_expr_str) cli::cli_warn( - "@examplesIf condition {.var cond_expr_str} is FALSE" + "@examplesIf condition {.val {cond_expr_str}} is {.val FALSE}" ) } else { new_cond <- "if (FALSE) {" @@ -111,8 +111,8 @@ as_example.COMMENT <- function(x, run_dont_run = FALSE) { meant <- gsub("%", "\\\\%", x) xun <- unclass(x) cli::cli_warn(c( - "In the examples, {.var {xun}} is an Rd comment", - "x" = "did you mean {.var {meant}}?" + "In the examples, {.val {xun}} is an Rd comment", + "x" = "did you mean {.val {meant}}?" )) } "" @@ -155,7 +155,7 @@ block_tag_to_comment <- function(tag, x, run_dont_run = FALSE) { #' @export as_example.tag <- function(x, run_dont_run = FALSE) { untag <- paste(class(x), collapse = "/") - cli::cli_warn("Unknown tag: {.var {untag}}") + cli::cli_warn("Unknown tag: {.val {untag}}") } #' @export diff --git a/R/rd-html.R b/R/rd-html.R index a3d46c021..15e0cf6c3 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -566,7 +566,7 @@ parse_opts <- function(string) { stop_bad_tag <- function(tag, msg = NULL) { bad_tag <- paste0("\\", tag, "{}") - msg_abort <- 'Failed to parse tag {.var {bad_tag}}.' + msg_abort <- 'Failed to parse tag {.val {bad_tag}}.' if (!is.null(msg)) { msg_abort <- c(msg_abort, "x" = msg) } diff --git a/R/render.R b/R/render.R index c01e44bdc..542ff411c 100644 --- a/R/render.R +++ b/R/render.R @@ -149,27 +149,27 @@ data_open_graph <- function(pkg = ".") { check_open_graph <- function(og) { if (!is.list(og)) { fog <- friendly_type_of(og) - cli::cli_abort("{.var opengraph} must be a list, not {.var fog}") + cli::cli_abort("{.var opengraph} must be a list, not {.val fog}") } supported_fields <- c("image", "twitter") unsupported_fields <- setdiff(names(og), supported_fields) if (length(unsupported_fields)) { cli::cli_warn( - "Unsupported `opengraph` field{?s}: {unsupported_fields}." + "Unsupported {.var opengraph} field{?s}: {.val unsupported_fields}." ) } if ("twitter" %in% names(og)) { if (is.character(og$twitter) && length(og$twitter) == 1 && grepl("^@", og$twitter)) { cli::cli_abort( - "The `opengraph: twitter` option must be a list." + "The {.var opengraph: twitter} option must be a list." ) } if (!is.list(og$twitter)) { - cli::cli_abort("The `opengraph: twitter` option must be a list.") + cli::cli_abort("The {.var opengraph: twitter} option must be a list.") } if (is.null(og$twitter$creator) && is.null(og$twitter$site)) { cli::cli_abort( - "{.var opengraph: twitter} must include either 'creator' or 'site'." + "{.var opengraph: twitter} must include either {.val creator} or {.val site}." ) } } @@ -202,7 +202,7 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE) if (check && !made_by_pkgdown(full_path)) { if (!quiet) { - cli::cli_inform("Skipping {.file {{path}}: not generated by pkgdown") + cli::cli_alert_info("Skipping {.file {{path}}: not generated by pkgdown") } return(FALSE) } diff --git a/R/templates.R b/R/templates.R index 0ef590160..00ec08fa6 100644 --- a/R/templates.R +++ b/R/templates.R @@ -6,7 +6,8 @@ find_template <- function(type, name, ext = ".html", pkg = ".") { existing <- paths[file_exists(paths)] if (length(existing) == 0) { - cli::cli_abort(paste0("Can't find template for ", type, "-", name, ".")) + tname <- paste0(type, "-", name) + cli::cli_abort("Can't find template for {.val {tname}}.") } existing[[1]] } diff --git a/R/theme.R b/R/theme.R index 6d90e4d73..20ae3ffe9 100644 --- a/R/theme.R +++ b/R/theme.R @@ -57,8 +57,8 @@ bs_theme_rules <- function(pkg) { theme_path <- path_pkgdown("highlight-styles", paste0(theme, ".scss")) if (!file_exists(theme_path)) { cli::cli_abort(c( - "Unknown theme: {.var {theme}}", - i = "Valid themes are: {highlight_styles()}" + "Unknown theme: {.val {theme}}", + i = "Valid themes are: {.val highlight_styles()}" )) } paths <- c(paths, theme_path) @@ -101,15 +101,16 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { } else if (bootswatch_theme %in% bslib::bootswatch_themes(bs_version)) { bootswatch_theme } else { - cli::cli_abort( + cli::cli_abort(c( sprintf( - "Can't find Bootswatch theme '%s' (%s) for Bootstrap version '%s' (%s).", + "Can't find Bootswatch theme {.val %s} ({.val %s}) for Bootstrap version {.val %s} ({.val %s}).", bootswatch_theme, pkgdown_field(c("template", "bootswatch")), bs_version, pkgdown_field(c("template", "bootstrap")) - ) - ) + ), + x = "Edit settings in {.file {pkgdown_config_relpath(pkg)}}" + )) } } diff --git a/R/topics.R b/R/topics.R index cbbe8cd81..5cb1a21d0 100644 --- a/R/topics.R +++ b/R/topics.R @@ -10,7 +10,9 @@ select_topics <- function(match_strings, topics, check = FALSE) { # If none of the specified topics have a match, return no topics if (purrr::every(indexes, is_empty)) { if (check) { - cli::cli_abort("No topics matched in '_pkgdown.yml'. No topics selected.") + cli::cli_abort(c( + "No topics matched in '_pkgdown.yml'. No topics selected." + )) } return(integer()) } @@ -51,7 +53,7 @@ all_sign <- function(x, text) { } } - cli::cli_abort("Must be all negative or all positive: {.var {text}}") + cli::cli_abort("Must be all negative or all positive: {.val {text}}") } match_env <- function(topics) { @@ -172,8 +174,8 @@ match_eval <- function(string, env) { topic_must <- function(message, topic) { cli::cli_abort( c( - paste0("In {.file _pkgdown.yml}, topic must ", message), - "x" = paste0("Not {.var {topic}}") + "In {.file _pkgdown.yml}, topic must {message}", + "x" = "Not {.val {topic}}" ) ) } @@ -184,6 +186,7 @@ section_topics <- function(match_strings, topics, src_path) { topics <- rbind(topics, ext_topics(ext_strings)) selected <- topics[select_topics(match_strings, topics), , ] + tibble::tibble( name = selected$name, path = selected$file_out, diff --git a/R/usage.R b/R/usage.R index 8e9b2488c..c557b81f9 100644 --- a/R/usage.R +++ b/R/usage.R @@ -87,7 +87,7 @@ usage_type <- function(x) { out } else { untype <- paste0(typeof(x), " (in ", as.character(x), ")") - cli::cli_abort("Unknown type: {.var {untype}}") + cli::cli_abort("Unknown type: {.val {untype}}") } } @@ -131,7 +131,7 @@ fun_info <- function(fun) { name = call_name(fun) ) } else { - cli::cli_abort(paste0("Unknown call: ", as.character(x[[1]]))) + cli::cli_abort("Unknown call: {.val {as.character(x[[1]])}}") } } else { list( @@ -162,7 +162,7 @@ usage_code.NULL <- function(x) character() #' @export usage_code.tag <- function(x) { if (!identical(class(x), "tag")) { - cli::cli_abort(paste0("Undefined tag in usage ", class(x)[[1]])) + cli::cli_abort("Undefined tag in usage: {.val class(x)[[1]]}}") } paste0(purrr::flatten_chr(purrr::map(x, usage_code)), collapse = "") } diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index eff444709..8245a2c4e 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -12,7 +12,7 @@ Caused by error in `purrr::map()`: i In index: 4. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x Check for empty \url{} tags. # parse failures include file name [ansi] @@ -29,7 +29,7 @@ Caused by error in `purrr::map()`: i In index: 4. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x Check for empty \url{} tags. # parse failures include file name [unicode] @@ -46,7 +46,7 @@ Caused by error in `purrr::map()`: ℹ In index: 4. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ Check for empty \url{} tags. # parse failures include file name [fancy] @@ -63,7 +63,7 @@ Caused by error in `purrr::map()`: ℹ In index: 4. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ Check for empty \url{} tags. # test usage ok on rendered page [plain] diff --git a/tests/testthat/_snaps/package.md b/tests/testthat/_snaps/package.md index 1db0aa566..a069241e7 100644 --- a/tests/testthat/_snaps/package.md +++ b/tests/testthat/_snaps/package.md @@ -5,5 +5,5 @@ Condition Error in `check_bootstrap_version()`: ! Boostrap version must be 3 or 5. - x You specified a value of `1` in template.bootstrap. + x You specified a value of 1 in template.bootstrap. diff --git a/tests/testthat/_snaps/rd-example.md b/tests/testthat/_snaps/rd-example.md index f88f1ccf5..ec108cd11 100644 --- a/tests/testthat/_snaps/rd-example.md +++ b/tests/testthat/_snaps/rd-example.md @@ -4,7 +4,7 @@ expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) Condition Warning: - @examplesIf condition `cond_expr_str` is FALSE + @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" # @examplesIf [ansi] @@ -12,7 +12,7 @@ expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) Condition Warning: - @examplesIf condition `cond_expr_str` is FALSE + @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" # @examplesIf [unicode] @@ -20,7 +20,7 @@ expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) Condition Warning: - @examplesIf condition `cond_expr_str` is FALSE + @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" # @examplesIf [fancy] @@ -28,5 +28,5 @@ expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) Condition Warning: - @examplesIf condition `cond_expr_str` is FALSE + @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index 1a7e5612f..c15bd53d2 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -182,7 +182,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x Check for empty \url{} tags. Code rd2html("\\url{a\nb}") @@ -190,7 +190,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") @@ -198,7 +198,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\email{}`. + ! Failed to parse tag "\\email{}". x empty Code rd2html("\\linkS4class{}") @@ -206,7 +206,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\linkS4class{}`. + ! Failed to parse tag "\\linkS4class{}". # bad specs throw errors [ansi] @@ -216,7 +216,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x Check for empty \url{} tags. Code rd2html("\\url{a\nb}") @@ -224,7 +224,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". x This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") @@ -232,7 +232,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\email{}`. + ! Failed to parse tag "\\email{}". x empty Code rd2html("\\linkS4class{}") @@ -240,7 +240,7 @@ Error in `purrr::map_chr()`: i In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\linkS4class{}`. + ! Failed to parse tag "\\linkS4class{}". # bad specs throw errors [unicode] @@ -250,7 +250,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ Check for empty \url{} tags. Code rd2html("\\url{a\nb}") @@ -258,7 +258,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") @@ -266,7 +266,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\email{}`. + ! Failed to parse tag "\\email{}". ✖ empty Code rd2html("\\linkS4class{}") @@ -274,7 +274,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\linkS4class{}`. + ! Failed to parse tag "\\linkS4class{}". # bad specs throw errors [fancy] @@ -284,7 +284,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ Check for empty \url{} tags. Code rd2html("\\url{a\nb}") @@ -292,7 +292,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\url{}`. + ! Failed to parse tag "\\url{}". ✖ This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") @@ -300,7 +300,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\email{}`. + ! Failed to parse tag "\\email{}". ✖ empty Code rd2html("\\linkS4class{}") @@ -308,7 +308,7 @@ Error in `purrr::map_chr()`: ℹ In index: 1. Caused by error in `stop_bad_tag()`: - ! Failed to parse tag `\linkS4class{}`. + ! Failed to parse tag "\\linkS4class{}". # \describe items can contain multiple paragraphs diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index 7fb106e7d..94b0d07b7 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -1,6 +1,7 @@ # check_bootswatch_theme() works - Can't find Bootswatch theme 'paper' (template.bootswatch) for Bootstrap version '4' (template.bootstrap). + Can't find Bootswatch theme "paper" ("template.bootswatch") for Bootstrap version "4" ("template.bootstrap"). + x Edit settings in '_pkgdown.yml' # capture data_template() diff --git a/tests/testthat/_snaps/topics.md b/tests/testthat/_snaps/topics.md index db935a207..f4d173991 100644 --- a/tests/testthat/_snaps/topics.md +++ b/tests/testthat/_snaps/topics.md @@ -7,7 +7,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be valid R code - x Not `x + ` + x Not "x + " Code t <- select_topics("y", topics) Condition @@ -15,7 +15,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not `y` + x Not "y" Code t <- select_topics("paste(1)", topics) Condition @@ -23,7 +23,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known selector function - x Not `paste(1)` + x Not "paste(1)" Code t <- select_topics("starts_with", topics) Condition @@ -31,7 +31,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not `starts_with` + x Not "starts_with" Code t <- select_topics("1", topics) Condition @@ -39,7 +39,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a string or function call - x Not `1` + x Not "1" Code t <- select_topics("starts_with('y')", topics, check = TRUE) Condition @@ -55,7 +55,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not `a4` + x Not "a4" Code select_topics("c::a", topics) Condition @@ -63,7 +63,7 @@ i In index: 1. Caused by error in `topic_must()`: ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not `c::a` + x Not "c::a" # an unmatched selection generates a warning @@ -72,5 +72,5 @@ Condition Error in `topic_must()`: ! In '_pkgdown.yml', topic must match a function or concept - x Not `starts_with('unmatched')` + x Not "starts_with('unmatched')" diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 13aceb748..d70a03ff9 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -1,7 +1,8 @@ test_that("check_bootswatch_theme() works", { - expect_equal(check_bootswatch_theme("_default", 4, list()), NULL) - expect_equal(check_bootswatch_theme("lux", 4, list()), "lux") - expect_snapshot_error(check_bootswatch_theme("paper", 4, list())) + pkg <- as_pkgdown(test_path("assets/reference")) + expect_equal(check_bootswatch_theme("_default", 4, pkg), NULL) + expect_equal(check_bootswatch_theme("lux", 4, pkg), "lux") + expect_snapshot_error(check_bootswatch_theme("paper", 4, pkg)) }) test_that("capture data_template()", { From d5f85c6da1b2d1c13fd5ff25a94443c2bdaebf0f Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Mon, 27 Nov 2023 06:53:19 -0700 Subject: [PATCH 13/20] use field in a few places --- R/sitrep.R | 2 +- R/theme.R | 2 +- tests/testthat/_snaps/render.md | 2 +- tests/testthat/_snaps/sitrep.md | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/sitrep.R b/R/sitrep.R index f88d9f039..bf4ee0ca7 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -17,7 +17,7 @@ pkgdown_sitrep <- function(pkg = ".") { warns <- c() if (is.null(pkg$meta[["url"]])) { - warns <- c(warns, "x" = "{pkgdown_field('url')} is not configured in {.file {pkgdown_config_relpath(pkg)}}. See vignette {.vignette pkgdown::metatdata}.") + warns <- c(warns, "x" = "{.field {pkgdown_field('url')}} is not configured in {.file {pkgdown_config_relpath(pkg)}}. See {.vignette pkgdown::metatdata}.") } desc_urls <- pkg$desc$get_urls() diff --git a/R/theme.R b/R/theme.R index 20ae3ffe9..0154a5a0d 100644 --- a/R/theme.R +++ b/R/theme.R @@ -103,7 +103,7 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { } else { cli::cli_abort(c( sprintf( - "Can't find Bootswatch theme {.val %s} ({.val %s}) for Bootstrap version {.val %s} ({.val %s}).", + "Can't find Bootswatch theme {.val %s} ({.field %s}) for Bootstrap version {.val %s} ({.field %s}).", bootswatch_theme, pkgdown_field(c("template", "bootswatch")), bs_version, diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index 94b0d07b7..fe29f25c9 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -1,6 +1,6 @@ # check_bootswatch_theme() works - Can't find Bootswatch theme "paper" ("template.bootswatch") for Bootstrap version "4" ("template.bootstrap"). + Can't find Bootswatch theme "paper" (template.bootswatch) for Bootstrap version "4" (template.bootstrap). x Edit settings in '_pkgdown.yml' # capture data_template() diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 37cf72ac4..18a38c996 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -5,7 +5,7 @@ Condition Warning: pkgdown situation report: configuration error - x url is not configured in '_pkgdown.yml'. See vignette `vignette(pkgdown::metatdata)`. + x url is not configured in '_pkgdown.yml'. See `vignette(pkgdown::metatdata)`. x 'DESCRIPTION' URL is empty. --- @@ -29,7 +29,7 @@ Condition Warning: pkgdown situation report: configuration error - x url is not configured in _pkgdown.yml. See vignette `vignette(pkgdown::metatdata)`. + x url is not configured in _pkgdown.yml. See `vignette(pkgdown::metatdata)`. x DESCRIPTION URL is empty. --- @@ -53,7 +53,7 @@ Condition Warning: pkgdown situation report: configuration error - ✖ url is not configured in '_pkgdown.yml'. See vignette `vignette(pkgdown::metatdata)`. + ✖ url is not configured in '_pkgdown.yml'. See `vignette(pkgdown::metatdata)`. ✖ 'DESCRIPTION' URL is empty. --- @@ -77,7 +77,7 @@ Condition Warning: pkgdown situation report: configuration error - ✖ url is not configured in _pkgdown.yml. See vignette `vignette(pkgdown::metatdata)`. + ✖ url is not configured in _pkgdown.yml. See `vignette(pkgdown::metatdata)`. ✖ DESCRIPTION URL is empty. --- From 4213153f401cad8b474c65616da6bafb179fc23c Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Mon, 27 Nov 2023 13:20:44 -0700 Subject: [PATCH 14/20] Respond to reviews --- NAMESPACE | 1 - R/build-articles.R | 10 +- R/build-favicons.R | 18 +-- R/build-github.R | 4 +- R/build-home-index.R | 7 +- R/build-home-md.R | 2 +- R/build-home.R | 2 +- R/build-news.R | 6 +- R/build-redirects.R | 2 +- R/build-reference.R | 18 +-- R/build-search-docs.R | 4 +- R/build-tutorials.R | 2 +- R/build.R | 21 ++-- R/clean.R | 9 +- R/deploy-site.R | 20 ++-- R/init.R | 2 +- R/render.R | 4 +- R/rmarkdown.R | 11 +- R/sitrep.R | 4 +- R/test.R | 6 +- R/topics.R | 17 ++- R/usage.R | 7 +- R/utils-fs.R | 2 +- R/utils-yaml.R | 2 +- man/build_favicons.Rd | 3 - man/clean_site.Rd | 4 +- man/test-dont.Rd | 2 +- man/test-output-styles.Rd | 4 +- tests/testthat/_snaps/build-articles.md | 62 ++++++++++ tests/testthat/_snaps/build-github.md | 3 + tests/testthat/_snaps/build-home-citation.md | 3 + tests/testthat/_snaps/build-home-index.md | 15 ++- tests/testthat/_snaps/build-home.md | 33 +++++ tests/testthat/_snaps/build-logo.md | 12 ++ tests/testthat/_snaps/build-news.md | 20 ++++ tests/testthat/_snaps/build-reference.md | 119 +++++++++++++++++-- tests/testthat/_snaps/build-search-docs.md | 45 ------- tests/testthat/_snaps/check.md | 8 +- tests/testthat/_snaps/figure.md | 32 +++++ tests/testthat/_snaps/init.md | 72 +++++++++++ tests/testthat/_snaps/render.md | 12 ++ tests/testthat/_snaps/rmarkdown.md | 64 ++++++++-- tests/testthat/_snaps/sitrep.md | 12 ++ tests/testthat/_snaps/topics.md | 28 ++--- tests/testthat/_snaps/utils-yaml.md | 16 +-- tests/testthat/test-build-articles.R | 2 +- tests/testthat/test-build-reference.R | 6 +- tests/testthat/test-build-search-docs.R | 25 ++-- 48 files changed, 567 insertions(+), 216 deletions(-) delete mode 100644 tests/testthat/_snaps/build-search-docs.md diff --git a/NAMESPACE b/NAMESPACE index 744020aa2..7ae939ddb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -112,7 +112,6 @@ export(autolink_html) export(build_article) export(build_articles) export(build_articles_index) -export(build_favicon) export(build_favicons) export(build_home) export(build_home_index) diff --git a/R/build-articles.R b/R/build-articles.R index 5e5fe5aad..f3f165a5a 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -177,7 +177,7 @@ build_articles <- function(pkg = ".", return(invisible()) } - cli::cli_h2("Building articles") + cli::cli_rule("Building articles") build_articles_index(pkg) purrr::walk( @@ -368,9 +368,7 @@ data_articles_index <- function(pkg = ".") { missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package)) if (length(missing) > 0) { - cli::cli_abort( - "Vignette{?s} missing from index: {missing}" - ) + cli::cli_abort("{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}") } print_yaml(list( @@ -381,9 +379,7 @@ data_articles_index <- function(pkg = ".") { data_articles_index_section <- function(section, pkg) { if (!set_contains(names(section), c("title", "contents"))) { - cli::cli_abort( - "Section must have components {.field title, contents}" - ) + cli::cli_abort("Section must have components {.field title}, {.field contents}") } # Match topics against any aliases diff --git a/R/build-favicons.R b/R/build-favicons.R index ceda69acf..d4b556640 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -19,7 +19,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { rlang::check_installed("openssl") pkg <- as_pkgdown(pkg) - cli::cli_h2("Building favicons") + cli::cli_rule("Building favicons") logo_path <- find_logo(pkg$src_path) @@ -97,27 +97,15 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { utils::unzip(tmp, exdir = path(pkg$src_path, "pkgdown", "favicon")) }, warning = function(e) { - cli::cli_abort("Your logo file couldn't be processed and may be corrupt.") + cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e) }, error = function(e) { - cli::cli_abort("Your logo file couldn't be processed and may be corrupt.") + cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e) }) invisible() } -#' Deprecated as of pkgdown 1.4.0 -#' @rdname build_favicons -#' @inheritParams build_favicons -#' @export -build_favicon <- function(pkg, overwrite) { - cli::cli_warn(c( - "{.fun build_favicon} is deprecated as of pkgdown 1.4.0. ", - "i" = "Please use {.fun build_favicons} instead." - )) - build_favicons(pkg, overwrite) -} - copy_favicons <- function(pkg = ".") { pkg <- as_pkgdown(pkg) diff --git a/R/build-github.R b/R/build-github.R index ac33b9836..76111e896 100644 --- a/R/build-github.R +++ b/R/build-github.R @@ -25,7 +25,7 @@ build_site_github_pages <- function(pkg = ".", pkg <- as_pkgdown(pkg, override = list(destination = dest_dir)) if (clean) { - cli::cli_h2("Cleaning files from old site") + cli::cli_rule("Cleaning files from old site") clean_site(pkg) } @@ -36,7 +36,7 @@ build_site_github_pages <- function(pkg = ".", } build_github_pages <- function(pkg = ".") { - cli::cli_h2("Extra files for GitHub pages") + cli::cli_rule("Extra files for GitHub pages") pkg <- as_pkgdown(pkg) # Add .nojekyll since site is static HTML diff --git a/R/build-home-index.R b/R/build-home-index.R index f9d14daf8..bdb02ecdf 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -65,10 +65,9 @@ data_home_sidebar <- function(pkg = ".") { if (length(html_path)) { if (!file.exists(html_path)) { rel_html_path <- fs::path_rel(html_path, pkg$src_path) - rel_config_path <- pkgdown_config_relpath(pkg) cli::cli_abort(c( - "Can't locate {.file {rel_html_path}}", - "x" = "{.field {pkgdown_field(c('home', 'sidebar', 'html'))}} in {.file {rel_config_path}} is misconfigured" + "Can't locate {.file {rel_html_path}}.", + "x" = "{.field {pkgdown_field(c('home', 'sidebar', 'html'))}} in {.file {pkgdown_config_relpath(pkg)}} is misconfigured." )) } return(read_file(html_path)) @@ -217,7 +216,7 @@ check_missing_images <- function(pkg, src_path, dst_path) { paths <- rel_src[!exists] cli::cli_warn(c( "Missing images in {.file {src_path}}: {.file {paths}}", - "i" = "pkgdown can only use images in {.file man/figures} and {.file vignettes}" + i = "pkgdown can only use images in {.file man/figures} and {.file vignettes}" )) } } diff --git a/R/build-home-md.R b/R/build-home-md.R index 04e9a60b0..f2309deae 100644 --- a/R/build-home-md.R +++ b/R/build-home-md.R @@ -22,7 +22,7 @@ build_home_md <- function(pkg) { } render_md <- function(pkg, filename) { - cli::cli_alert_info("Reading {src_path(path_rel(filename, pkg$src_path))}") + cli::cli_inform("Reading {src_path(path_rel(filename, pkg$src_path))}") body <- markdown_body(filename, strip_header = TRUE) path <- path_ext_set(basename(filename), "html") diff --git a/R/build-home.R b/R/build-home.R index e287bc929..6bfa26ce5 100644 --- a/R/build-home.R +++ b/R/build-home.R @@ -31,7 +31,7 @@ build_home <- function(pkg = ".", quiet = TRUE) { pkg <- section_init(pkg, depth = 0L, override = override) - cli::cli_h2("Building home") + cli::cli_rule("Building home") dir_create(pkg$dst_path) build_citation_authors(pkg) diff --git a/R/build-news.R b/R/build-news.R index 614b0929c..34d145df2 100644 --- a/R/build-news.R +++ b/R/build-news.R @@ -78,7 +78,7 @@ build_news <- function(pkg = ".", if (!has_news(pkg$src_path)) return() - cli::cli_h2("Building news") + cli::cli_rule("Building news") dir_create(path(pkg$dst_path, "news")) switch(news_style(pkg$meta), @@ -162,8 +162,8 @@ data_news <- function(pkg = list()) { if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) { cli::cli_abort(c( "Invalid NEWS.md: inconsistent use of section headings.", - "i" = "Top-level headings must be either all

or all

.", - "i" = "See {.help pkgdown::build_news} for more details." + i = "Top-level headings must be either all

or all

.", + i = "See {.help pkgdown::build_news} for more details." )) } if (ulevels == "h1") { diff --git a/R/build-redirects.R b/R/build-redirects.R index 6375445da..a57fe939a 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -11,7 +11,7 @@ build_redirects <- function(pkg = ".", return(invisible()) } - cli::cli_h2("Building redirects") + cli::cli_rule("Building redirects") if (is.null(pkg$meta$url)) { cli::cli_abort("{.field {pkgdown_field('url')}} in {.file {pkgdown_config_relpath(pkg)}} required to generate redirects") } diff --git a/R/build-reference.R b/R/build-reference.R index 6925260ac..3e41e75aa 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -161,12 +161,16 @@ build_reference <- function(pkg = ".", topics = NULL) { pkg <- section_init(pkg, depth = 1L, override = override) - if (!missing(document)) { - cli::cli_warn("{.var document} is deprecated. Please use {.var devel} instead.") + if (document != "DEPRECATED") { + lifecycle::deprecate_warn( + "1.4.0", + "build_site(document)", + details = "Please use `build_site(devel)` instead." + ) devel <- document } - cli::cli_h2("Building function reference") + cli::cli_rule("Building function reference") build_reference_index(pkg) copy_figures(pkg) @@ -274,7 +278,7 @@ build_reference_topic <- function(topic, if (lazy && !out_of_date(in_path, out_path)) return(invisible()) - cli::cli_alert_info("Reading {src_path(path('man', topic$file_in))}") + cli::cli_inform("Reading {src_path(path('man', topic$file_in))}") data <- withCallingHandlers( data_reference_topic( @@ -284,11 +288,7 @@ build_reference_topic <- function(topic, run_dont_run = run_dont_run ), error = function(err) { - msg <- c( - paste0("Failed to parse Rd in ", topic$file_in), - i = err$message - ) - abort(msg, parent = err) + cli::cli_abort("Failed to parse Rd in {.file {topic$file_in}}", parent = err) } ) diff --git a/R/build-search-docs.R b/R/build-search-docs.R index 6dab99c40..c5264ff08 100644 --- a/R/build-search-docs.R +++ b/R/build-search-docs.R @@ -45,7 +45,7 @@ build_sitemap <- function(pkg = ".") { } xml_path <- path(pkg$dst_path, "sitemap.xml") - cli::cli_alert_info("Writing {dst_path(path_rel(xml_path, pkg$dst_path))}") + cli::cli_inform("Writing {dst_path(path_rel(xml_path, pkg$dst_path))}") xml2::write_xml(doc, file = xml_path) @@ -86,7 +86,7 @@ url_node <- function(url) { build_search <- function(pkg = ".", override = list()) { pkg <- section_init(pkg, depth = 1L, override = override) - cli::cli_alert("Building search index") + cli::cli_inform("Building search index") search_index <- build_search_index(pkg) jsonlite::write_json( search_index, diff --git a/R/build-tutorials.R b/R/build-tutorials.R index caeacdfaf..d9b6679bd 100644 --- a/R/build-tutorials.R +++ b/R/build-tutorials.R @@ -35,7 +35,7 @@ build_tutorials <- function(pkg = ".", override = list(), preview = NA) { return(invisible()) } - cli::cli_h2("Building tutorials") + cli::cli_rule("Building tutorials") dir_create(path(pkg$dst_path, "tutorials")) data <- purrr::transpose(tutorials) diff --git a/R/build.R b/R/build.R index 188c3afc7..b185dc1b2 100644 --- a/R/build.R +++ b/R/build.R @@ -327,14 +327,18 @@ build_site <- function(pkg = ".", document = "DEPRECATED") { pkg <- as_pkgdown(pkg, override = override) - if (!missing(document)) { - cli::cli_warn("{.var document} is deprecated. Please use {.var devel} instead.") + if (document != "DEPRECATED") { + lifecycle::deprecate_warn( + "1.4.0", + "build_site(document)", + details = "Please use `build_site(devel)` instead." + ) devel <- document } if (install) { withr::local_temp_libpaths() - cli::cli_h2("Installing package {.pkg {pkg$package}} into temporary library") + cli::cli_rule("Installing package {.pkg {pkg$package}} into temporary library") # Keep source, so that e.g. pillar can show the source code # of its functions in its articles withr::with_options( @@ -404,7 +408,8 @@ build_site_external <- function(pkg = ".", timeout = getOption('pkgdown.timeout', Inf) ) - cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.") + cli::cli_rule(paste0("finished building pkgdown site for package ", cli::col_blue(pkg$package))) + preview_site(pkg, preview = preview) invisible() } @@ -421,9 +426,9 @@ build_site_local <- function(pkg = ".", pkg <- section_init(pkg, depth = 0, override = override) - cli::cli_h1("Building pkgdown site for {.pkg {pkg$package}}") - cli::cli_alert("Reading from: {src_path(path_abs(pkg$src_path))}") - cli::cli_alert("Writing to: {dst_path(path_abs(pkg$dst_path))}") + cli::cli_rule(paste0("Building pkgdown site for package ", cli::col_blue(pkg$package))) + cli::cli_inform("Reading from: {src_path(path_abs(pkg$src_path))}") + cli::cli_inform("Writing to: {dst_path(path_abs(pkg$dst_path))}") init_site(pkg) @@ -448,6 +453,6 @@ build_site_local <- function(pkg = ".", build_search(pkg, override = override) } - cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.") + cli::cli_rule(paste0("finished building pkgdown site for package ", cli::col_blue(pkg$package))) preview_site(pkg, preview = preview) } diff --git a/R/clean.R b/R/clean.R index 19f15dd7c..6116f3ae8 100644 --- a/R/clean.R +++ b/R/clean.R @@ -2,11 +2,17 @@ #' #' Delete all files in `docs/` (except for `CNAME`). #' +#' @param quiet If `TRUE`, suppresses a message. #' @inheritParams build_site #' @export -clean_site <- function(pkg = ".") { +clean_site <- function(pkg = ".", quiet = FALSE) { + pkg <- as_pkgdown(pkg) + if (!quiet) { + cli::cli_inform("Cleaning {.pkg {pkg$package}} pkgdown docs from {.path {pkg$dst_path}}") + } + if (!dir_exists(pkg$dst_path)) return(invisible()) top_level <- dir_ls(pkg$dst_path) @@ -16,6 +22,5 @@ clean_site <- function(pkg = ".") { dir_delete(top_level[is_dir]) file_delete(top_level[!is_dir]) - cli::cli_alert_success("Site cleaned for {.pkg {pkg$package}} (emptied {.path {pkg$dst_path}})") invisible(TRUE) } diff --git a/R/deploy-site.R b/R/deploy-site.R index 22d5f5ff9..3a3899019 100644 --- a/R/deploy-site.R +++ b/R/deploy-site.R @@ -43,15 +43,15 @@ deploy_site_github <- function( repo_slug = Sys.getenv("TRAVIS_REPO_SLUG", "")) { rlang::check_installed("openssl") if (!nzchar(tarball)) { - cli::cli_abort("No built tarball detected, please provide the location of one with {.var tarball}") + cli::cli_abort("No built tarball detected, please provide the location of one with {.var tarball}", call = caller_env()) } if (!nzchar(ssh_id)) { - cli::cli_abort("No deploy key found, please setup with {.fn travis::use_travis_deploy}") + cli::cli_abort("No deploy key found, please setup with {.fn travis::use_travis_deploy}", call = caller_env()) } if (!nzchar(repo_slug)) { - cli::cli_abort("No repo detected, please supply one with {.var repo_slug}") + cli::cli_abort("No repo detected, please supply one with {.var repo_slug}", call = caller_env()) } cli::cli_alert("Deploying site to GitHub") @@ -61,13 +61,13 @@ deploy_site_github <- function( } ssh_id_file <- "~/.ssh/id_rsa" - cli::cli_alert_info("Setting up SSH id") - cli::cli_alert_info("Copying private key to {.file ssh_id_file}") + cli::cli_inform("Setting up SSH id") + cli::cli_inform("Copying private key to {.file ssh_id_file}") write_lines(rawToChar(openssl::base64_decode(ssh_id)), ssh_id_file) - cli::cli_alert_info("Setting private key permissions to 0600") + cli::cli_inform("Setting private key permissions to 0600") fs::file_chmod(ssh_id_file, "0600") - cli::cli_alert_info("Setting remote to use the ssh url") + cli::cli_inform("Setting remote to use the ssh url") git("remote", "set-url", "origin", sprintf("git@%s:%s.git", host, repo_slug)) @@ -165,7 +165,7 @@ git_current_branch <- function() { } github_worktree_add <- function(dir, remote, branch) { - cli::cli_alert_info("Adding worktree") + cli::cli_inform("Adding worktree") git("worktree", "add", "--track", "-B", branch, @@ -175,7 +175,7 @@ github_worktree_add <- function(dir, remote, branch) { } github_worktree_remove <- function(dir) { - cli::cli_alert_info("Removing worktree") + cli::cli_inform("Removing worktree") git("worktree", "remove", dir) } @@ -183,7 +183,7 @@ github_push <- function(dir, commit_message, remote, branch) { # force execution before changing working directory force(commit_message) - cli::cli_alert_info("Commiting updated site") + cli::cli_inform("Commiting updated site") withr::with_dir(dir, { git("add", "-A", ".") diff --git a/R/init.R b/R/init.R index eb411975d..ac6d87b87 100644 --- a/R/init.R +++ b/R/init.R @@ -27,7 +27,7 @@ init_site <- function(pkg = ".") { cli::cli_abort("{.file {pkg$dst_path}} is non-empty and not built by pkgdown") } - cli::cli_h2("Initialising site") + cli::cli_rule("Initialising site") dir_create(pkg$dst_path) copy_assets(pkg) diff --git a/R/render.R b/R/render.R index 542ff411c..1aaa20ec1 100644 --- a/R/render.R +++ b/R/render.R @@ -202,7 +202,7 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE) if (check && !made_by_pkgdown(full_path)) { if (!quiet) { - cli::cli_alert_info("Skipping {.file {{path}}: not generated by pkgdown") + cli::cli_inform("Skipping {.file {{path}}: not generated by pkgdown") } return(FALSE) } @@ -215,7 +215,7 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE) } if (!quiet) { - cli::cli_alert_info("Writing {dst_path(path)}") + cli::cli_inform("Writing {dst_path(path)}") } write_lines(contents, path = full_path) diff --git a/R/rmarkdown.R b/R/rmarkdown.R index da558faf9..d823fba83 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -10,7 +10,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet cli::cli_abort("Can't find {src_path(input)") } - cli::cli_alert_info("Reading {src_path(input)}") + cli::cli_inform("Reading {src_path(input)}") digest <- file_digest(output_path) args <- list( @@ -38,11 +38,10 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ) ), error = function(cnd) { - cli::cli_abort(c( + cli::cli_abort( "Failed to render RMarkdown document", - "x" = cnd$parent$message, - "x" = cnd$stderr - )) + parent = cnd + ) } ) @@ -56,7 +55,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet } if (digest != file_digest(output_path)) { href <- paste0("ide:run:pkgdown::preview_page('", path_rel(output_path, pkg$dst_path), "')") - cli::cli_alert_info("Writing {cli::style_hyperlink(dst_path(output), href)}") + cli::cli_inform("Writing {cli::style_hyperlink(dst_path(output), href)}") } # Copy over images needed by the document diff --git a/R/sitrep.R b/R/sitrep.R index bf4ee0ca7..acde54e30 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -29,8 +29,8 @@ pkgdown_sitrep <- function(pkg = ".") { if (length(warns) == 0) { cli::cli_alert_success("pkgdown situation report: {.emph {cli::col_green('all clear')}}") cli::cli_alert("{.emph Double-check the following URLs:}") - cli::cli_alert_info("{.file {pkgdown_config_relpath(pkg)}} contains URL {.url {pkg$meta['url']}}") - cli::cli_alert_info("{.file DESCRIPTION} contains URL{?s} {.url {desc_urls}}") + cli::cli_inform("{.file {pkgdown_config_relpath(pkg)}} contains URL {.url {pkg$meta['url']}}") + cli::cli_inform("{.file DESCRIPTION} contains URL{?s} {.url {desc_urls}}") } else { cli::cli_warn(c( "pkgdown situation report: {.emph {cli::col_red('configuration error')}}", diff --git a/R/test.R b/R/test.R index 50a0f19ff..e63affb14 100644 --- a/R/test.R +++ b/R/test.R @@ -89,7 +89,7 @@ NULL #' @family tests #' @examples #' \dontrun{ -#' cli::cli_abort("This is an error!") +#' abort("This is an error!") #' } #' #' # Inline \donttest is silently ommitted @@ -149,8 +149,8 @@ NULL #' a #' #' cat("This some text!\n") -#' cli::cli_inform("This is a message!") -#' cli::cli_warn("This is a warning!") +#' message("This is a message!") +#' warning("This is a warning!") #' #' # This is a multi-line block #' { diff --git a/R/topics.R b/R/topics.R index 5cb1a21d0..a87a3b4ac 100644 --- a/R/topics.R +++ b/R/topics.R @@ -10,9 +10,10 @@ select_topics <- function(match_strings, topics, check = FALSE) { # If none of the specified topics have a match, return no topics if (purrr::every(indexes, is_empty)) { if (check) { - cli::cli_abort(c( - "No topics matched in '_pkgdown.yml'. No topics selected." - )) + cli::cli_abort( + "No topics matched in {.file _pkgdown.yml}. No topics selected.", + call = caller_env() + ) } return(integer()) } @@ -163,7 +164,7 @@ match_eval <- function(string, env) { tryCatch( eval(expr, env), error = function(e) { - topic_must("be a known selector function", string) + topic_must("be a known selector function", string, parent = e) } ) } else { @@ -171,12 +172,10 @@ match_eval <- function(string, env) { } } -topic_must <- function(message, topic) { +topic_must <- function(message, topic, parent = NULL) { cli::cli_abort( - c( - "In {.file _pkgdown.yml}, topic must {message}", - "x" = "Not {.val {topic}}" - ) + "In {.file _pkgdown.yml}, topic must {message}, not {.val {topic}}", + parent = parent ) } diff --git a/R/usage.R b/R/usage.R index c557b81f9..77e9d0940 100644 --- a/R/usage.R +++ b/R/usage.R @@ -28,10 +28,9 @@ parse_usage <- function(x) { parse_exprs(r) }, error = function(e) { - cli::cli_warn(c( - "Failed to parse usage:", - "x" = "{.var {r}}" - )) + cli::cli_warn( + "Failed to parse usage: {.code {r}}" + ) list() } ) diff --git a/R/utils-fs.R b/R/utils-fs.R index f33700036..0ba3da3be 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -41,7 +41,7 @@ file_copy_to <- function(pkg, eq <- purrr::map2_lgl(from_paths, to_paths, file_equal) if (any(!eq)) { - cli::cli_alert_info(c( + cli::cli_inform(c( "Copying {src_path(path_rel(from_paths[!eq], pkg$src_path))}", " to {dst_path(path_rel(to_paths[!eq], pkg$dst_path))}" )) diff --git a/R/utils-yaml.R b/R/utils-yaml.R index 04b6e5596..528b538b4 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -7,7 +7,7 @@ check_yaml_has <- function(missing, where, pkg) { missing_fields <- purrr::map_chr(missing_components, pkgdown_field) cli::cli_abort( - "Can't find {.field {missing_fields}} component{?s} in {.file {pkgdown_config_relpath(pkg)}}." + "Can't find {cli::qty(missing_fields)} component{?s} {.field {missing_fields}} in {.file {pkgdown_config_relpath(pkg)}}." ) } diff --git a/man/build_favicons.Rd b/man/build_favicons.Rd index b252e0b4b..245393ebf 100644 --- a/man/build_favicons.Rd +++ b/man/build_favicons.Rd @@ -2,12 +2,9 @@ % Please edit documentation in R/build-favicons.R \name{build_favicons} \alias{build_favicons} -\alias{build_favicon} \title{Create favicons from package logo} \usage{ build_favicons(pkg = ".", overwrite = FALSE) - -build_favicon(pkg, overwrite) } \arguments{ \item{pkg}{Path to package.} diff --git a/man/clean_site.Rd b/man/clean_site.Rd index 4fee8dfee..d8e73f3cf 100644 --- a/man/clean_site.Rd +++ b/man/clean_site.Rd @@ -4,10 +4,12 @@ \alias{clean_site} \title{Clean site} \usage{ -clean_site(pkg = ".") +clean_site(pkg = ".", quiet = FALSE) } \arguments{ \item{pkg}{Path to package.} + +\item{quiet}{If \code{TRUE}, suppresses a message.} } \description{ Delete all files in \verb{docs/} (except for \code{CNAME}). diff --git a/man/test-dont.Rd b/man/test-dont.Rd index 6f23fc3cc..804b68984 100644 --- a/man/test-dont.Rd +++ b/man/test-dont.Rd @@ -8,7 +8,7 @@ Test case: don't } \examples{ \dontrun{ - cli::cli_abort("This is an error!") + abort("This is an error!") } # Inline \donttest is silently ommitted diff --git a/man/test-output-styles.Rd b/man/test-output-styles.Rd index 118a229ae..e7655192f 100644 --- a/man/test-output-styles.Rd +++ b/man/test-output-styles.Rd @@ -13,8 +13,8 @@ a <- 1:100 a cat("This some text!\n") -cli::cli_inform("This is a message!") -cli::cli_warn("This is a warning!") +message("This is a message!") +warning("This is a warning!") # This is a multi-line block { diff --git a/tests/testthat/_snaps/build-articles.md b/tests/testthat/_snaps/build-articles.md index 0488d2eb7..33f1df726 100644 --- a/tests/testthat/_snaps/build-articles.md +++ b/tests/testthat/_snaps/build-articles.md @@ -2,16 +2,27 @@ Code copy_figures(pkg) + Message + Copying man/figures/kitten.jpg + to reference/figures/kitten.jpg --- Code build_articles(pkg, lazy = FALSE) + Message + Writing articles/index.html + Reading vignettes/kitten.Rmd + Writing articles/kitten.html # warns about missing images [plain] Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/html-vignette.Rmd + Writing articles/html-vignette.html Condition Warning: Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' @@ -21,6 +32,10 @@ Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/html-vignette.Rmd + Writing articles/html-vignette.html Condition Warning: Missing images in vignettes/html-vignette.Rmd: foo.png @@ -30,6 +45,10 @@ Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/html-vignette.Rmd + Writing articles/html-vignette.html Condition Warning: Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' @@ -39,6 +58,10 @@ Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/html-vignette.Rmd + Writing articles/html-vignette.html Condition Warning: Missing images in vignettes/html-vignette.Rmd: foo.png @@ -48,56 +71,89 @@ Code path <- build_article("standard", pkg) + Message + Reading vignettes/standard.Rmd + Writing articles/standard.html # can build article that uses html_vignette Code expect_error(build_article("html-vignette", pkg), NA) + Message + Reading vignettes/html-vignette.Rmd + Writing articles/html-vignette.html # can override html_document() options Code path <- build_article("html-document", pkg) + Message + Reading vignettes/html-document.Rmd + Writing articles/html-document.html # html widgets get needed css/js Code path <- build_article("widget", pkg) + Message + Reading vignettes/widget.Rmd + Writing articles/widget.html # can override options with _output.yml Code path <- build_article("html-document", pkg) + Message + Reading vignettes/html-document.Rmd + Writing articles/html-document.html # can set width Code path <- build_article("width", pkg) + Message + Reading vignettes/width.Rmd + Writing articles/width.html # finds external resources referenced by R code in the article html Code path <- build_article("resources", pkg) + Message + Reading vignettes/resources.Rmd + Writing articles/resources.html # BS5 article laid out correctly with and without TOC Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code toc_true_path <- build_article("standard", pkg) + Message + Reading vignettes/standard.Rmd + Writing articles/standard.html --- Code toc_false_path <- build_article("toc-false", pkg) + Message + Reading vignettes/toc-false.Rmd + Writing articles/toc-false.html # articles in vignettes/articles/ are unnested into articles/ Code path <- build_article("articles/nested", pkg) + Message + Reading vignettes/articles/nested.Rmd + Writing articles/nested.html --- @@ -108,9 +164,15 @@ Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code path <- build_article("html-deps", pkg) + Message + Reading vignettes/html-deps.Rmd + Writing articles/html-deps.html diff --git a/tests/testthat/_snaps/build-github.md b/tests/testthat/_snaps/build-github.md index 461afc69a..36977fe4c 100644 --- a/tests/testthat/_snaps/build-github.md +++ b/tests/testthat/_snaps/build-github.md @@ -2,4 +2,7 @@ Code build_github_pages(pkg) + Message + Writing .nojekyll + Writing CNAME diff --git a/tests/testthat/_snaps/build-home-citation.md b/tests/testthat/_snaps/build-home-citation.md index 7910dda4e..89dac427d 100644 --- a/tests/testthat/_snaps/build-home-citation.md +++ b/tests/testthat/_snaps/build-home-citation.md @@ -2,6 +2,9 @@ Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # multiple citations all have HTML and BibTeX formats diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index 37e018779..ffc10e283 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -2,6 +2,9 @@ Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js # data_home_sidebar() works by default @@ -53,8 +56,8 @@ # data_home_sidebar() errors well when no HTML file - Can't locate 'file.html' - x home.sidebar.html in '_pkgdown.yml' is misconfigured + Can't locate 'file.html'. + x home.sidebar.html in '_pkgdown.yml' is misconfigured. # data_home_sidebar() can get a custom markdown formatted component @@ -76,23 +79,23 @@ # data_home_sidebar() outputs informative error messages - Can't find home.sidebar.components.fancy component in '_pkgdown.yml'. + Can't find component home.sidebar.components.fancy in '_pkgdown.yml'. --- - Can't find home.sidebar.components.fancy and home.sidebar.components.cool components in '_pkgdown.yml'. + Can't find components home.sidebar.components.fancy and home.sidebar.components.cool in '_pkgdown.yml'. --- i In index: 1. i With name: fancy. Caused by error in `check_yaml_has()`: - ! Can't find home.sidebar.components.fancy.title component in '_pkgdown.yml'. + ! Can't find component home.sidebar.components.fancy.title in '_pkgdown.yml'. --- i In index: 1. i With name: fancy. Caused by error in `check_yaml_has()`: - ! Can't find home.sidebar.components.fancy.title and home.sidebar.components.fancy.text components in '_pkgdown.yml'. + ! Can't find components home.sidebar.components.fancy.title and home.sidebar.components.fancy.text in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/build-home.md b/tests/testthat/_snaps/build-home.md index e95c93c19..fdc38a3cd 100644 --- a/tests/testthat/_snaps/build-home.md +++ b/tests/testthat/_snaps/build-home.md @@ -2,55 +2,88 @@ Code build_home(pkg) + Message + Writing authors.html + Writing 404.html --- Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # warns about missing images [plain] Code build_home(pkg) + Message + Writing authors.html Condition Warning: Missing images in 'README.md': 'foo.png' i pkgdown can only use images in 'man/figures' and 'vignettes' + Message + Writing 404.html # warns about missing images [ansi] Code build_home(pkg) + Message + Writing authors.html Condition Warning: Missing images in README.md: foo.png i pkgdown can only use images in man/figures and vignettes + Message + Writing 404.html # warns about missing images [unicode] Code build_home(pkg) + Message + Writing authors.html Condition Warning: Missing images in 'README.md': 'foo.png' ℹ pkgdown can only use images in 'man/figures' and 'vignettes' + Message + Writing 404.html # warns about missing images [fancy] Code build_home(pkg) + Message + Writing authors.html Condition Warning: Missing images in README.md: foo.png ℹ pkgdown can only use images in man/figures and vignettes + Message + Writing 404.html # can build site even if no Authors@R present Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # .github files are copied and linked Code build_home(pkg) + Message + Writing authors.html + Reading .github/404.md + Writing 404.html + Reading .github/CODE_OF_CONDUCT.md + Writing CODE_OF_CONDUCT.html + Reading .github/SUPPORT.md + Writing SUPPORT.html diff --git a/tests/testthat/_snaps/build-logo.md b/tests/testthat/_snaps/build-logo.md index 86a7316f9..889c7bc5f 100644 --- a/tests/testthat/_snaps/build-logo.md +++ b/tests/testthat/_snaps/build-logo.md @@ -2,19 +2,31 @@ Code copy_logo(pkg) + Message + Copying man/figures/logo.svg + to logo.svg # can handle logo in subdir [ansi] Code copy_logo(pkg) + Message + Copying man/figures/logo.svg + to logo.svg # can handle logo in subdir [unicode] Code copy_logo(pkg) + Message + Copying man/figures/logo.svg + to logo.svg # can handle logo in subdir [fancy] Code copy_logo(pkg) + Message + Copying man/figures/logo.svg + to logo.svg diff --git a/tests/testthat/_snaps/build-news.md b/tests/testthat/_snaps/build-news.md index 504a4b369..fa420cd76 100644 --- a/tests/testthat/_snaps/build-news.md +++ b/tests/testthat/_snaps/build-news.md @@ -31,6 +31,11 @@ Code build_news(pkg) + Message + Writing news/news-2.0.html + Writing news/news-1.1.html + Writing news/news-1.0.html + Writing news/index.html # multi-page news are rendered [ansi] @@ -49,6 +54,11 @@ Code build_news(pkg) + Message + Writing news/news-2.0.html + Writing news/news-1.1.html + Writing news/news-1.0.html + Writing news/index.html # multi-page news are rendered [unicode] @@ -67,6 +77,11 @@ Code build_news(pkg) + Message + Writing news/news-2.0.html + Writing news/news-1.1.html + Writing news/news-1.0.html + Writing news/index.html # multi-page news are rendered [fancy] @@ -85,6 +100,11 @@ Code build_news(pkg) + Message + Writing news/news-2.0.html + Writing news/news-1.1.html + Writing news/news-1.0.html + Writing news/index.html # news headings get class and release date diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index 8245a2c4e..e78a2791a 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -2,13 +2,15 @@ Code build_reference(pkg) + Message + Writing reference/index.html + Reading man/f.Rd Condition Error in `purrr::map()`: i In index: 1. i With name: f.Rd. Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - In index: 4. + ! Failed to parse Rd in 'f.Rd' Caused by error in `purrr::map()`: i In index: 4. Caused by error in `stop_bad_tag()`: @@ -19,13 +21,15 @@ Code build_reference(pkg) + Message + Writing reference/index.html + Reading man/f.Rd Condition Error in `purrr::map()`: i In index: 1. i With name: f.Rd. Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - In index: 4. + ! Failed to parse Rd in f.Rd Caused by error in `purrr::map()`: i In index: 4. Caused by error in `stop_bad_tag()`: @@ -36,13 +40,15 @@ Code build_reference(pkg) + Message + Writing reference/index.html + Reading man/f.Rd Condition Error in `purrr::map()`: ℹ In index: 1. ℹ With name: f.Rd. Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - In index: 4. + ! Failed to parse Rd in 'f.Rd' Caused by error in `purrr::map()`: ℹ In index: 4. Caused by error in `stop_bad_tag()`: @@ -53,13 +59,15 @@ Code build_reference(pkg) + Message + Writing reference/index.html + Reading man/f.Rd Condition Error in `purrr::map()`: ℹ In index: 1. ℹ With name: f.Rd. Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - In index: 4. + ! Failed to parse Rd in f.Rd Caused by error in `purrr::map()`: ℹ In index: 4. Caused by error in `stop_bad_tag()`: @@ -70,129 +78,224 @@ Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html # test usage ok on rendered page [ansi] Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html # test usage ok on rendered page [unicode] Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html # test usage ok on rendered page [fancy] Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "c") + Message + Writing reference/index.html + Reading man/c.Rd + Writing reference/c.html # .Rd without usage doesn't get Usage section [plain] Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html # .Rd without usage doesn't get Usage section [ansi] Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html # .Rd without usage doesn't get Usage section [unicode] Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html # .Rd without usage doesn't get Usage section [fancy] Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html --- Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "e") + Message + Writing reference/index.html + Reading man/e.Rd + Writing reference/e.html # pkgdown html dependencies are suppressed from examples in references Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js --- Code build_reference(pkg, topics = "a") + Message + Writing reference/index.html + Reading man/a.Rd + Writing reference/a.html diff --git a/tests/testthat/_snaps/build-search-docs.md b/tests/testthat/_snaps/build-search-docs.md deleted file mode 100644 index d56d25c96..000000000 --- a/tests/testthat/_snaps/build-search-docs.md +++ /dev/null @@ -1,45 +0,0 @@ -# docsearch.json and sitemap.xml are valid - - Code - build_site(pkg, new_process = FALSE) - -# build_search() builds the expected search`.json with an URL - - Code - init_site(pkg) - ---- - - Code - build_news(pkg) - ---- - - Code - build_home(pkg) - ---- - - Code - build_sitemap(pkg) - -# build_search() builds the expected search.json with no URL - - Code - init_site(pkg) - ---- - - Code - build_news(pkg) - ---- - - Code - build_home(pkg) - ---- - - Code - build_sitemap(pkg) - diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index e75f065e3..bbb19b5e4 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -44,7 +44,7 @@ check_pkgdown(pkg) Condition Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width + ! Vignettes missing from index: 'articles/nested' and 'width' # fails if article index incomplete [ansi] @@ -52,7 +52,7 @@ check_pkgdown(pkg) Condition Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width + ! Vignettes missing from index: articles/nested and width # fails if article index incomplete [unicode] @@ -60,7 +60,7 @@ check_pkgdown(pkg) Condition Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width + ! Vignettes missing from index: 'articles/nested' and 'width' # fails if article index incomplete [fancy] @@ -68,7 +68,7 @@ check_pkgdown(pkg) Condition Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width + ! Vignettes missing from index: articles/nested and width # informs if everything is ok [plain] diff --git a/tests/testthat/_snaps/figure.md b/tests/testthat/_snaps/figure.md index c6487fc6e..25fcbf24c 100644 --- a/tests/testthat/_snaps/figure.md +++ b/tests/testthat/_snaps/figure.md @@ -2,39 +2,71 @@ Code build_reference(pkg, devel = FALSE) + Message + Writing reference/index.html + Reading man/figure.Rd + Writing reference/figure.html --- Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/figures.Rmd + Writing articles/figures.html # can override defaults in _pkgdown.yml [ansi] Code build_reference(pkg, devel = FALSE) + Message + Writing reference/index.html + Reading man/figure.Rd + Writing reference/figure.html --- Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/figures.Rmd + Writing articles/figures.html # can override defaults in _pkgdown.yml [unicode] Code build_reference(pkg, devel = FALSE) + Message + Writing reference/index.html + Reading man/figure.Rd + Writing reference/figure.html --- Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/figures.Rmd + Writing articles/figures.html # can override defaults in _pkgdown.yml [fancy] Code build_reference(pkg, devel = FALSE) + Message + Writing reference/index.html + Reading man/figure.Rd + Writing reference/figure.html --- Code build_articles(pkg) + Message + Writing articles/index.html + Reading vignettes/figures.Rmd + Writing articles/figures.html diff --git a/tests/testthat/_snaps/init.md b/tests/testthat/_snaps/init.md index efdf10d1a..9f4f2bc4e 100644 --- a/tests/testthat/_snaps/init.md +++ b/tests/testthat/_snaps/init.md @@ -2,81 +2,153 @@ Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css and pkgdown/extra.js + to extra.css and extra.js --- Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # extra.css and extra.js copied and linked [ansi] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css and pkgdown/extra.js + to extra.css and extra.js --- Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # extra.css and extra.js copied and linked [unicode] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css and pkgdown/extra.js + to extra.css and extra.js --- Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # extra.css and extra.js copied and linked [fancy] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css and pkgdown/extra.js + to extra.css and extra.js --- Code build_home(pkg) + Message + Writing authors.html + Writing 404.html # single extra.css correctly copied [plain] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css + to extra.css # single extra.css correctly copied [ansi] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css + to extra.css # single extra.css correctly copied [unicode] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css + to extra.css # single extra.css correctly copied [fancy] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/extra.css + to extra.css # asset subdirectories are copied [plain] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt + to subdir1/file1.txt and subdir1/subdir2/file2.txt # asset subdirectories are copied [ansi] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt + to subdir1/file1.txt and subdir1/subdir2/file2.txt # asset subdirectories are copied [unicode] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt + to subdir1/file1.txt and subdir1/subdir2/file2.txt # asset subdirectories are copied [fancy] Code init_site(pkg) + Message + Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js + to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js + Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt + to subdir1/file1.txt and subdir1/subdir2/file2.txt # site meta doesn't break unexpectedly [plain] diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index fe29f25c9..73767cc5c 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -56,19 +56,31 @@ Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js # can include text in header, before body, and after body [ansi] Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js # can include text in header, before body, and after body [unicode] Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js # can include text in header, before body, and after body [fancy] Code init_site(pkg) + Message + Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js + to link.svg and pkgdown.js diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md index c2d273c59..aa291fc7d 100644 --- a/tests/testthat/_snaps/rmarkdown.md +++ b/tests/testthat/_snaps/rmarkdown.md @@ -2,71 +2,102 @@ Code render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + Message + Reading assets/vignette-with-img.Rmd + Writing test.html # render_rmarkdown copies image files in subdirectories [ansi] Code render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + Message + Reading assets/vignette-with-img.Rmd + Writing test.html # render_rmarkdown copies image files in subdirectories [unicode] Code render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + Message + Reading assets/vignette-with-img.Rmd + Writing test.html # render_rmarkdown copies image files in subdirectories [fancy] Code render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") + Message + Reading assets/vignette-with-img.Rmd + Writing test.html # render_rmarkdown yields useful error [plain] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) + Message + Reading assets/pandoc-fail.Rmd Condition - Error in `value[[3L]]()`: + Error in `render_rmarkdown()`: ! Failed to render RMarkdown document - x pandoc document conversion failed with error 3 - x [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. + Caused by error: + ! in callr subprocess. + Caused by error: + ! pandoc document conversion failed with error 3 # render_rmarkdown yields useful error [ansi] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) + Message + Reading assets/pandoc-fail.Rmd Condition - Error in `value[[3L]]()`: + Error in `render_rmarkdown()`: ! Failed to render RMarkdown document - x pandoc document conversion failed with error 3 - x [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. + Caused by error: + ! in callr subprocess. + Caused by error: + ! pandoc document conversion failed with error 3 # render_rmarkdown yields useful error [unicode] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) + Message + Reading assets/pandoc-fail.Rmd Condition - Error in `value[[3L]]()`: + Error in `render_rmarkdown()`: ! Failed to render RMarkdown document - ✖ pandoc document conversion failed with error 3 - ✖ [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. + Caused by error: + ! in callr subprocess. + Caused by error: + ! pandoc document conversion failed with error 3 # render_rmarkdown yields useful error [fancy] Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( pandoc_args = "--fail-if-warnings")) + Message + Reading assets/pandoc-fail.Rmd Condition - Error in `value[[3L]]()`: + Error in `render_rmarkdown()`: ! Failed to render RMarkdown document - ✖ pandoc document conversion failed with error 3 - ✖ [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. + Caused by error: + ! in callr subprocess. + Caused by error: + ! pandoc document conversion failed with error 3 # render_rmarkdown styles ANSI escapes [plain] Code path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", output = "test.html") + Message + Reading assets/vignette-with-crayon.Rmd + Writing test.html --- @@ -77,6 +108,9 @@ Code path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", output = "test.html") + Message + Reading assets/vignette-with-crayon.Rmd + Writing test.html --- @@ -87,6 +121,9 @@ Code path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", output = "test.html") + Message + Reading assets/vignette-with-crayon.Rmd + Writing test.html --- @@ -97,6 +134,9 @@ Code path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", output = "test.html") + Message + Reading assets/vignette-with-crayon.Rmd + Writing test.html --- diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 18a38c996..8d7d4e5b0 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -21,6 +21,9 @@ Code pkgdown_sitrep(pkg) + Message + '_pkgdown.yml' contains URL + 'DESCRIPTION' contains URL # pkgdown_sitrep works [ansi] @@ -45,6 +48,9 @@ Code pkgdown_sitrep(pkg) + Message + _pkgdown.yml contains URL  + DESCRIPTION contains URL  # pkgdown_sitrep works [unicode] @@ -69,6 +75,9 @@ Code pkgdown_sitrep(pkg) + Message + '_pkgdown.yml' contains URL + 'DESCRIPTION' contains URL # pkgdown_sitrep works [fancy] @@ -93,4 +102,7 @@ Code pkgdown_sitrep(pkg) + Message + _pkgdown.yml contains URL  + DESCRIPTION contains URL  diff --git a/tests/testthat/_snaps/topics.md b/tests/testthat/_snaps/topics.md index f4d173991..ef6c87a05 100644 --- a/tests/testthat/_snaps/topics.md +++ b/tests/testthat/_snaps/topics.md @@ -6,44 +6,41 @@ Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be valid R code - x Not "x + " + ! In '_pkgdown.yml', topic must be valid R code, not "x + " Code t <- select_topics("y", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not "y" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "y" Code t <- select_topics("paste(1)", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a known selector function - x Not "paste(1)" + ! In '_pkgdown.yml', topic must be a known selector function, not "paste(1)" + Caused by error in `paste()`: + ! could not find function "paste" Code t <- select_topics("starts_with", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not "starts_with" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "starts_with" Code t <- select_topics("1", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a string or function call - x Not "1" + ! In '_pkgdown.yml', topic must be a string or function call, not "1" Code t <- select_topics("starts_with('y')", topics, check = TRUE) Condition - Error in `select_topics()`: + Error: ! No topics matched in '_pkgdown.yml'. No topics selected. # can select by name or alias @@ -54,16 +51,14 @@ Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not "a4" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "a4" Code select_topics("c::a", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error in `topic_must()`: - ! In '_pkgdown.yml', topic must be a known topic name or alias - x Not "c::a" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "c::a" # an unmatched selection generates a warning @@ -71,6 +66,5 @@ select_topics(c("a", "starts_with('unmatched')"), topics, check = TRUE) Condition Error in `topic_must()`: - ! In '_pkgdown.yml', topic must match a function or concept - x Not "starts_with('unmatched')" + ! In '_pkgdown.yml', topic must match a function or concept, not "starts_with('unmatched')" diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index 80129eeb7..1e5a5d606 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -11,12 +11,12 @@ check_yaml_has("x", where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x component in '_pkgdown.yml'. + ! Can't find component a.x in '_pkgdown.yml'. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x and a.y components in '_pkgdown.yml'. + ! Can't find components a.x and a.y in '_pkgdown.yml'. # pkgdown_field(s) produces useful description [ansi] @@ -31,12 +31,12 @@ check_yaml_has("x", where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x component in _pkgdown.yml. + ! Can't find component a.x in _pkgdown.yml. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x and a.y components in _pkgdown.yml. + ! Can't find components a.x and a.y in _pkgdown.yml. # pkgdown_field(s) produces useful description [unicode] @@ -51,12 +51,12 @@ check_yaml_has("x", where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x component in '_pkgdown.yml'. + ! Can't find component a.x in '_pkgdown.yml'. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x and a.y components in '_pkgdown.yml'. + ! Can't find components a.x and a.y in '_pkgdown.yml'. # pkgdown_field(s) produces useful description [fancy] @@ -71,10 +71,10 @@ check_yaml_has("x", where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x component in _pkgdown.yml. + ! Can't find component a.x in _pkgdown.yml. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find a.x and a.y components in _pkgdown.yml. + ! Can't find components a.x and a.y in _pkgdown.yml. diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 3701091ce..1a1bf9978 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -33,7 +33,7 @@ cli::test_that_cli("warns about missing images", { test_that("articles don't include header-attrs.js script", { pkg <- as_pkgdown(test_path("assets/articles")) - withr::defer(clean_site(pkg)) + withr::defer(clean_site(pkg, quiet = TRUE)) expect_snapshot(path <- build_article("standard", pkg)) diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index de81ebe25..5644a0249 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -1,6 +1,6 @@ cli::test_that_cli("parse failures include file name", { skip_if_not(getRversion() >= "4.0.0") - pkg <- local_pkgdown_site("assets/reference-fail") + pkg <- local_pkgdown_site(test_path("assets/reference-fail")) expect_snapshot(build_reference(pkg), error = TRUE) }) @@ -35,7 +35,7 @@ cli::test_that_cli("test usage ok on rendered page", { expect_snapshot(build_reference(pkg, topics = "c")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) expect_equal(xpath_text(html, "//div[@id='ref-usage']", trim = TRUE), "c()") - clean_site(pkg) + clean_site(pkg, quiet = TRUE) pkg <- local_pkgdown_site(test_path("assets/reference"), " template: @@ -53,7 +53,7 @@ cli::test_that_cli(".Rd without usage doesn't get Usage section", { expect_snapshot(build_reference(pkg, topics = "e")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "e.html")) expect_equal(xpath_length(html, "//div[@id='ref-usage']"), 0) - clean_site(pkg) + clean_site(pkg, quiet = TRUE) pkg <- local_pkgdown_site(test_path("assets/reference"), " template: diff --git a/tests/testthat/test-build-search-docs.R b/tests/testthat/test-build-search-docs.R index 4fa477cda..ad61a7a86 100644 --- a/tests/testthat/test-build-search-docs.R +++ b/tests/testthat/test-build-search-docs.R @@ -1,7 +1,8 @@ test_that("docsearch.json and sitemap.xml are valid", { pkg <- local_pkgdown_site(test_path("assets/search-site")) - expect_snapshot(build_site(pkg, new_process = FALSE)) + # can't use expect_snapshot() here because the dst_path is different each time + suppressMessages(expect_message(build_site(pkg, new_process = FALSE))) json <- path(pkg$dst_path, "docsearch.json") expect_true(jsonlite::validate(read_lines(json))) @@ -21,10 +22,13 @@ test_that("build_search() builds the expected search`.json with an URL", { mode: devel ') - expect_snapshot(init_site(pkg)) - expect_snapshot(build_news(pkg)) - expect_snapshot(build_home(pkg)) - expect_snapshot(build_sitemap(pkg)) + # can't use expect_snapshot() here because the dst_path is different each time + # expect_message caputres the messages from from build_* and init_site functions + # suppressMessages prevents the messages from spilling into the testthat results + suppressMessages(expect_message(init_site(pkg))) + suppressMessages(expect_message(build_news(pkg))) + suppressMessages(expect_message(build_home(pkg))) + suppressMessages(expect_message(build_sitemap(pkg))) json_path <- withr::local_tempfile() jsonlite::write_json(build_search_index(pkg), json_path, pretty = TRUE) @@ -41,10 +45,13 @@ test_that("build_search() builds the expected search.json with no URL", { mode: devel ') - expect_snapshot(init_site(pkg)) - expect_snapshot(build_news(pkg)) - expect_snapshot(build_home(pkg)) - expect_snapshot(build_sitemap(pkg)) + # expect_message caputres the messages from from build_* and init_site functions + # suppressMessages prevents the messages from spilling into the testthat results + + suppressMessages(expect_message(init_site(pkg))) + suppressMessages(expect_message(build_news(pkg))) + suppressMessages(expect_message(build_home(pkg))) + suppressMessages(expect_message(build_sitemap(pkg))) json_path <- withr::local_tempfile() jsonlite::write_json(build_search_index(pkg), json_path, pretty = TRUE) From f69afe725b6479296b27c7131d4b68ff09f8acf2 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Mon, 27 Nov 2023 13:44:07 -0700 Subject: [PATCH 15/20] add `local_edition(3)` to fix snapshot tests --- tests/testthat/_snaps/build-articles.md | 41 +-- tests/testthat/_snaps/build-home-authors.md | 32 +-- tests/testthat/_snaps/build-home.md | 41 +-- tests/testthat/_snaps/build-logo.md | 26 +- tests/testthat/_snaps/build-news.md | 71 +---- .../testthat/_snaps/build-reference-index.md | 111 +------- tests/testthat/_snaps/build-reference.md | 219 +--------------- tests/testthat/_snaps/check.md | 75 +----- tests/testthat/_snaps/figure.md | 56 +--- tests/testthat/_snaps/init.md | 167 +----------- tests/testthat/_snaps/rd-example.md | 26 +- tests/testthat/_snaps/rd-html.md | 242 +----------------- tests/testthat/_snaps/render.md | 26 +- tests/testthat/_snaps/rmarkdown.md | 114 +-------- tests/testthat/_snaps/sitrep.md | 83 +----- tests/testthat/_snaps/utils-yaml.md | 62 +---- tests/testthat/test-build-articles.R | 3 +- tests/testthat/test-build-home-authors.R | 3 +- tests/testthat/test-build-home.R | 3 +- tests/testthat/test-build-logo.R | 4 +- tests/testthat/test-build-news.R | 3 +- tests/testthat/test-build-reference-index.R | 9 +- tests/testthat/test-build-reference.R | 9 +- tests/testthat/test-check.R | 9 +- tests/testthat/test-figure.R | 3 +- tests/testthat/test-init.R | 12 +- tests/testthat/test-rd-example.R | 4 +- tests/testthat/test-rd-html.R | 15 +- tests/testthat/test-rmarkdown.R | 9 +- tests/testthat/test-sitrep.R | 4 +- tests/testthat/test-utils-yaml.R | 4 +- 31 files changed, 94 insertions(+), 1392 deletions(-) diff --git a/tests/testthat/_snaps/build-articles.md b/tests/testthat/_snaps/build-articles.md index 33f1df726..bed3dc4c3 100644 --- a/tests/testthat/_snaps/build-articles.md +++ b/tests/testthat/_snaps/build-articles.md @@ -15,7 +15,7 @@ Reading vignettes/kitten.Rmd Writing articles/kitten.html -# warns about missing images [plain] +# warns about missing images Code build_articles(pkg) @@ -28,45 +28,6 @@ Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' i pkgdown can only use images in 'man/figures' and 'vignettes' -# warns about missing images [ansi] - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/html-vignette.Rmd - Writing articles/html-vignette.html - Condition - Warning: - Missing images in vignettes/html-vignette.Rmd: foo.png - i pkgdown can only use images in man/figures and vignettes - -# warns about missing images [unicode] - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/html-vignette.Rmd - Writing articles/html-vignette.html - Condition - Warning: - Missing images in 'vignettes/html-vignette.Rmd': 'foo.png' - ℹ pkgdown can only use images in 'man/figures' and 'vignettes' - -# warns about missing images [fancy] - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/html-vignette.Rmd - Writing articles/html-vignette.html - Condition - Warning: - Missing images in vignettes/html-vignette.Rmd: foo.png - ℹ pkgdown can only use images in man/figures and vignettes - # articles don't include header-attrs.js script Code diff --git a/tests/testthat/_snaps/build-home-authors.md b/tests/testthat/_snaps/build-home-authors.md index c6429c32c..361466b5a 100644 --- a/tests/testthat/_snaps/build-home-authors.md +++ b/tests/testthat/_snaps/build-home-authors.md @@ -16,7 +16,7 @@ -# role has multiple fallbacks [plain] +# role has multiple fallbacks Code role_lookup("unknown") @@ -26,33 +26,3 @@ Output [1] "unknown" -# role has multiple fallbacks [ansi] - - Code - role_lookup("unknown") - Condition - Warning: - Unknown MARC role abbreviation: unknown - Output - [1] "unknown" - -# role has multiple fallbacks [unicode] - - Code - role_lookup("unknown") - Condition - Warning: - Unknown MARC role abbreviation: unknown - Output - [1] "unknown" - -# role has multiple fallbacks [fancy] - - Code - role_lookup("unknown") - Condition - Warning: - Unknown MARC role abbreviation: unknown - Output - [1] "unknown" - diff --git a/tests/testthat/_snaps/build-home.md b/tests/testthat/_snaps/build-home.md index fdc38a3cd..cf1bf5b85 100644 --- a/tests/testthat/_snaps/build-home.md +++ b/tests/testthat/_snaps/build-home.md @@ -14,7 +14,7 @@ Writing authors.html Writing 404.html -# warns about missing images [plain] +# warns about missing images Code build_home(pkg) @@ -27,45 +27,6 @@ Message Writing 404.html -# warns about missing images [ansi] - - Code - build_home(pkg) - Message - Writing authors.html - Condition - Warning: - Missing images in README.md: foo.png - i pkgdown can only use images in man/figures and vignettes - Message - Writing 404.html - -# warns about missing images [unicode] - - Code - build_home(pkg) - Message - Writing authors.html - Condition - Warning: - Missing images in 'README.md': 'foo.png' - ℹ pkgdown can only use images in 'man/figures' and 'vignettes' - Message - Writing 404.html - -# warns about missing images [fancy] - - Code - build_home(pkg) - Message - Writing authors.html - Condition - Warning: - Missing images in README.md: foo.png - ℹ pkgdown can only use images in man/figures and vignettes - Message - Writing 404.html - # can build site even if no Authors@R present Code diff --git a/tests/testthat/_snaps/build-logo.md b/tests/testthat/_snaps/build-logo.md index 889c7bc5f..bf005edad 100644 --- a/tests/testthat/_snaps/build-logo.md +++ b/tests/testthat/_snaps/build-logo.md @@ -1,4 +1,4 @@ -# can handle logo in subdir [plain] +# can handle logo in subdir Code copy_logo(pkg) @@ -6,27 +6,3 @@ Copying man/figures/logo.svg to logo.svg -# can handle logo in subdir [ansi] - - Code - copy_logo(pkg) - Message - Copying man/figures/logo.svg - to logo.svg - -# can handle logo in subdir [unicode] - - Code - copy_logo(pkg) - Message - Copying man/figures/logo.svg - to logo.svg - -# can handle logo in subdir [fancy] - - Code - copy_logo(pkg) - Message - Copying man/figures/logo.svg - to logo.svg - diff --git a/tests/testthat/_snaps/build-news.md b/tests/testthat/_snaps/build-news.md index fa420cd76..0209c2e89 100644 --- a/tests/testthat/_snaps/build-news.md +++ b/tests/testthat/_snaps/build-news.md @@ -14,7 +14,7 @@ 1 1.0.0.9000 dev testpackage-1009000 2 1.0.0 1.0 testpackage-100 -# multi-page news are rendered [plain] +# multi-page news are rendered Code data_news(pkg)[c("version", "page", "anchor")] @@ -37,75 +37,6 @@ Writing news/news-1.0.html Writing news/index.html -# multi-page news are rendered [ansi] - - Code - data_news(pkg)[c("version", "page", "anchor")] - Output - # A tibble: 4 x 3 - version page anchor -    - 1 2.0 2.0 testpackage-20 - 2 1.1 1.1 testpackage-11 - 3 1.0.1 1.0 testpackage-101 - 4 1.0.0 1.0 testpackage-100 - ---- - - Code - build_news(pkg) - Message - Writing news/news-2.0.html - Writing news/news-1.1.html - Writing news/news-1.0.html - Writing news/index.html - -# multi-page news are rendered [unicode] - - Code - data_news(pkg)[c("version", "page", "anchor")] - Output - # A tibble: 4 × 3 - version page anchor - - 1 2.0 2.0 testpackage-20 - 2 1.1 1.1 testpackage-11 - 3 1.0.1 1.0 testpackage-101 - 4 1.0.0 1.0 testpackage-100 - ---- - - Code - build_news(pkg) - Message - Writing news/news-2.0.html - Writing news/news-1.1.html - Writing news/news-1.0.html - Writing news/index.html - -# multi-page news are rendered [fancy] - - Code - data_news(pkg)[c("version", "page", "anchor")] - Output - # A tibble: 4 × 3 - version page anchor -    - 1 2.0 2.0 testpackage-20 - 2 1.1 1.1 testpackage-11 - 3 1.0.1 1.0 testpackage-101 - 4 1.0.0 1.0 testpackage-100 - ---- - - Code - build_news(pkg) - Message - Writing news/news-2.0.html - Writing news/news-1.1.html - Writing news/news-1.0.html - Writing news/index.html - # news headings get class and release date
diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index aed65b432..ee7ea4cfe 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -62,7 +62,7 @@ ! Item 2 in section 1 in reference is empty. i Either delete the empty line or add a function name in '_pkgdown.yml'. -# errors well when a content entry is not a character [plain] +# errors well when a content entry is not a character Code build_reference_index(pkg) @@ -73,40 +73,7 @@ ! Item 2 in section 1 in reference must be a character. i You might need to add '' around e.g. - 'N' or - 'off' in '_pkgdown.yml'. -# errors well when a content entry is not a character [ansi] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - i In index: 1. - Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference must be a character. - i You might need to add '' around e.g. - 'N' or - 'off' in _pkgdown.yml. - -# errors well when a content entry is not a character [unicode] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference must be a character. - ℹ You might need to add '' around e.g. - 'N' or - 'off' in '_pkgdown.yml'. - -# errors well when a content entry is not a character [fancy] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference must be a character. - ℹ You might need to add '' around e.g. - 'N' or - 'off' in _pkgdown.yml. - -# errors well when a content entry refers to a not installed package [plain] +# errors well when a content entry refers to a not installed package Code build_reference_index(pkg) @@ -118,43 +85,7 @@ Caused by error in `.f()`: ! The package "notapackage" is required as it's used in the reference index. -# errors well when a content entry refers to a not installed package [ansi] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - i In index: 1. - Caused by error in `purrr::map2()`: - i In index: 1. - Caused by error in `.f()`: - ! The package "notapackage" is required as it's used in the reference index. - -# errors well when a content entry refers to a not installed package [unicode] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `purrr::map2()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! The package "notapackage" is required as it's used in the reference index. - -# errors well when a content entry refers to a not installed package [fancy] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `purrr::map2()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! The package "notapackage" is required as it's used in the reference index. - -# errors well when a content entry refers to a non existing function [plain] +# errors well when a content entry refers to a non existing function Code build_reference_index(pkg) @@ -166,42 +97,6 @@ Caused by error in `.f()`: ! Could not find documentation for `rlang::lala()`. -# errors well when a content entry refers to a non existing function [ansi] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - i In index: 1. - Caused by error in `purrr::map2()`: - i In index: 1. - Caused by error in `.f()`: - ! Could not find documentation for `rlang::lala()`. - -# errors well when a content entry refers to a non existing function [unicode] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `purrr::map2()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! Could not find documentation for `rlang::lala()`. - -# errors well when a content entry refers to a non existing function [fancy] - - Code - build_reference_index(pkg) - Condition - Error in `map2()`: - ℹ In index: 1. - Caused by error in `purrr::map2()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! Could not find documentation for `rlang::lala()`. - # can use a topic from another package Code diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index e78a2791a..eeec43842 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -1,4 +1,4 @@ -# parse failures include file name [plain] +# parse failures include file name Code build_reference(pkg) @@ -17,116 +17,7 @@ ! Failed to parse tag "\\url{}". x Check for empty \url{} tags. -# parse failures include file name [ansi] - - Code - build_reference(pkg) - Message - Writing reference/index.html - Reading man/f.Rd - Condition - Error in `purrr::map()`: - i In index: 1. - i With name: f.Rd. - Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - Caused by error in `purrr::map()`: - i In index: 4. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - x Check for empty \url{} tags. - -# parse failures include file name [unicode] - - Code - build_reference(pkg) - Message - Writing reference/index.html - Reading man/f.Rd - Condition - Error in `purrr::map()`: - ℹ In index: 1. - ℹ With name: f.Rd. - Caused by error in `.f()`: - ! Failed to parse Rd in 'f.Rd' - Caused by error in `purrr::map()`: - ℹ In index: 4. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ Check for empty \url{} tags. - -# parse failures include file name [fancy] - - Code - build_reference(pkg) - Message - Writing reference/index.html - Reading man/f.Rd - Condition - Error in `purrr::map()`: - ℹ In index: 1. - ℹ With name: f.Rd. - Caused by error in `.f()`: - ! Failed to parse Rd in f.Rd - Caused by error in `purrr::map()`: - ℹ In index: 4. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ Check for empty \url{} tags. - -# test usage ok on rendered page [plain] - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - -# test usage ok on rendered page [ansi] - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - -# test usage ok on rendered page [unicode] +# test usage ok on rendered page Code build_reference(pkg, topics = "c") @@ -152,85 +43,7 @@ Reading man/c.Rd Writing reference/c.html -# test usage ok on rendered page [fancy] - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - -# .Rd without usage doesn't get Usage section [plain] - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - -# .Rd without usage doesn't get Usage section [ansi] - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - -# .Rd without usage doesn't get Usage section [unicode] +# .Rd without usage doesn't get Usage section Code build_reference(pkg, topics = "e") @@ -256,32 +69,6 @@ Reading man/e.Rd Writing reference/e.html -# .Rd without usage doesn't get Usage section [fancy] - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "e") - Message - Writing reference/index.html - Reading man/e.Rd - Writing reference/e.html - # pkgdown html dependencies are suppressed from examples in references Code diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index bbb19b5e4..23dd24cee 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -1,4 +1,4 @@ -# fails if reference index incomplete [plain] +# fails if reference index incomplete Code check_pkgdown(pkg) @@ -8,53 +8,7 @@ x Missing topics: ? i Either add to _pkgdown.yml or use @keywords internal -# fails if reference index incomplete [ansi] - - Code - check_pkgdown(pkg) - Condition - Error in `check_missing_topics()`: - ! All topics must be included in reference index - x Missing topics: ? - i Either add to _pkgdown.yml or use @keywords internal - -# fails if reference index incomplete [unicode] - - Code - check_pkgdown(pkg) - Condition - Error in `check_missing_topics()`: - ! All topics must be included in reference index - ✖ Missing topics: ? - ℹ Either add to _pkgdown.yml or use @keywords internal - -# fails if reference index incomplete [fancy] - - Code - check_pkgdown(pkg) - Condition - Error in `check_missing_topics()`: - ! All topics must be included in reference index - ✖ Missing topics: ? - ℹ Either add to _pkgdown.yml or use @keywords internal - -# fails if article index incomplete [plain] - - Code - check_pkgdown(pkg) - Condition - Error in `data_articles_index()`: - ! Vignettes missing from index: 'articles/nested' and 'width' - -# fails if article index incomplete [ansi] - - Code - check_pkgdown(pkg) - Condition - Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width - -# fails if article index incomplete [unicode] +# fails if article index incomplete Code check_pkgdown(pkg) @@ -62,30 +16,7 @@ Error in `data_articles_index()`: ! Vignettes missing from index: 'articles/nested' and 'width' -# fails if article index incomplete [fancy] - - Code - check_pkgdown(pkg) - Condition - Error in `data_articles_index()`: - ! Vignettes missing from index: articles/nested and width - -# informs if everything is ok [plain] - - Code - check_pkgdown(pkg) - -# informs if everything is ok [ansi] - - Code - check_pkgdown(pkg) - -# informs if everything is ok [unicode] - - Code - check_pkgdown(pkg) - -# informs if everything is ok [fancy] +# informs if everything is ok Code check_pkgdown(pkg) diff --git a/tests/testthat/_snaps/figure.md b/tests/testthat/_snaps/figure.md index 25fcbf24c..462dbe54c 100644 --- a/tests/testthat/_snaps/figure.md +++ b/tests/testthat/_snaps/figure.md @@ -1,4 +1,4 @@ -# can override defaults in _pkgdown.yml [plain] +# can override defaults in _pkgdown.yml Code build_reference(pkg, devel = FALSE) @@ -16,57 +16,3 @@ Reading vignettes/figures.Rmd Writing articles/figures.html -# can override defaults in _pkgdown.yml [ansi] - - Code - build_reference(pkg, devel = FALSE) - Message - Writing reference/index.html - Reading man/figure.Rd - Writing reference/figure.html - ---- - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/figures.Rmd - Writing articles/figures.html - -# can override defaults in _pkgdown.yml [unicode] - - Code - build_reference(pkg, devel = FALSE) - Message - Writing reference/index.html - Reading man/figure.Rd - Writing reference/figure.html - ---- - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/figures.Rmd - Writing articles/figures.html - -# can override defaults in _pkgdown.yml [fancy] - - Code - build_reference(pkg, devel = FALSE) - Message - Writing reference/index.html - Reading man/figure.Rd - Writing reference/figure.html - ---- - - Code - build_articles(pkg) - Message - Writing articles/index.html - Reading vignettes/figures.Rmd - Writing articles/figures.html - diff --git a/tests/testthat/_snaps/init.md b/tests/testthat/_snaps/init.md index 9f4f2bc4e..d1e168bff 100644 --- a/tests/testthat/_snaps/init.md +++ b/tests/testthat/_snaps/init.md @@ -1,4 +1,4 @@ -# extra.css and extra.js copied and linked [plain] +# extra.css and extra.js copied and linked Code init_site(pkg) @@ -16,81 +16,7 @@ Writing authors.html Writing 404.html -# extra.css and extra.js copied and linked [ansi] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css and pkgdown/extra.js - to extra.css and extra.js - ---- - - Code - build_home(pkg) - Message - Writing authors.html - Writing 404.html - -# extra.css and extra.js copied and linked [unicode] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css and pkgdown/extra.js - to extra.css and extra.js - ---- - - Code - build_home(pkg) - Message - Writing authors.html - Writing 404.html - -# extra.css and extra.js copied and linked [fancy] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css and pkgdown/extra.js - to extra.css and extra.js - ---- - - Code - build_home(pkg) - Message - Writing authors.html - Writing 404.html - -# single extra.css correctly copied [plain] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css - to extra.css - -# single extra.css correctly copied [ansi] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css - to extra.css - -# single extra.css correctly copied [unicode] +# single extra.css correctly copied Code init_site(pkg) @@ -100,17 +26,7 @@ Copying pkgdown/extra.css to extra.css -# single extra.css correctly copied [fancy] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css - to extra.css - -# asset subdirectories are copied [plain] +# asset subdirectories are copied Code init_site(pkg) @@ -120,82 +36,7 @@ Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt to subdir1/file1.txt and subdir1/subdir2/file2.txt -# asset subdirectories are copied [ansi] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt - to subdir1/file1.txt and subdir1/subdir2/file2.txt - -# asset subdirectories are copied [unicode] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt - to subdir1/file1.txt and subdir1/subdir2/file2.txt - -# asset subdirectories are copied [fancy] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt - to subdir1/file1.txt and subdir1/subdir2/file2.txt - -# site meta doesn't break unexpectedly [plain] - - Code - yaml - Output - pandoc: '{version}' - pkgdown: '{version}' - pkgdown_sha: '{sha}' - articles: {} - last_built: 2020-01-01T00:00Z - urls: - reference: http://test.org/reference - article: http://test.org/articles - - -# site meta doesn't break unexpectedly [ansi] - - Code - yaml - Output - pandoc: '{version}' - pkgdown: '{version}' - pkgdown_sha: '{sha}' - articles: {} - last_built: 2020-01-01T00:00Z - urls: - reference: http://test.org/reference - article: http://test.org/articles - - -# site meta doesn't break unexpectedly [unicode] - - Code - yaml - Output - pandoc: '{version}' - pkgdown: '{version}' - pkgdown_sha: '{sha}' - articles: {} - last_built: 2020-01-01T00:00Z - urls: - reference: http://test.org/reference - article: http://test.org/articles - - -# site meta doesn't break unexpectedly [fancy] +# site meta doesn't break unexpectedly Code yaml diff --git a/tests/testthat/_snaps/rd-example.md b/tests/testthat/_snaps/rd-example.md index ec108cd11..8d4c6fc03 100644 --- a/tests/testthat/_snaps/rd-example.md +++ b/tests/testthat/_snaps/rd-example.md @@ -1,4 +1,4 @@ -# @examplesIf [plain] +# @examplesIf Code expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) @@ -6,27 +6,3 @@ Warning: @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" -# @examplesIf [ansi] - - Code - expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) - Condition - Warning: - @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" - -# @examplesIf [unicode] - - Code - expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) - Condition - Warning: - @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" - -# @examplesIf [fancy] - - Code - expect_equal(strtrim(rd2ex(rd3), 40), strtrim(exp3, 40)) - Condition - Warning: - @examplesIf condition "TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && TRUE && FALSE" is "FALSE" - diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index c15bd53d2..6b3d3f710 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -1,4 +1,4 @@ -# subsection generates h3 [plain] +# subsection generates h3 Code cli::cat_line(rd2html("\\subsection{A}{B}")) @@ -19,96 +19,7 @@

p2

-# subsection generates h3 [ansi] - - Code - cli::cat_line(rd2html("\\subsection{A}{B}")) - Output -
-

A

-

B

-
- ---- - - Code - cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) - Output -
-

A

-

p1

-

p2

-
- -# subsection generates h3 [unicode] - - Code - cli::cat_line(rd2html("\\subsection{A}{B}")) - Output -
-

A

-

B

-
- ---- - - Code - cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) - Output -
-

A

-

p1

-

p2

-
- -# subsection generates h3 [fancy] - - Code - cli::cat_line(rd2html("\\subsection{A}{B}")) - Output -
-

A

-

B

-
- ---- - - Code - cli::cat_line(rd2html("\\subsection{A}{\n p1\n\n p2\n }")) - Output -
-

A

-

p1

-

p2

-
- -# nested subsection generates h4 [plain] - - Code - cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) - Output -
-

H3

-
-

H4

- -
-
- -# nested subsection generates h4 [ansi] - - Code - cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) - Output -
-

H3

-
-

H4

- -
-
- -# nested subsection generates h4 [unicode] +# nested subsection generates h4 Code cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) @@ -121,20 +32,7 @@ -# nested subsection generates h4 [fancy] - - Code - cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}")) - Output -
-

H3

-
-

H4

- -
-
- -# Sexprs with multiple args are parsed [plain] +# Sexprs with multiple args are parsed Code rd2html("\\Sexpr[results=verbatim]{1}") @@ -144,37 +42,7 @@ Caused by error in `.f()`: ! \\Sexpr{result=verbatim} not yet supported -# Sexprs with multiple args are parsed [ansi] - - Code - rd2html("\\Sexpr[results=verbatim]{1}") - Condition - Error in `purrr::map_chr()`: - i In index: 1. - Caused by error in `.f()`: - ! \\Sexpr{result=verbatim} not yet supported - -# Sexprs with multiple args are parsed [unicode] - - Code - rd2html("\\Sexpr[results=verbatim]{1}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! \\Sexpr{result=verbatim} not yet supported - -# Sexprs with multiple args are parsed [fancy] - - Code - rd2html("\\Sexpr[results=verbatim]{1}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `.f()`: - ! \\Sexpr{result=verbatim} not yet supported - -# bad specs throw errors [plain] +# bad specs throw errors Code rd2html("\\url{}") @@ -208,108 +76,6 @@ Caused by error in `stop_bad_tag()`: ! Failed to parse tag "\\linkS4class{}". -# bad specs throw errors [ansi] - - Code - rd2html("\\url{}") - Condition - Error in `purrr::map_chr()`: - i In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - x Check for empty \url{} tags. - Code - rd2html("\\url{a\nb}") - Condition - Error in `purrr::map_chr()`: - i In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - x This may be caused by a \url tag that spans a line break. - Code - rd2html("\\email{}") - Condition - Error in `purrr::map_chr()`: - i In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\email{}". - x empty - Code - rd2html("\\linkS4class{}") - Condition - Error in `purrr::map_chr()`: - i In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\linkS4class{}". - -# bad specs throw errors [unicode] - - Code - rd2html("\\url{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ Check for empty \url{} tags. - Code - rd2html("\\url{a\nb}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ This may be caused by a \url tag that spans a line break. - Code - rd2html("\\email{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\email{}". - ✖ empty - Code - rd2html("\\linkS4class{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\linkS4class{}". - -# bad specs throw errors [fancy] - - Code - rd2html("\\url{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ Check for empty \url{} tags. - Code - rd2html("\\url{a\nb}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\url{}". - ✖ This may be caused by a \url tag that spans a line break. - Code - rd2html("\\email{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\email{}". - ✖ empty - Code - rd2html("\\linkS4class{}") - Condition - Error in `purrr::map_chr()`: - ℹ In index: 1. - Caused by error in `stop_bad_tag()`: - ! Failed to parse tag "\\linkS4class{}". - # \describe items can contain multiple paragraphs
diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index 73767cc5c..f125a3cab 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -52,7 +52,7 @@ right:

Site built with pkgdown {version}.

-# can include text in header, before body, and after body [plain] +# can include text in header, before body, and after body Code init_site(pkg) @@ -60,27 +60,3 @@ Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js to link.svg and pkgdown.js -# can include text in header, before body, and after body [ansi] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - -# can include text in header, before body, and after body [unicode] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - -# can include text in header, before body, and after body [fancy] - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md index aa291fc7d..e5f92a0f7 100644 --- a/tests/testthat/_snaps/rmarkdown.md +++ b/tests/testthat/_snaps/rmarkdown.md @@ -1,4 +1,4 @@ -# render_rmarkdown copies image files in subdirectories [plain] +# render_rmarkdown copies image files in subdirectories Code render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") @@ -6,31 +6,7 @@ Reading assets/vignette-with-img.Rmd Writing test.html -# render_rmarkdown copies image files in subdirectories [ansi] - - Code - render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") - Message - Reading assets/vignette-with-img.Rmd - Writing test.html - -# render_rmarkdown copies image files in subdirectories [unicode] - - Code - render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") - Message - Reading assets/vignette-with-img.Rmd - Writing test.html - -# render_rmarkdown copies image files in subdirectories [fancy] - - Code - render_rmarkdown(pkg, "assets/vignette-with-img.Rmd", "test.html") - Message - Reading assets/vignette-with-img.Rmd - Writing test.html - -# render_rmarkdown yields useful error [plain] +# render_rmarkdown yields useful error Code render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( @@ -45,78 +21,7 @@ Caused by error: ! pandoc document conversion failed with error 3 -# render_rmarkdown yields useful error [ansi] - - Code - render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( - pandoc_args = "--fail-if-warnings")) - Message - Reading assets/pandoc-fail.Rmd - Condition - Error in `render_rmarkdown()`: - ! Failed to render RMarkdown document - Caused by error: - ! in callr subprocess. - Caused by error: - ! pandoc document conversion failed with error 3 - -# render_rmarkdown yields useful error [unicode] - - Code - render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( - pandoc_args = "--fail-if-warnings")) - Message - Reading assets/pandoc-fail.Rmd - Condition - Error in `render_rmarkdown()`: - ! Failed to render RMarkdown document - Caused by error: - ! in callr subprocess. - Caused by error: - ! pandoc document conversion failed with error 3 - -# render_rmarkdown yields useful error [fancy] - - Code - render_rmarkdown(pkg, "assets/pandoc-fail.Rmd", "test.html", output_format = rmarkdown::html_document( - pandoc_args = "--fail-if-warnings")) - Message - Reading assets/pandoc-fail.Rmd - Condition - Error in `render_rmarkdown()`: - ! Failed to render RMarkdown document - Caused by error: - ! in callr subprocess. - Caused by error: - ! pandoc document conversion failed with error 3 - -# render_rmarkdown styles ANSI escapes [plain] - - Code - path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", - output = "test.html") - Message - Reading assets/vignette-with-crayon.Rmd - Writing test.html - ---- - - #> X - -# render_rmarkdown styles ANSI escapes [ansi] - - Code - path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", - output = "test.html") - Message - Reading assets/vignette-with-crayon.Rmd - Writing test.html - ---- - - #> X - -# render_rmarkdown styles ANSI escapes [unicode] +# render_rmarkdown styles ANSI escapes Code path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", @@ -129,16 +34,3 @@ #> X -# render_rmarkdown styles ANSI escapes [fancy] - - Code - path <- render_rmarkdown(pkg, input = "assets/vignette-with-crayon.Rmd", - output = "test.html") - Message - Reading assets/vignette-with-crayon.Rmd - Writing test.html - ---- - - #> X - diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 8d7d4e5b0..f2d595f71 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -1,4 +1,4 @@ -# pkgdown_sitrep works [plain] +# pkgdown_sitrep works Code pkgdown_sitrep(pkg) @@ -25,84 +25,3 @@ '_pkgdown.yml' contains URL 'DESCRIPTION' contains URL -# pkgdown_sitrep works [ansi] - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - x url is not configured in _pkgdown.yml. See `vignette(pkgdown::metatdata)`. - x DESCRIPTION URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - x DESCRIPTION URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Message - _pkgdown.yml contains URL  - DESCRIPTION contains URL  - -# pkgdown_sitrep works [unicode] - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - ✖ url is not configured in '_pkgdown.yml'. See `vignette(pkgdown::metatdata)`. - ✖ 'DESCRIPTION' URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - ✖ 'DESCRIPTION' URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Message - '_pkgdown.yml' contains URL - 'DESCRIPTION' contains URL - -# pkgdown_sitrep works [fancy] - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - ✖ url is not configured in _pkgdown.yml. See `vignette(pkgdown::metatdata)`. - ✖ DESCRIPTION URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Condition - Warning: - pkgdown situation report: configuration error - ✖ DESCRIPTION URL is empty. - ---- - - Code - pkgdown_sitrep(pkg) - Message - _pkgdown.yml contains URL  - DESCRIPTION contains URL  - diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index 1e5a5d606..ee3e1b483 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -1,4 +1,4 @@ -# pkgdown_field(s) produces useful description [plain] +# pkgdown_field(s) produces useful description Code pkgdown_field(c("a", "b")) @@ -18,63 +18,3 @@ Error in `check_yaml_has()`: ! Can't find components a.x and a.y in '_pkgdown.yml'. -# pkgdown_field(s) produces useful description [ansi] - - Code - pkgdown_field(c("a", "b")) - Output - [1] "a.b" - ---- - - Code - check_yaml_has("x", where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find component a.x in _pkgdown.yml. - Code - check_yaml_has(c("x", "y"), where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find components a.x and a.y in _pkgdown.yml. - -# pkgdown_field(s) produces useful description [unicode] - - Code - pkgdown_field(c("a", "b")) - Output - [1] "a.b" - ---- - - Code - check_yaml_has("x", where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find component a.x in '_pkgdown.yml'. - Code - check_yaml_has(c("x", "y"), where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find components a.x and a.y in '_pkgdown.yml'. - -# pkgdown_field(s) produces useful description [fancy] - - Code - pkgdown_field(c("a", "b")) - Output - [1] "a.b" - ---- - - Code - check_yaml_has("x", where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find component a.x in _pkgdown.yml. - Code - check_yaml_has(c("x", "y"), where = "a", pkg = pkg) - Condition - Error in `check_yaml_has()`: - ! Can't find components a.x and a.y in _pkgdown.yml. - diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 1a1bf9978..6bd1d2aca 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -26,7 +26,8 @@ test_that("links to man/figures are automatically relocated", { expect_false(dir_exists(path(pkg$dst_path, "man"))) }) -cli::test_that_cli("warns about missing images", { +test_that("warns about missing images", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/bad-images")) expect_snapshot(build_articles(pkg)) }) diff --git a/tests/testthat/test-build-home-authors.R b/tests/testthat/test-build-home-authors.R index a6c2445b8..661d7dba9 100644 --- a/tests/testthat/test-build-home-authors.R +++ b/tests/testthat/test-build-home-authors.R @@ -55,7 +55,8 @@ test_that("data_home_sidebar_authors() works with text", { expect_snapshot(cat(data_home_sidebar_authors(pkg))) }) -cli::test_that_cli("role has multiple fallbacks", { +test_that("role has multiple fallbacks", { + local_edition(3) expect_equal(role_lookup("cre"), "maintainer") expect_equal(role_lookup("res"), "researcher") expect_snapshot(role_lookup("unknown")) diff --git a/tests/testthat/test-build-home.R b/tests/testthat/test-build-home.R index 4bf483e2c..6376a3592 100644 --- a/tests/testthat/test-build-home.R +++ b/tests/testthat/test-build-home.R @@ -21,7 +21,8 @@ test_that("intermediate files cleaned up automatically", { ) }) -cli::test_that_cli("warns about missing images", { +test_that("warns about missing images", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/bad-images")) expect_snapshot(build_home(pkg)) }) diff --git a/tests/testthat/test-build-logo.R b/tests/testthat/test-build-logo.R index 8737b0b11..5a97e1b87 100644 --- a/tests/testthat/test-build-logo.R +++ b/tests/testthat/test-build-logo.R @@ -1,4 +1,6 @@ -cli::test_that_cli("can handle logo in subdir", { +test_that("can handle logo in subdir", { + local_edition(3) + src <- withr::local_tempdir() dst <- withr::local_tempdir() diff --git a/tests/testthat/test-build-news.R b/tests/testthat/test-build-news.R index 15921fa45..0b6386e99 100644 --- a/tests/testthat/test-build-news.R +++ b/tests/testthat/test-build-news.R @@ -24,8 +24,9 @@ test_that("data_news works as expected for h1 & h2", { }) -cli::test_that_cli("multi-page news are rendered", { +test_that("multi-page news are rendered", { skip_if_no_pandoc() + local_edition(3) pkg <- local_pkgdown_site(meta = " news: diff --git a/tests/testthat/test-build-reference-index.R b/tests/testthat/test-build-reference-index.R index 5806e28e1..59ef31855 100644 --- a/tests/testthat/test-build-reference-index.R +++ b/tests/testthat/test-build-reference-index.R @@ -72,15 +72,17 @@ test_that("errors well when a content entry is empty", { expect_snapshot_error(build_reference_index(pkg)) }) -cli::test_that_cli("errors well when a content entry is not a character", { +test_that("errors well when a content entry is not a character", { + local_edition(3) meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - aname\n - N") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) expect_snapshot(build_reference_index(pkg), error = TRUE) }) -cli::test_that_cli("errors well when a content entry refers to a not installed package", { +test_that("errors well when a content entry refers to a not installed package", { skip_if_not_installed("cli", "3.1.0") + local_edition(3) meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - notapackage::lala") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) @@ -88,7 +90,8 @@ cli::test_that_cli("errors well when a content entry refers to a not installed p expect_snapshot(build_reference_index(pkg), error = TRUE) }) -cli::test_that_cli("errors well when a content entry refers to a non existing function", { +test_that("errors well when a content entry refers to a non existing function", { + local_edition(3) meta <- yaml::yaml.load( "reference:\n- title: bla\n contents:\n - rlang::lala") pkg <- as_pkgdown(test_path("assets/reference"), override = meta) diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index 5644a0249..e3b107c57 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -1,5 +1,6 @@ -cli::test_that_cli("parse failures include file name", { +test_that("parse failures include file name", { skip_if_not(getRversion() >= "4.0.0") + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference-fail")) expect_snapshot(build_reference(pkg), error = TRUE) }) @@ -30,7 +31,8 @@ test_that("examples_env sets width", { }) -cli::test_that_cli("test usage ok on rendered page", { +test_that("test usage ok on rendered page", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference")) expect_snapshot(build_reference(pkg, topics = "c")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) @@ -48,7 +50,8 @@ cli::test_that_cli("test usage ok on rendered page", { expect_equal(xpath_text(html, "//div[h2[@id='ref-usage']]/div", trim = TRUE), "c()") }) -cli::test_that_cli(".Rd without usage doesn't get Usage section", { +test_that(".Rd without usage doesn't get Usage section", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference")) expect_snapshot(build_reference(pkg, topics = "e")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "e.html")) diff --git a/tests/testthat/test-check.R b/tests/testthat/test-check.R index 796ddf33e..e3a9edb6b 100644 --- a/tests/testthat/test-check.R +++ b/tests/testthat/test-check.R @@ -1,4 +1,5 @@ -cli::test_that_cli("fails if reference index incomplete", { +test_that("fails if reference index incomplete", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference"), meta = " reference: - title: Title @@ -8,7 +9,8 @@ cli::test_that_cli("fails if reference index incomplete", { }) -cli::test_that_cli("fails if article index incomplete", { +test_that("fails if article index incomplete", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/articles"), meta = " articles: - title: Title @@ -17,7 +19,8 @@ cli::test_that_cli("fails if article index incomplete", { expect_snapshot(check_pkgdown(pkg), error = TRUE) }) -cli::test_that_cli("informs if everything is ok", { +test_that("informs if everything is ok", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference")) expect_snapshot(check_pkgdown(pkg)) }) diff --git a/tests/testthat/test-figure.R b/tests/testthat/test-figure.R index 0ac81796b..05e45633e 100644 --- a/tests/testthat/test-figure.R +++ b/tests/testthat/test-figure.R @@ -1,5 +1,6 @@ -cli::test_that_cli("can override defaults in _pkgdown.yml", { +test_that("can override defaults in _pkgdown.yml", { skip_if_no_pandoc() + local_edition(3) withr::local_temp_libpaths() pkg <- local_pkgdown_site(test_path("assets/figure")) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index c1595c6e0..004962a89 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -1,4 +1,5 @@ -cli::test_that_cli("extra.css and extra.js copied and linked", { +test_that("extra.css and extra.js copied and linked", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-extra-2")) expect_snapshot(init_site(pkg)) @@ -15,14 +16,16 @@ cli::test_that_cli("extra.css and extra.js copied and linked", { expect_true("extra.css" %in% paths) }) -cli::test_that_cli("single extra.css correctly copied", { +test_that("single extra.css correctly copied", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-extra-1")) expect_snapshot(init_site(pkg)) expect_true(file_exists(path(pkg$dst_path, "extra.css"))) }) -cli::test_that_cli("asset subdirectories are copied", { +test_that("asset subdirectories are copied", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-asset-subdirs")) expect_snapshot(init_site(pkg)) @@ -30,7 +33,8 @@ cli::test_that_cli("asset subdirectories are copied", { expect_true(file_exists(path(pkg$dst_path, "subdir1", "subdir2", "file2.txt"))) }) -cli::test_that_cli("site meta doesn't break unexpectedly", { +test_that("site meta doesn't break unexpectedly", { + local_edition(3) pkgdown <- as_pkgdown(test_path("assets/reference")) # null out components that will vary diff --git a/tests/testthat/test-rd-example.R b/tests/testthat/test-rd-example.R index 229d900e6..b3cd337a5 100644 --- a/tests/testthat/test-rd-example.R +++ b/tests/testthat/test-rd-example.R @@ -51,7 +51,9 @@ test_that("extracts conditions from if", { expect_equal(rd2ex("\\ifelse{latex}{1 + 2}{3 + 4}"), "3 + 4") }) -cli::test_that_cli("@examplesIf", { +test_that("@examplesIf", { + local_edition(3) + rd <- paste0( "\\dontshow{if (1 == 0) (if (getRversion() >= \"3.4\") withAutoprint else force)(\\{ # examplesIf}\n", "answer <- 43\n", diff --git a/tests/testthat/test-rd-html.R b/tests/testthat/test-rd-html.R index 1ebb705f6..9d9305407 100644 --- a/tests/testthat/test-rd-html.R +++ b/tests/testthat/test-rd-html.R @@ -24,11 +24,13 @@ test_that("simple wrappers work as expected", { expect_equal(rd2html("\\strong{\\emph{x}}"), "x") }) -cli::test_that_cli("subsection generates h3", { +test_that("subsection generates h3", { + local_edition(3) expect_snapshot(cli::cat_line(rd2html("\\subsection{A}{B}"))) }) -cli::test_that_cli("subsection generates h3", { +test_that("subsection generates h3", { + local_edition(3) expect_snapshot(cli::cat_line(rd2html("\\subsection{A}{ p1 @@ -45,7 +47,8 @@ test_that("subsection generates generated anchor", { expect_equal(xpath_attr(html, ".//a", "href"), "#a") }) -cli::test_that_cli("nested subsection generates h4", { +test_that("nested subsection generates h4", { + local_edition(3) expect_snapshot(cli::cat_line(rd2html("\\subsection{H3}{\\subsection{H4}{}}"))) }) @@ -171,8 +174,9 @@ test_that("Sexprs with multiple args are parsed", { expect_equal(rd2html("\\Sexpr[results=hide,stage=build]{1}"), character()) }) -cli::test_that_cli("Sexprs with multiple args are parsed", { +test_that("Sexprs with multiple args are parsed", { skip_if_not(getRversion() >= "4.0.0") + local_edition(3) local_context_eval() expect_snapshot(rd2html("\\Sexpr[results=verbatim]{1}"), error = TRUE) }) @@ -279,7 +283,8 @@ test_that("link to non-existing functions return label", { expect_equal(rd2html("\\linkS4class{TEST}"), "TEST") }) -cli::test_that_cli("bad specs throw errors", { +test_that("bad specs throw errors", { + local_edition(3) expect_snapshot(error = TRUE, { rd2html("\\url{}") rd2html("\\url{a\nb}") diff --git a/tests/testthat/test-rmarkdown.R b/tests/testthat/test-rmarkdown.R index 4bee49382..24b3af222 100644 --- a/tests/testthat/test-rmarkdown.R +++ b/tests/testthat/test-rmarkdown.R @@ -1,4 +1,5 @@ -cli::test_that_cli("render_rmarkdown copies image files in subdirectories", { +test_that("render_rmarkdown copies image files in subdirectories", { + local_edition(3) skip_if_no_pandoc() tmp <- dir_create(file_temp()) pkg <- list(src_path = test_path("."), dst_path = tmp, bs_version = 3) @@ -12,7 +13,8 @@ cli::test_that_cli("render_rmarkdown copies image files in subdirectories", { ) }) -cli::test_that_cli("render_rmarkdown yields useful error", { +test_that("render_rmarkdown yields useful error", { + local_edition(3) skip_on_cran() # fragile due to pandoc dependency skip_if_no_pandoc("2.18") @@ -25,8 +27,9 @@ cli::test_that_cli("render_rmarkdown yields useful error", { }) }) -cli::test_that_cli("render_rmarkdown styles ANSI escapes", { +test_that("render_rmarkdown styles ANSI escapes", { skip_if_no_pandoc() + local_edition(3) tmp <- dir_create(file_temp()) pkg <- list(src_path = test_path("."), dst_path = tmp, bs_version = 5) diff --git a/tests/testthat/test-sitrep.R b/tests/testthat/test-sitrep.R index a488ae565..cbc709a83 100644 --- a/tests/testthat/test-sitrep.R +++ b/tests/testthat/test-sitrep.R @@ -1,4 +1,6 @@ -cli::test_that_cli("pkgdown_sitrep works", { +test_that("pkgdown_sitrep works", { + local_edition(3) + # URL not in the pkgdown config pkg <- test_path("assets/figure") expect_snapshot(pkgdown_sitrep(pkg)) diff --git a/tests/testthat/test-utils-yaml.R b/tests/testthat/test-utils-yaml.R index 23646d227..2cc87e9a7 100644 --- a/tests/testthat/test-utils-yaml.R +++ b/tests/testthat/test-utils-yaml.R @@ -1,4 +1,6 @@ -cli::test_that_cli("pkgdown_field(s) produces useful description", { +test_that("pkgdown_field(s) produces useful description", { + local_edition(3) + pkg <- local_pkgdown_site() file_touch(file.path(pkg$src_path, "_pkgdown.yml")) From 4c3aa08084e98f59696ffed33becc01e22e8af31 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Tue, 28 Nov 2023 07:34:47 -0700 Subject: [PATCH 16/20] improved `pkgdown_field()` and snapshot updates --- NEWS.md | 1 + R/build-home-authors.R | 6 +-- R/build-home-index.R | 8 +++- R/build-redirects.R | 7 +++- R/build-reference-index.R | 10 +++-- R/figure.R | 6 +-- R/package.R | 22 +++++++---- R/rd-html.R | 6 +-- R/render.R | 12 ++++-- R/sitrep.R | 7 ++-- R/theme.R | 4 +- R/topics.R | 10 +++-- R/utils-fs.R | 1 + R/utils-yaml.R | 30 ++++++++++++--- tests/testthat/_snaps/build-home-index.md | 38 ++++++++++++++----- tests/testthat/_snaps/build-redirects.md | 6 ++- .../testthat/_snaps/build-reference-index.md | 8 ++-- tests/testthat/_snaps/build-reference.md | 4 +- tests/testthat/_snaps/navbar.md | 2 +- tests/testthat/_snaps/package.md | 6 +-- tests/testthat/_snaps/rd-html.md | 14 +++---- tests/testthat/_snaps/sitrep.md | 3 +- tests/testthat/_snaps/topics.md | 16 ++++---- tests/testthat/_snaps/utils-yaml.md | 12 ++---- tests/testthat/assets/articles/_pkgdown.yml | 0 tests/testthat/test-build-home-index.R | 9 +++-- tests/testthat/test-build-redirects.R | 5 ++- tests/testthat/test-package.R | 6 ++- tests/testthat/test-render.R | 3 +- tests/testthat/test-utils-yaml.R | 12 ++++-- 30 files changed, 174 insertions(+), 100 deletions(-) create mode 100644 tests/testthat/assets/articles/_pkgdown.yml diff --git a/NEWS.md b/NEWS.md index c39a678cd..cff5f58be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Deprecated `build_favicon()` was removed (`build_favicons()` remains). * Use [cli](https://github.com/r-lib/cli) to provide interactive feedback. * Preserve Markdown code blocks with class rmd from roxygen2 docs (@salim-b, #2298). * Avoid unwanted linebreaks from parsing `DESCRIPTION` (@salim-b, #2247). diff --git a/R/build-home-authors.R b/R/build-home-authors.R index beb5dfb98..87fef29a7 100644 --- a/R/build-home-authors.R +++ b/R/build-home-authors.R @@ -56,12 +56,12 @@ data_home_sidebar_authors <- function(pkg = ".") { bullets <- c( markdown_text_inline( pkg$meta$authors$sidebar$before, - pkgdown_field(c("authors", "sidebar", "before")) + pkgdown_field(pkg, c("authors", "sidebar", "before")) ), authors, markdown_text_inline( pkg$meta$authors$sidebar$after, - pkgdown_field(c("authors", "sidebar", "after")) + pkgdown_field(pkg, c("authors", "sidebar", "after")) ) ) @@ -96,7 +96,7 @@ author_name <- function(x, authors, pkg) { if (!is.null(author$html)) { name <- markdown_text_inline( author$html, - pkgdown_field(c("authors", name, "html")) + pkgdown_field(pkg, c("authors", name, "html")) ) } diff --git a/R/build-home-index.R b/R/build-home-index.R index bdb02ecdf..516808b20 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -65,10 +65,16 @@ data_home_sidebar <- function(pkg = ".") { if (length(html_path)) { if (!file.exists(html_path)) { rel_html_path <- fs::path_rel(html_path, pkg$src_path) + + msg_fld <- pkgdown_field( + pkg, c('home', 'sidebar', 'html'), fmt = TRUE, cfg = TRUE + ) + cli::cli_abort(c( "Can't locate {.file {rel_html_path}}.", - "x" = "{.field {pkgdown_field(c('home', 'sidebar', 'html'))}} in {.file {pkgdown_config_relpath(pkg)}} is misconfigured." + x = paste0(msg_fld, " is misconfigured.") )) + } return(read_file(html_path)) } diff --git a/R/build-redirects.R b/R/build-redirects.R index a57fe939a..d8405b233 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -13,7 +13,8 @@ build_redirects <- function(pkg = ".", cli::cli_rule("Building redirects") if (is.null(pkg$meta$url)) { - cli::cli_abort("{.field {pkgdown_field('url')}} in {.file {pkgdown_config_relpath(pkg)}} required to generate redirects") + msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE) + cli::cli_abort(paste0(msg_fld, " is required to generate redirects.")) } purrr::iwalk( @@ -25,8 +26,10 @@ build_redirects <- function(pkg = ".", build_redirect <- function(entry, index, pkg) { if (!is.character(entry) || length(entry) != 2) { + msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE) cli::cli_abort( - "Entry {.emph {index}} in {.field {pkgdown_field('redirects')}} must be a character vector of length 2.", + "Entry {.emph {index}} must be a character vector of length 2.", + x = paste0("Edit ", msg_fld, ".") ) } diff --git a/R/build-reference-index.R b/R/build-reference-index.R index fc2173ed9..780ab22f9 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -69,9 +69,10 @@ check_all_characters <- function(contents, index, pkg) { any_null <- any(null) if (any_null) { + msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE) cli::cli_abort(c( - "Item {.field {which(null)}} in section {index} in {.field {pkgdown_field('reference')}} is empty.", - i = "Either delete the empty line or add a function name in {.file {pkgdown_config_relpath(pkg)}}." + "Item {.field {which(null)}} in section {index} is empty.", + x = paste0("Delete the empty line or add function name to ", msg_fld, ".") )) } @@ -82,9 +83,10 @@ check_all_characters <- function(contents, index, pkg) { return(invisible()) } + msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE) cli::cli_abort(c( - "Item {.field {which(not_char)}} in section {index} in {.field {pkgdown_field('reference')}} must be a character.", - i = "You might need to add '' around e.g. - 'N' or - 'off' in {.file {pkgdown_config_relpath(pkg)}}." + "Item {.field {which(not_char)}} in section {index} must be a character.", + x = paste0("You might need to add '' around e.g. - 'N' or - 'off' to ", msg_fld, ".") )) } diff --git a/R/figure.R b/R/figure.R index f55ae4e32..10ceb864e 100644 --- a/R/figure.R +++ b/R/figure.R @@ -136,12 +136,12 @@ match_fun <- function(x) { f <- eval(e, globalenv()) if (!is.function(f)) { - cli::cli_abort("{.var x} must evaluate to a function") + cli::cli_abort("{.var x} must evaluate to a function", call = caller_env()) } f } else { - cli::cli_abort("{.var x} must be a function or string") + cli::cli_abort("{.var x} must be a function or string", call = caller_env()) } } @@ -157,6 +157,6 @@ fun_name <- function(x) { } else if (is_call(expr, "::")) { as.character(expr[[3]]) } else { - cli::cli_abort("Unknown input") + cli::cli_abort("Unknown input", call = caller_env()) } } diff --git a/R/package.R b/R/package.R index 90e7f241b..c3ea28654 100644 --- a/R/package.R +++ b/R/package.R @@ -13,7 +13,10 @@ as_pkgdown <- function(pkg = ".", override = list()) { } if (!dir_exists(pkg)) { - cli::cli_abort("{.file {pkg}} is not an existing directory") + cli::cli_abort( + "{.file {pkg}} is not an existing directory", + call = caller_env() + ) } desc <- read_desc(pkg) @@ -89,12 +92,12 @@ is_pkgdown <- function(x) inherits(x, "pkgdown") read_desc <- function(path = ".") { path <- path(path, "DESCRIPTION") if (!file_exists(path)) { - cli::cli_abort("Can't find {.file DESCRIPTION}") + cli::cli_abort("Can't find {.file DESCRIPTION}", call = caller_env()) } desc::description$new(path) } -check_bootstrap_version <- function(version, pkg = list()) { +check_bootstrap_version <- function(version, pkg) { if (is.null(version)) { 3 } else if (version %in% c(3, 5)) { @@ -103,11 +106,14 @@ check_bootstrap_version <- function(version, pkg = list()) { cli::cli_warn("{.var bootstrap: 4} no longer supported, using {.var bootstrap: 5} instead") 5 } else { - field <- pkgdown_field(c("template", "bootstrap")) - cli::cli_abort(c( - "Boostrap version must be 3 or 5.", - "x" = "You specified a value of {.val {version}} in {.field {field}}." - )) + msg_fld <- pkgdown_field(pkg, c("template", "bootstrap"), cfg = TRUE, fmt = TRUE) + cli::cli_abort( + c( + "Boostrap version must be 3 or 5.", + x = paste0("You set a value of {.val {version}} to ", msg_fld, ".") + ), + call = caller_env() + ) } } diff --git a/R/rd-html.R b/R/rd-html.R index 15e0cf6c3..03372285c 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -511,6 +511,7 @@ as_html.tag <- function(x, ...) { flatten_text(x, ...) } else { cli::cli_inform("Unknown tag: ", paste(class(x), collapse = "/")) + "" } } @@ -567,10 +568,7 @@ parse_opts <- function(string) { stop_bad_tag <- function(tag, msg = NULL) { bad_tag <- paste0("\\", tag, "{}") msg_abort <- 'Failed to parse tag {.val {bad_tag}}.' - if (!is.null(msg)) { - msg_abort <- c(msg_abort, "x" = msg) - } - cli::cli_abort(msg_abort) + cli::cli_abort(c(msg_abort, i = msg), call = caller_env()) } is_newline <- function(x, trim = FALSE) { diff --git a/R/render.R b/R/render.R index 1aaa20ec1..a18560bbd 100644 --- a/R/render.R +++ b/R/render.R @@ -161,7 +161,8 @@ check_open_graph <- function(og) { if ("twitter" %in% names(og)) { if (is.character(og$twitter) && length(og$twitter) == 1 && grepl("^@", og$twitter)) { cli::cli_abort( - "The {.var opengraph: twitter} option must be a list." + "The {.var opengraph: twitter} option must be a list.", + call = caller_env() ) } if (!is.list(og$twitter)) { @@ -169,19 +170,22 @@ check_open_graph <- function(og) { } if (is.null(og$twitter$creator) && is.null(og$twitter$site)) { cli::cli_abort( - "{.var opengraph: twitter} must include either {.val creator} or {.val site}." + "{.var opengraph: twitter} must include either {.val creator} or {.val site}.", + call = caller_env() ) } } if ("image" %in% names(og)) { if (is.character(og$image) && length(og$image) == 1) { cli::cli_abort( - "The {.var opengraph: image} option must be a list." + "The {.var opengraph: image} option must be a list.", + call = caller_env() ) } if (!is.list(og$image)) { cli::cli_abort( - "The {.var opengraph: image} option must be a list." + "The {.var opengraph: image} option must be a list.", + call = caller_env() ) } } diff --git a/R/sitrep.R b/R/sitrep.R index acde54e30..e67ca7d45 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -17,18 +17,19 @@ pkgdown_sitrep <- function(pkg = ".") { warns <- c() if (is.null(pkg$meta[["url"]])) { - warns <- c(warns, "x" = "{.field {pkgdown_field('url')}} is not configured in {.file {pkgdown_config_relpath(pkg)}}. See {.vignette pkgdown::metatdata}.") + msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE) + warns <- c(warns, x = paste0(msg_fld, "is misconfigured. See {.vignette pkgdown::metatdata}.")) } desc_urls <- pkg$desc$get_urls() desc_urls <- sub("/$", "", desc_urls) if (length(desc_urls) == 0 || !pkg$meta[["url"]] %in% desc_urls) { - warns <- c(warns, "x" = "{.file DESCRIPTION} {.field URL} is empty.") + warns <- c(warns, x = "{.file DESCRIPTION} {.field URL} is empty.") } if (length(warns) == 0) { cli::cli_alert_success("pkgdown situation report: {.emph {cli::col_green('all clear')}}") - cli::cli_alert("{.emph Double-check the following URLs:}") + cli::cli_inform("{.emph Double-check the following URLs:}") cli::cli_inform("{.file {pkgdown_config_relpath(pkg)}} contains URL {.url {pkg$meta['url']}}") cli::cli_inform("{.file DESCRIPTION} contains URL{?s} {.url {desc_urls}}") } else { diff --git a/R/theme.R b/R/theme.R index 0154a5a0d..6df16e2ac 100644 --- a/R/theme.R +++ b/R/theme.R @@ -105,9 +105,9 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { sprintf( "Can't find Bootswatch theme {.val %s} ({.field %s}) for Bootstrap version {.val %s} ({.field %s}).", bootswatch_theme, - pkgdown_field(c("template", "bootswatch")), + pkgdown_field(pkg, c("template", "bootswatch")), bs_version, - pkgdown_field(c("template", "bootstrap")) + pkgdown_field(pkg, c("template", "bootstrap")) ), x = "Edit settings in {.file {pkgdown_config_relpath(pkg)}}" )) diff --git a/R/topics.R b/R/topics.R index a87a3b4ac..db39d9e8d 100644 --- a/R/topics.R +++ b/R/topics.R @@ -54,7 +54,10 @@ all_sign <- function(x, text) { } } - cli::cli_abort("Must be all negative or all positive: {.val {text}}") + cli::cli_abort( + "Must be all negative or all positive: {.val {text}}", + call = caller_env() + ) } match_env <- function(topics) { @@ -172,10 +175,11 @@ match_eval <- function(string, env) { } } -topic_must <- function(message, topic, parent = NULL) { +topic_must <- function(message, topic, ..., call = NULL) { cli::cli_abort( "In {.file _pkgdown.yml}, topic must {message}, not {.val {topic}}", - parent = parent + ..., + call = call ) } diff --git a/R/utils-fs.R b/R/utils-fs.R index 0ba3da3be..8cb22a5ca 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -104,5 +104,6 @@ path_pkgdown <- function(...) { pkgdown_config_relpath <- function(pkg) { pkg <- as_pkgdown(pkg) config_path <- pkgdown_config_path(pkg$src_path) + fs::path_rel(config_path, pkg$src_path) } diff --git a/R/utils-yaml.R b/R/utils-yaml.R index 528b538b4..1120a943a 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -4,10 +4,10 @@ check_yaml_has <- function(missing, where, pkg) { } missing_components <- lapply(missing, function(x) c(where, x)) - missing_fields <- purrr::map_chr(missing_components, pkgdown_field) + msg_flds <- pkgdown_field(pkg, missing_components, fmt = TRUE, cfg = TRUE) cli::cli_abort( - "Can't find {cli::qty(missing_fields)} component{?s} {.field {missing_fields}} in {.file {pkgdown_config_relpath(pkg)}}." + paste0("Can't find {cli::qty(missing)} component{?s} ", msg_flds, ".") ) } @@ -19,13 +19,31 @@ yaml_character <- function(pkg, where) { } else if (is.character(x)) { x } else { - fld <- pkgdown_field(where) - cli::cli_abort("{fld} must be a character vector") + fld <- pkgdown_field(pkg, where, fmt = TRUE) + cli::cli_abort(paste0(fld, " must be a character vector.")) } } -pkgdown_field <- function(fields) { - purrr::map_chr(list(fields), ~ paste0(.x, collapse = ".")) +pkgdown_field <- function(pkg, fields, cfg = FALSE, fmt = FALSE) { + + if (!is.list(fields)) fields <- list(fields) + + flds <- purrr::map_chr(fields, ~ paste0(.x, collapse = ".")) + if (fmt) { + flds <- paste0("{.field ", flds, "}") + } + + if (cfg) { + config_path <- pkgdown_config_relpath(pkg) + if (fmt) { + config_path <- paste0("{.file ", config_path, "}") + } + + paste0(flds, " in ", config_path) + } else { + + flds + } } # print helper ------------------------------------------------------------ diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index ffc10e283..46d3103b4 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -79,23 +79,41 @@ # data_home_sidebar() outputs informative error messages - Can't find component home.sidebar.components.fancy in '_pkgdown.yml'. + Code + data_home_sidebar(pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find component home.sidebar.components.fancy in '_pkgdown.yml'. --- - Can't find components home.sidebar.components.fancy and home.sidebar.components.cool in '_pkgdown.yml'. + Code + data_home_sidebar(pkg) + Condition + Error in `check_yaml_has()`: + ! Can't find components home.sidebar.components.fancy in '_pkgdown.yml'. + Can't find components home.sidebar.components.cool in '_pkgdown.yml'. --- - i In index: 1. - i With name: fancy. - Caused by error in `check_yaml_has()`: - ! Can't find component home.sidebar.components.fancy.title in '_pkgdown.yml'. + Code + data_home_sidebar(pkg) + Condition + Error in `purrr::map2()`: + i In index: 1. + i With name: fancy. + Caused by error in `check_yaml_has()`: + ! Can't find component home.sidebar.components.fancy.title in '_pkgdown.yml'. --- - i In index: 1. - i With name: fancy. - Caused by error in `check_yaml_has()`: - ! Can't find components home.sidebar.components.fancy.title and home.sidebar.components.fancy.text in '_pkgdown.yml'. + Code + data_home_sidebar(pkg) + Condition + Error in `purrr::map2()`: + i In index: 1. + i With name: fancy. + Caused by error in `check_yaml_has()`: + ! Can't find components home.sidebar.components.fancy.title in '_pkgdown.yml'. + Can't find components home.sidebar.components.fancy.text in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/build-redirects.md b/tests/testthat/_snaps/build-redirects.md index f7b6c2fe4..57fd512be 100644 --- a/tests/testthat/_snaps/build-redirects.md +++ b/tests/testthat/_snaps/build-redirects.md @@ -1,4 +1,8 @@ # build_redirect() errors if one entry is not right. - Entry 5 in redirects must be a character vector of length 2. + Code + build_redirect(c("old.html"), 5, pkg) + Condition + Error in `build_redirect()`: + ! Entry 5 must be a character vector of length 2. diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index ee7ea4cfe..ec62f4a83 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -59,8 +59,8 @@ i In index: 1. Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference is empty. - i Either delete the empty line or add a function name in '_pkgdown.yml'. + ! Item 2 in section 1 is empty. + x Delete the empty line or add function name to reference in '_pkgdown.yml'. # errors well when a content entry is not a character @@ -70,8 +70,8 @@ Error in `map2()`: i In index: 1. Caused by error in `check_all_characters()`: - ! Item 2 in section 1 in reference must be a character. - i You might need to add '' around e.g. - 'N' or - 'off' in '_pkgdown.yml'. + ! Item 2 in section 1 must be a character. + x You might need to add '' around e.g. - 'N' or - 'off' to reference in '_pkgdown.yml'. # errors well when a content entry refers to a not installed package diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index eeec43842..1c1a82835 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -13,9 +13,9 @@ ! Failed to parse Rd in 'f.Rd' Caused by error in `purrr::map()`: i In index: 4. - Caused by error in `stop_bad_tag()`: + Caused by error in `.f()`: ! Failed to parse tag "\\url{}". - x Check for empty \url{} tags. + i Check for empty \url{} tags. # test usage ok on rendered page diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 3e39d249c..52a9b9803 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -175,7 +175,7 @@ data_navbar(pkg) Condition Error in `yaml_character()`: - ! navbar.structure.left must be a character vector + ! navbar.structure.left must be a character vector. # render_navbar_links BS3 & BS4 default diff --git a/tests/testthat/_snaps/package.md b/tests/testthat/_snaps/package.md index a069241e7..f556c9cf4 100644 --- a/tests/testthat/_snaps/package.md +++ b/tests/testthat/_snaps/package.md @@ -1,9 +1,9 @@ # check_bootstrap_version() gives informative error otherwise Code - check_bootstrap_version(1) + check_bootstrap_version(1, pkg) Condition - Error in `check_bootstrap_version()`: + Error: ! Boostrap version must be 3 or 5. - x You specified a value of 1 in template.bootstrap. + x You set a value of 1 to template.bootstrap in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index 6b3d3f710..0f687d649 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -49,31 +49,31 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `stop_bad_tag()`: + Caused by error in `.f()`: ! Failed to parse tag "\\url{}". - x Check for empty \url{} tags. + i Check for empty \url{} tags. Code rd2html("\\url{a\nb}") Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `stop_bad_tag()`: + Caused by error in `.f()`: ! Failed to parse tag "\\url{}". - x This may be caused by a \url tag that spans a line break. + i This may be caused by a \url tag that spans a line break. Code rd2html("\\email{}") Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `stop_bad_tag()`: + Caused by error in `.f()`: ! Failed to parse tag "\\email{}". - x empty + i empty Code rd2html("\\linkS4class{}") Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `stop_bad_tag()`: + Caused by error in `.f()`: ! Failed to parse tag "\\linkS4class{}". # \describe items can contain multiple paragraphs diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index f2d595f71..46c863665 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -5,7 +5,7 @@ Condition Warning: pkgdown situation report: configuration error - x url is not configured in '_pkgdown.yml'. See `vignette(pkgdown::metatdata)`. + x url in '_pkgdown.yml'is misconfigured. See `vignette(pkgdown::metatdata)`. x 'DESCRIPTION' URL is empty. --- @@ -22,6 +22,7 @@ Code pkgdown_sitrep(pkg) Message + Double-check the following URLs: '_pkgdown.yml' contains URL 'DESCRIPTION' contains URL diff --git a/tests/testthat/_snaps/topics.md b/tests/testthat/_snaps/topics.md index ef6c87a05..9b5ea1b51 100644 --- a/tests/testthat/_snaps/topics.md +++ b/tests/testthat/_snaps/topics.md @@ -5,21 +5,21 @@ Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be valid R code, not "x + " Code t <- select_topics("y", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a known topic name or alias, not "y" Code t <- select_topics("paste(1)", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a known selector function, not "paste(1)" Caused by error in `paste()`: ! could not find function "paste" @@ -28,14 +28,14 @@ Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a known topic name or alias, not "starts_with" Code t <- select_topics("1", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a string or function call, not "1" Code t <- select_topics("starts_with('y')", topics, check = TRUE) @@ -50,14 +50,14 @@ Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a known topic name or alias, not "a4" Code select_topics("c::a", topics) Condition Error in `purrr::map()`: i In index: 1. - Caused by error in `topic_must()`: + Caused by error: ! In '_pkgdown.yml', topic must be a known topic name or alias, not "c::a" # an unmatched selection generates a warning @@ -65,6 +65,6 @@ Code select_topics(c("a", "starts_with('unmatched')"), topics, check = TRUE) Condition - Error in `topic_must()`: + Error: ! In '_pkgdown.yml', topic must match a function or concept, not "starts_with('unmatched')" diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index ee3e1b483..c2fb3d18b 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -1,11 +1,4 @@ -# pkgdown_field(s) produces useful description - - Code - pkgdown_field(c("a", "b")) - Output - [1] "a.b" - ---- +# pkgdown_field produces useful description Code check_yaml_has("x", where = "a", pkg = pkg) @@ -16,5 +9,6 @@ check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition Error in `check_yaml_has()`: - ! Can't find components a.x and a.y in '_pkgdown.yml'. + ! Can't find components a.x in '_pkgdown.yml'. + Can't find components a.y in '_pkgdown.yml'. diff --git a/tests/testthat/assets/articles/_pkgdown.yml b/tests/testthat/assets/articles/_pkgdown.yml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index b2e1b6e9c..502768b45 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -80,29 +80,30 @@ test_that("data_home_sidebar() can add a README", { }) test_that("data_home_sidebar() outputs informative error messages", { + local_edition(3) pkg <- as_pkgdown(test_path("assets/sidebar")) # no component definition for a component named in structure pkg$meta$home$sidebar <- list(structure = "fancy") - expect_snapshot_error(data_home_sidebar(pkg)) + expect_snapshot(data_home_sidebar(pkg), error = TRUE) # no component definition for two components named in structure pkg$meta$home$sidebar <- list(structure = c("fancy", "cool")) - expect_snapshot_error(data_home_sidebar(pkg)) + expect_snapshot(data_home_sidebar(pkg), error = TRUE) # no title pkg$meta$home$sidebar <- list( structure = c("fancy"), components = list(fancy = list(text = "bla")) ) - expect_snapshot_error(data_home_sidebar(pkg)) + expect_snapshot(data_home_sidebar(pkg), error = TRUE) # no title nor text pkg$meta$home$sidebar <- list( structure = c("fancy"), components = list(fancy = list(html = "bla")) ) - expect_snapshot_error(data_home_sidebar(pkg)) + expect_snapshot(data_home_sidebar(pkg), error = TRUE) }) test_that("package repo verification", { diff --git a/tests/testthat/test-build-redirects.R b/tests/testthat/test-build-redirects.R index 4ecf2d604..db03260a7 100644 --- a/tests/testthat/test-build-redirects.R +++ b/tests/testthat/test-build-redirects.R @@ -17,6 +17,7 @@ test_that("build_redirect() works", { }) test_that("build_redirect() errors if one entry is not right.", { + local_edition(3) pkg <- list( src_path = withr::local_tempdir(), dst_path = withr::local_tempdir(), @@ -25,7 +26,9 @@ test_that("build_redirect() errors if one entry is not right.", { bs_version = 5 ) pkg <- structure(pkg, class = "pkgdown") - expect_snapshot_error(build_redirect(c("old.html"), 5, pkg = pkg)) + file_touch(file.path(pkg$src_path, "_pkgdown.yml")) + + expect_snapshot(build_redirect(c("old.html"), 5, pkg), error = TRUE) }) test_that("article_redirects() creates redirects for vignettes in vignettes/articles", { diff --git a/tests/testthat/test-package.R b/tests/testthat/test-package.R index 22bbaff7c..01fef0a4f 100644 --- a/tests/testthat/test-package.R +++ b/tests/testthat/test-package.R @@ -14,7 +14,11 @@ test_that("check_bootstrap_version() allows 3, 4 (with warning), and 5", { }) test_that("check_bootstrap_version() gives informative error otherwise", { - expect_snapshot(check_bootstrap_version(1), error = TRUE) + local_edition(3) + pkg <- local_pkgdown_site(test_path("assets/articles")) + file_touch(file.path(pkg$src_path, "_pkgdown.yml")) + + expect_snapshot(check_bootstrap_version(1, pkg), error = TRUE) }) test_that("package_vignettes() moves vignettes/articles up one level", { diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index d70a03ff9..b2f8bef21 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -13,7 +13,8 @@ test_that("capture data_template()", { expect_snapshot_output(data) }) -cli::test_that_cli("can include text in header, before body, and after body", { +test_that("can include text in header, before body, and after body", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/site-empty"), ' template: includes: diff --git a/tests/testthat/test-utils-yaml.R b/tests/testthat/test-utils-yaml.R index 2cc87e9a7..20477723f 100644 --- a/tests/testthat/test-utils-yaml.R +++ b/tests/testthat/test-utils-yaml.R @@ -1,12 +1,16 @@ -test_that("pkgdown_field(s) produces useful description", { +test_that("pkgdown_field produces useful description", { local_edition(3) pkg <- local_pkgdown_site() file_touch(file.path(pkg$src_path, "_pkgdown.yml")) - expect_snapshot({ - pkgdown_field(c("a", "b")) - }) + expect_equal(pkgdown_field(pkg, c("a", "b")), "a.b") + expect_equal(pkgdown_field(pkg, c("a", "b"), fmt = TRUE), "{.field a.b}") + expect_equal(pkgdown_field(pkg, c("a"), cfg = TRUE), "a in _pkgdown.yml") + expect_equal( + pkgdown_field(pkg, c("a"), cfg = TRUE, fmt = TRUE), + "{.field a} in {.file _pkgdown.yml}" + ) expect_snapshot(error = TRUE, { check_yaml_has("x", where = "a", pkg = pkg) From 40dc4e250e63397878c2ac978ac7b5dbfdde8bef Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Wed, 29 Nov 2023 06:00:38 -0700 Subject: [PATCH 17/20] fix up more tests suppress messages during init_site() testing to account for path differences between testing platforms --- R/build-favicons.R | 10 +++++-- R/build-redirects.R | 7 +++-- R/build-reference-index.R | 20 +++++++------ R/topics.R | 2 +- R/utils-yaml.R | 8 ++++-- tests/testthat/_snaps/build-home-index.md | 8 +++--- tests/testthat/_snaps/build-redirects.md | 3 +- .../testthat/_snaps/build-reference-index.md | 4 +-- tests/testthat/_snaps/build-reference.md | 26 ----------------- tests/testthat/_snaps/init.md | 28 ------------------- tests/testthat/_snaps/navbar.md | 2 +- tests/testthat/_snaps/render.md | 8 ------ tests/testthat/_snaps/topics.md | 16 +++++------ tests/testthat/_snaps/utils-yaml.md | 4 +-- tests/testthat/test-build-articles.R | 3 +- tests/testthat/test-build-reference.R | 6 ++-- tests/testthat/test-init.R | 6 ++-- tests/testthat/test-render.R | 2 +- 18 files changed, 59 insertions(+), 104 deletions(-) diff --git a/R/build-favicons.R b/R/build-favicons.R index d4b556640..a151c5bf4 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -24,7 +24,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { logo_path <- find_logo(pkg$src_path) if (is.null(logo_path)) { - cli::cli_abort("Can't find package logo PNG or SVG to build favicons.") + cli::cli_abort( + "Can't find package logo PNG or SVG to build favicons.", + call = caller_env() + ) } if (has_favicons(pkg) && !overwrite) { @@ -69,7 +72,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { quiet = TRUE ) if (httr::http_error(resp)) { - cli::cli_abort("API request failed.") + cli::cli_abort("API request failed.", call = caller_env()) } content <- httr::content(resp) @@ -80,7 +83,8 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { c( "API request failed.", "i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}" - ) + ), + call = caller_env() ) } diff --git a/R/build-redirects.R b/R/build-redirects.R index d8405b233..9a8fda362 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -28,8 +28,11 @@ build_redirect <- function(entry, index, pkg) { if (!is.character(entry) || length(entry) != 2) { msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE) cli::cli_abort( - "Entry {.emph {index}} must be a character vector of length 2.", - x = paste0("Edit ", msg_fld, ".") + c( + "Entry {.emph {index}} must be a character vector of length 2.", + x = paste0("Edit ", msg_fld, ".") + ), + call = caller_env() ) } diff --git a/R/build-reference-index.R b/R/build-reference-index.R index 780ab22f9..1e0c3dfce 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -70,10 +70,12 @@ check_all_characters <- function(contents, index, pkg) { if (any_null) { msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE) - cli::cli_abort(c( - "Item {.field {which(null)}} in section {index} is empty.", - x = paste0("Delete the empty line or add function name to ", msg_fld, ".") - )) + cli::cli_abort( + c( + "Item {.field {which(null)}} in section {index} is empty.", + x = paste0("Delete the empty line or add function name to ", msg_fld, ".") + ), call = caller_env() + ) } not_char <- !purrr::map_lgl(contents, is.character) @@ -84,10 +86,12 @@ check_all_characters <- function(contents, index, pkg) { } msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE) - cli::cli_abort(c( - "Item {.field {which(not_char)}} in section {index} must be a character.", - x = paste0("You might need to add '' around e.g. - 'N' or - 'off' to ", msg_fld, ".") - )) + cli::cli_abort( + c( + "Item {.field {which(not_char)}} in section {index} must be a character.", + x = paste0("You might need to add '' around e.g. - 'N' or - 'off' to ", msg_fld, ".") + ), call = caller_env() + ) } diff --git a/R/topics.R b/R/topics.R index db39d9e8d..b135eb3bc 100644 --- a/R/topics.R +++ b/R/topics.R @@ -177,7 +177,7 @@ match_eval <- function(string, env) { topic_must <- function(message, topic, ..., call = NULL) { cli::cli_abort( - "In {.file _pkgdown.yml}, topic must {message}, not {.val {topic}}", + "In {.file _pkgdown.yml}, topic must {message}, not {.val {topic}}.", ..., call = call ) diff --git a/R/utils-yaml.R b/R/utils-yaml.R index 1120a943a..ff8ece88d 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -7,7 +7,8 @@ check_yaml_has <- function(missing, where, pkg) { msg_flds <- pkgdown_field(pkg, missing_components, fmt = TRUE, cfg = TRUE) cli::cli_abort( - paste0("Can't find {cli::qty(missing)} component{?s} ", msg_flds, ".") + paste0("Can't find {cli::qty(missing)} component{?s} ", msg_flds, "."), + call = caller_env() ) } @@ -20,7 +21,10 @@ yaml_character <- function(pkg, where) { x } else { fld <- pkgdown_field(pkg, where, fmt = TRUE) - cli::cli_abort(paste0(fld, " must be a character vector.")) + cli::cli_abort( + paste0(fld, " must be a character vector."), + call = caller_env() + ) } } diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index 46d3103b4..e45aa0003 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -82,7 +82,7 @@ Code data_home_sidebar(pkg) Condition - Error in `check_yaml_has()`: + Error in `data_home_sidebar()`: ! Can't find component home.sidebar.components.fancy in '_pkgdown.yml'. --- @@ -90,7 +90,7 @@ Code data_home_sidebar(pkg) Condition - Error in `check_yaml_has()`: + 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'. @@ -102,7 +102,7 @@ Error in `purrr::map2()`: i In index: 1. i With name: fancy. - Caused by error in `check_yaml_has()`: + Caused by error in `.f()`: ! Can't find component home.sidebar.components.fancy.title in '_pkgdown.yml'. --- @@ -113,7 +113,7 @@ Error in `purrr::map2()`: i In index: 1. i With name: fancy. - Caused by error in `check_yaml_has()`: + 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'. diff --git a/tests/testthat/_snaps/build-redirects.md b/tests/testthat/_snaps/build-redirects.md index 57fd512be..5d392178e 100644 --- a/tests/testthat/_snaps/build-redirects.md +++ b/tests/testthat/_snaps/build-redirects.md @@ -3,6 +3,7 @@ Code build_redirect(c("old.html"), 5, pkg) Condition - Error in `build_redirect()`: + Error: ! Entry 5 must be a character vector of length 2. + x Edit url in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index ec62f4a83..aceb87436 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -58,7 +58,7 @@ # errors well when a content entry is empty i In index: 1. - Caused by error in `check_all_characters()`: + Caused by error in `.f()`: ! Item 2 in section 1 is empty. x Delete the empty line or add function name to reference in '_pkgdown.yml'. @@ -69,7 +69,7 @@ Condition Error in `map2()`: i In index: 1. - Caused by error in `check_all_characters()`: + Caused by error in `.f()`: ! Item 2 in section 1 must be a character. x You might need to add '' around e.g. - 'N' or - 'off' to reference in '_pkgdown.yml'. diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index 1c1a82835..fccc3612d 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -17,32 +17,6 @@ ! Failed to parse tag "\\url{}". i Check for empty \url{} tags. -# test usage ok on rendered page - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - - Code - build_reference(pkg, topics = "c") - Message - Writing reference/index.html - Reading man/c.Rd - Writing reference/c.html - # .Rd without usage doesn't get Usage section Code diff --git a/tests/testthat/_snaps/init.md b/tests/testthat/_snaps/init.md index d1e168bff..fa579a752 100644 --- a/tests/testthat/_snaps/init.md +++ b/tests/testthat/_snaps/init.md @@ -1,21 +1,3 @@ -# extra.css and extra.js copied and linked - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css and pkgdown/extra.js - to extra.css and extra.js - ---- - - Code - build_home(pkg) - Message - Writing authors.html - Writing 404.html - # single extra.css correctly copied Code @@ -26,16 +8,6 @@ Copying pkgdown/extra.css to extra.css -# asset subdirectories are copied - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/assets/subdir1/file1.txt and pkgdown/assets/subdir1/subdir2/file2.txt - to subdir1/file1.txt and subdir1/subdir2/file2.txt - # site meta doesn't break unexpectedly Code diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 52a9b9803..40190cdf0 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -174,7 +174,7 @@ Code data_navbar(pkg) Condition - Error in `yaml_character()`: + Error in `navbar_links()`: ! navbar.structure.left must be a character vector. # render_navbar_links BS3 & BS4 default diff --git a/tests/testthat/_snaps/render.md b/tests/testthat/_snaps/render.md index f125a3cab..700823873 100644 --- a/tests/testthat/_snaps/render.md +++ b/tests/testthat/_snaps/render.md @@ -52,11 +52,3 @@ right:

Site built with pkgdown {version}.

-# can include text in header, before body, and after body - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - diff --git a/tests/testthat/_snaps/topics.md b/tests/testthat/_snaps/topics.md index 9b5ea1b51..7d3e10dbe 100644 --- a/tests/testthat/_snaps/topics.md +++ b/tests/testthat/_snaps/topics.md @@ -6,21 +6,21 @@ Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be valid R code, not "x + " + ! In '_pkgdown.yml', topic must be valid R code, not "x + ". Code t <- select_topics("y", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a known topic name or alias, not "y" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "y". Code t <- select_topics("paste(1)", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a known selector function, not "paste(1)" + ! In '_pkgdown.yml', topic must be a known selector function, not "paste(1)". Caused by error in `paste()`: ! could not find function "paste" Code @@ -29,14 +29,14 @@ Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a known topic name or alias, not "starts_with" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "starts_with". Code t <- select_topics("1", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a string or function call, not "1" + ! In '_pkgdown.yml', topic must be a string or function call, not "1". Code t <- select_topics("starts_with('y')", topics, check = TRUE) Condition @@ -51,14 +51,14 @@ Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a known topic name or alias, not "a4" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "a4". Code select_topics("c::a", topics) Condition Error in `purrr::map()`: i In index: 1. Caused by error: - ! In '_pkgdown.yml', topic must be a known topic name or alias, not "c::a" + ! In '_pkgdown.yml', topic must be a known topic name or alias, not "c::a". # an unmatched selection generates a warning @@ -66,5 +66,5 @@ select_topics(c("a", "starts_with('unmatched')"), topics, check = TRUE) Condition Error: - ! In '_pkgdown.yml', topic must match a function or concept, not "starts_with('unmatched')" + ! In '_pkgdown.yml', topic must match a function or concept, not "starts_with('unmatched')". diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index c2fb3d18b..2f000754a 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -3,12 +3,12 @@ Code check_yaml_has("x", where = "a", pkg = pkg) Condition - Error in `check_yaml_has()`: + Error: ! Can't find component a.x in '_pkgdown.yml'. Code check_yaml_has(c("x", "y"), where = "a", pkg = pkg) Condition - Error in `check_yaml_has()`: + Error: ! Can't find components a.x in '_pkgdown.yml'. Can't find components a.y in '_pkgdown.yml'. diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 6bd1d2aca..43fd19913 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -171,12 +171,13 @@ test_that("articles in vignettes/articles/ are unnested into articles/", { }) test_that("pkgdown deps are included only once in articles", { + local_edition(3) pkg <- local_pkgdown_site(test_path("assets/articles"), " template: bootstrap: 5 ") - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_snapshot(path <- build_article("html-deps", pkg)) html <- xml2::read_html(path) diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index e3b107c57..4176806b3 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -34,7 +34,7 @@ test_that("examples_env sets width", { test_that("test usage ok on rendered page", { local_edition(3) pkg <- local_pkgdown_site(test_path("assets/reference")) - expect_snapshot(build_reference(pkg, topics = "c")) + suppressMessages(expect_message(build_reference(pkg, topics = "c"))) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) expect_equal(xpath_text(html, "//div[@id='ref-usage']", trim = TRUE), "c()") clean_site(pkg, quiet = TRUE) @@ -43,8 +43,8 @@ test_that("test usage ok on rendered page", { template: bootstrap: 5 ") - expect_snapshot(init_site(pkg)) - expect_snapshot(build_reference(pkg, topics = "c")) + suppressMessages(expect_message(init_site(pkg))) + suppressMessages(expect_message(build_reference(pkg, topics = "c"))) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "c.html")) # tweak_anchors() moves id into

expect_equal(xpath_text(html, "//div[h2[@id='ref-usage']]/div", trim = TRUE), "c()") diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 004962a89..f2dc407a4 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -1,14 +1,14 @@ test_that("extra.css and extra.js copied and linked", { local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-extra-2")) - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_true(file_exists(path(pkg$dst_path, "extra.css"))) expect_true(file_exists(path(pkg$dst_path, "extra.js"))) skip_if_no_pandoc() # Now check they actually get used . - expect_snapshot(build_home(pkg)) + suppressMessages(expect_message(build_home(pkg))) html <- xml2::read_html(path(pkg$dst_path, "index.html")) paths <- xpath_attr(html, ".//link", "href") @@ -27,7 +27,7 @@ test_that("single extra.css correctly copied", { test_that("asset subdirectories are copied", { local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-asset-subdirs")) - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_true(file_exists(path(pkg$dst_path, "subdir1", "file1.txt"))) expect_true(file_exists(path(pkg$dst_path, "subdir1", "subdir2", "file2.txt"))) diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index b2f8bef21..fe6d98043 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -36,7 +36,7 @@ test_that("can include text in header, before body, and after body", { ) pkg$bs_version <- 5 - expect_snapshot(init_site(pkg)) + expect_message(init_site(pkg)) html <- render_page_html(pkg, "title-body") expect_equal( xpath_text(html, ".//test"), From 24ff4cce55eb149b5a953ac0d4ad5e987cd6441f Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Wed, 29 Nov 2023 06:13:00 -0700 Subject: [PATCH 18/20] fix few more init_site() in tests --- tests/testthat/_snaps/build-articles.md | 16 ---------------- tests/testthat/_snaps/build-home-index.md | 8 -------- tests/testthat/_snaps/build-reference.md | 16 ---------------- tests/testthat/_snaps/init.md | 10 ---------- tests/testthat/test-build-articles.R | 2 +- tests/testthat/test-build-home-index.R | 2 +- tests/testthat/test-build-reference.R | 4 ++-- tests/testthat/test-init.R | 2 +- 8 files changed, 5 insertions(+), 55 deletions(-) diff --git a/tests/testthat/_snaps/build-articles.md b/tests/testthat/_snaps/build-articles.md index bed3dc4c3..186dd29ad 100644 --- a/tests/testthat/_snaps/build-articles.md +++ b/tests/testthat/_snaps/build-articles.md @@ -86,14 +86,6 @@ # BS5 article laid out correctly with and without TOC - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - Code toc_true_path <- build_article("standard", pkg) Message @@ -123,14 +115,6 @@ # pkgdown deps are included only once in articles - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - Code path <- build_article("html-deps", pkg) Message diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index e45aa0003..afad1e7cb 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -1,11 +1,3 @@ -# version formatting in preserved - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - # data_home_sidebar() works by default Code diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index fccc3612d..9a9574a20 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -26,14 +26,6 @@ Reading man/e.Rd Writing reference/e.html ---- - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - --- Code @@ -45,14 +37,6 @@ # pkgdown html dependencies are suppressed from examples in references - Code - init_site(pkg) - Message - Copying ../../../../inst/BS5/assets/link.svg and ../../../../inst/BS5/assets/pkgdown.js - to link.svg and pkgdown.js - ---- - Code build_reference(pkg, topics = "a") Message diff --git a/tests/testthat/_snaps/init.md b/tests/testthat/_snaps/init.md index fa579a752..953b138c4 100644 --- a/tests/testthat/_snaps/init.md +++ b/tests/testthat/_snaps/init.md @@ -1,13 +1,3 @@ -# single extra.css correctly copied - - Code - init_site(pkg) - Message - Copying ../../../../inst/BS3/assets/bootstrap-toc.css, ../../../../inst/BS3/assets/bootstrap-toc.js, ../../../../inst/BS3/assets/docsearch.css, ../../../../inst/BS3/assets/docsearch.js, ../../../../inst/BS3/assets/link.svg, ../../../../inst/BS3/assets/pkgdown.css, and ../../../../inst/BS3/assets/pkgdown.js - to bootstrap-toc.css, bootstrap-toc.js, docsearch.css, docsearch.js, link.svg, pkgdown.css, and pkgdown.js - Copying pkgdown/extra.css - to extra.css - # site meta doesn't break unexpectedly Code diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 43fd19913..037702796 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -125,7 +125,7 @@ test_that("BS5 article laid out correctly with and without TOC", { bootstrap: 5 ") - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_snapshot(toc_true_path <- build_article("standard", pkg)) expect_snapshot(toc_false_path <- build_article("toc-false", pkg)) diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index 502768b45..0d52ad2be 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -12,7 +12,7 @@ test_that("version formatting in preserved", { pkg <- local_pkgdown_site(test_path("assets/version-formatting")) expect_equal(pkg$version, "1.0.0-9000") - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) build_home_index(pkg, quiet = TRUE) index <- read_lines(path(pkg$dst_path, "index.html")) expect_true(any(grepl("1.0.0-9000", index, fixed = TRUE))) diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index 4176806b3..43356f136 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -62,7 +62,7 @@ test_that(".Rd without usage doesn't get Usage section", { template: bootstrap: 5 ") - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_snapshot(build_reference(pkg, topics = "e")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "e.html")) # tweak_anchors() moves id into

@@ -71,7 +71,7 @@ test_that(".Rd without usage doesn't get Usage section", { test_that("pkgdown html dependencies are suppressed from examples in references", { pkg <- local_pkgdown_site(test_path("assets/reference-html-dep")) - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_snapshot(build_reference(pkg, topics = "a")) html <- xml2::read_html(file.path(pkg$dst_path, "reference", "a.html")) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index f2dc407a4..7a7aefc1f 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -19,7 +19,7 @@ test_that("extra.css and extra.js copied and linked", { test_that("single extra.css correctly copied", { local_edition(3) pkg <- local_pkgdown_site(test_path("assets/init-extra-1")) - expect_snapshot(init_site(pkg)) + suppressMessages(expect_message(init_site(pkg))) expect_true(file_exists(path(pkg$dst_path, "extra.css"))) }) From a1c756a31e4c1d7da0206bb34ab6425c065a1853 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Wed, 29 Nov 2023 15:35:11 -0700 Subject: [PATCH 19/20] add more calls and update snapshots that should be all of them, there are so many --- R/build-articles.R | 15 ++++++++++++--- R/build-home-index.R | 12 ++++++++---- R/build-news.R | 13 ++++++++----- R/build-redirects.R | 5 ++++- R/init.R | 5 ++++- R/markdown.R | 1 + R/package.R | 11 +++++++---- R/rd-example.R | 12 +++++++++--- R/rd-html.R | 5 ++++- R/render.R | 5 ++++- R/rmarkdown.R | 2 +- R/templates.R | 10 ++++++++-- R/theme.R | 9 ++++++--- R/topics-external.R | 5 ++++- R/usage.R | 15 ++++++++++++--- R/utils-fs.R | 5 ++++- tests/testthat/_snaps/build-reference-index.md | 2 +- tests/testthat/_snaps/check.md | 2 +- tests/testthat/_snaps/rd-html.md | 2 +- tests/testthat/_snaps/topics-external.md | 2 +- 20 files changed, 100 insertions(+), 38 deletions(-) diff --git a/R/build-articles.R b/R/build-articles.R index f3f165a5a..1f4292512 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -207,7 +207,10 @@ build_article <- function(name, # allow code sharing with building of the index. vig <- match(name, pkg$vignettes$name) if (is.na(vig)) { - cli::cli_abort("Can't find article {.file {name}}") + cli::cli_abort( + "Can't find article {.file {name}}", + call = caller_env() + ) } input <- pkg$vignettes$file_in[vig] @@ -368,7 +371,10 @@ data_articles_index <- function(pkg = ".") { missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package)) if (length(missing) > 0) { - cli::cli_abort("{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}") + cli::cli_abort( + "{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}", + call = caller_env() + ) } print_yaml(list( @@ -379,7 +385,10 @@ data_articles_index <- function(pkg = ".") { data_articles_index_section <- function(section, pkg) { if (!set_contains(names(section), c("title", "contents"))) { - cli::cli_abort("Section must have components {.field title}, {.field contents}") + cli::cli_abort( + "Section must have components {.field title}, {.field contents}", + call = caller_env() + ) } # Match topics against any aliases diff --git a/R/build-home-index.R b/R/build-home-index.R index 516808b20..86b99782a 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -70,10 +70,14 @@ data_home_sidebar <- function(pkg = ".") { pkg, c('home', 'sidebar', 'html'), fmt = TRUE, cfg = TRUE ) - cli::cli_abort(c( - "Can't locate {.file {rel_html_path}}.", - x = paste0(msg_fld, " is misconfigured.") - )) + cli::cli_abort( + c( + "Can't locate {.file {rel_html_path}}.", + x = paste0(msg_fld, " is misconfigured.") + ), + call = caller_env() + ) + } return(read_file(html_path)) diff --git a/R/build-news.R b/R/build-news.R index 34d145df2..03643affb 100644 --- a/R/build-news.R +++ b/R/build-news.R @@ -160,11 +160,14 @@ data_news <- function(pkg = list()) { xml2::xml_name() ulevels <- unique(levels) if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) { - cli::cli_abort(c( - "Invalid NEWS.md: inconsistent use of section headings.", - i = "Top-level headings must be either all

or all

.", - i = "See {.help pkgdown::build_news} for more details." - )) + cli::cli_abort( + c( + "Invalid NEWS.md: inconsistent use of section headings.", + i = "Top-level headings must be either all

or all

.", + i = "See {.help pkgdown::build_news} for more details." + ), + call = caller_env() + ) } if (ulevels == "h1") { # Bump every heading down a level so to get a single

for the page title diff --git a/R/build-redirects.R b/R/build-redirects.R index 9a8fda362..9bd64871f 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -14,7 +14,10 @@ build_redirects <- function(pkg = ".", cli::cli_rule("Building redirects") if (is.null(pkg$meta$url)) { msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE) - cli::cli_abort(paste0(msg_fld, " is required to generate redirects.")) + cli::cli_abort( + paste0(msg_fld, " is required to generate redirects."), + call = caller_env() + ) } purrr::iwalk( diff --git a/R/init.R b/R/init.R index ac6d87b87..8946dfd86 100644 --- a/R/init.R +++ b/R/init.R @@ -24,7 +24,10 @@ init_site <- function(pkg = ".") { pkg <- as_pkgdown(pkg) if (is_non_pkgdown_site(pkg$dst_path)) { - cli::cli_abort("{.file {pkg$dst_path}} is non-empty and not built by pkgdown") + cli::cli_abort( + "{.file {pkg$dst_path}} is non-empty and not built by pkgdown", + call = caller_env() + ) } cli::cli_rule("Initialising site") diff --git a/R/markdown.R b/R/markdown.R index 2c8189a9e..5574343fe 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -18,6 +18,7 @@ markdown_text_inline <- function(text, where = "", ...) { if (length(children) > 1) { cli::cli_abort( "Can't use a block element in {.var {where}}, need an inline element: {.var {text}}", + call = caller_env() ) } diff --git a/R/package.R b/R/package.R index c3ea28654..415baf2ef 100644 --- a/R/package.R +++ b/R/package.R @@ -296,8 +296,11 @@ check_unique_article_paths <- function(file_in, file_out) { }) names(same_out_bullets) <- rep_len("x", length(same_out_bullets)) - cli::cli_abort(c( - "Rendered articles must have unique names. Rename or relocate:", - same_out_bullets - )) + cli::cli_abort( + c( + "Rendered articles must have unique names. Rename or relocate:", + same_out_bullets + ), + call = caller_env() + ) } diff --git a/R/rd-example.R b/R/rd-example.R index 4c025ab8d..ee54d2cf9 100644 --- a/R/rd-example.R +++ b/R/rd-example.R @@ -48,13 +48,17 @@ process_conditional_examples <- function(rd) { grepl("# examplesIf$", x[[1]]) })) if (length(which_exif) == 0) return(rd) - if (length(which_exif) %% 2 != 0) cli::cli_abort("@examplesIf error, not closed?") + if (length(which_exif) %% 2 != 0) { + cli::cli_abort("@examplesIf error, not closed?", call = caller_env()) + } remove <- integer() modes <- c("begin", "end") for (idx in which_exif) { if (rd[[idx]] != "}) # examplesIf") { # Start of @examplesIf - if (modes[1] == "end") cli::cli_abort("@examplesIf error, not closed?") + if (modes[1] == "end") { + cli::cli_abort("@examplesIf error, not closed?", call = caller_env()) + } cond_expr <- parse(text = paste0(rd[[idx]], "\n})"))[[1]][[2]] cond <- eval(cond_expr) if (isTRUE(cond)) { @@ -74,7 +78,9 @@ process_conditional_examples <- function(rd) { } } else { # End of @examplesIf - if (modes[1] == "begin") cli::cli_abort("@examplesIf error, closed twice?") + if (modes[1] == "begin") { + cli::cli_abort("@examplesIf error, closed twice?", call = caller_env()) + } if (isTRUE(cond)) { remove <- c(remove, idx, idx + 1L) } else { diff --git a/R/rd-html.R b/R/rd-html.R index 03372285c..2cf26a412 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -229,7 +229,10 @@ as_html.tag_Sexpr <- function(x, ...) { text = as.character(res), rd = flatten_text(rd_text(as.character(res))), hide = "", - cli::cli_abort("\\\\Sexpr{{result={results}}} not yet supported") + cli::cli_abort( + "\\\\Sexpr{{result={results}}} not yet supported", + call = caller_env() + ) ) } diff --git a/R/render.R b/R/render.R index a18560bbd..ec90fcb96 100644 --- a/R/render.R +++ b/R/render.R @@ -149,7 +149,10 @@ data_open_graph <- function(pkg = ".") { check_open_graph <- function(og) { if (!is.list(og)) { fog <- friendly_type_of(og) - cli::cli_abort("{.var opengraph} must be a list, not {.val fog}") + cli::cli_abort( + "{.var opengraph} must be a list, not {.val fog}", + call = caller_env() + ) } supported_fields <- c("image", "twitter") unsupported_fields <- setdiff(names(og), supported_fields) diff --git a/R/rmarkdown.R b/R/rmarkdown.R index d823fba83..52c937f37 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -7,7 +7,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet output_path <- path_abs(output, pkg$dst_path) if (!file_exists(input_path)) { - cli::cli_abort("Can't find {src_path(input)") + cli::cli_abort("Can't find {src_path(input)", call = caller_env()) } cli::cli_inform("Reading {src_path(input)}") diff --git a/R/templates.R b/R/templates.R index 00ec08fa6..54816e4e5 100644 --- a/R/templates.R +++ b/R/templates.R @@ -7,7 +7,10 @@ find_template <- function(type, name, ext = ".html", pkg = ".") { if (length(existing) == 0) { tname <- paste0(type, "-", name) - cli::cli_abort("Can't find template for {.val {tname}}.") + cli::cli_abort( + "Can't find template for {.val {tname}}.", + call = caller_env() + ) } existing[[1]] } @@ -44,7 +47,10 @@ templates_dir <- function(pkg = list()) { if (!is.null(template$path)) { # Directory specified in yaml doesn't exist, so eagerly error if (!dir_exists(template$path)) { - cli::cli_abort("Can't find templates path: {src_path(template$path)}") + cli::cli_abort( + "Can't find templates path: {src_path(template$path)}", + call = caller_env() + ) } path_abs(template$path, start = pkg$src_path) } else if (!is.null(template$package)) { diff --git a/R/theme.R b/R/theme.R index 6df16e2ac..eb7e3f142 100644 --- a/R/theme.R +++ b/R/theme.R @@ -12,7 +12,10 @@ build_bslib <- function(pkg = ".") { data_deps <- function(pkg, depth) { if (!file.exists(data_deps_path(pkg))) { - cli::cli_abort("Run {.fn pkgdown::init_site} first.") + cli::cli_abort( + "Run {.fn pkgdown::init_site} first.", + call = caller_env() + ) } deps_path <- paste0(up_path(depth), "deps") @@ -59,7 +62,7 @@ bs_theme_rules <- function(pkg) { cli::cli_abort(c( "Unknown theme: {.val {theme}}", i = "Valid themes are: {.val highlight_styles()}" - )) + ), call = caller_env()) } paths <- c(paths, theme_path) @@ -110,7 +113,7 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { pkgdown_field(pkg, c("template", "bootstrap")) ), x = "Edit settings in {.file {pkgdown_config_relpath(pkg)}}" - )) + ), call = caller_env()) } } diff --git a/R/topics-external.R b/R/topics-external.R index e0d6620a9..0bd56bd90 100644 --- a/R/topics-external.R +++ b/R/topics-external.R @@ -30,7 +30,10 @@ get_rd_from_help <- function(package, alias) { help <- utils::help((alias), (package)) if (length(help) == 0) { fun <- paste0(package, "::", alias) - cli::cli_abort("Could not find documentation for {.fn {fun}}.") + cli::cli_abort( + "Could not find documentation for {.fn {fun}}.", + call = caller_env() + ) return() } diff --git a/R/usage.R b/R/usage.R index 77e9d0940..aa88be084 100644 --- a/R/usage.R +++ b/R/usage.R @@ -86,7 +86,10 @@ usage_type <- function(x) { out } else { untype <- paste0(typeof(x), " (in ", as.character(x), ")") - cli::cli_abort("Unknown type: {.val {untype}}") + cli::cli_abort( + "Unknown type: {.val {untype}}", + call = caller_env() + ) } } @@ -130,7 +133,10 @@ fun_info <- function(fun) { name = call_name(fun) ) } else { - cli::cli_abort("Unknown call: {.val {as.character(x[[1]])}}") + cli::cli_abort( + "Unknown call: {.val {as.character(x[[1]])}}", + call = caller_env() + ) } } else { list( @@ -161,7 +167,10 @@ usage_code.NULL <- function(x) character() #' @export usage_code.tag <- function(x) { if (!identical(class(x), "tag")) { - cli::cli_abort("Undefined tag in usage: {.val class(x)[[1]]}}") + cli::cli_abort( + "Undefined tag in usage: {.val class(x)[[1]]}}", + call = caller_env() + ) } paste0(purrr::flatten_chr(purrr::map(x, usage_code)), collapse = "") } diff --git a/R/utils-fs.R b/R/utils-fs.R index 8cb22a5ca..9e4445da0 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -55,7 +55,10 @@ out_of_date <- function(source, target) { return(TRUE) if (!file_exists(source)) { - cli::cli_abort("{.fn {source}} does not exist") + cli::cli_abort( + "{.fn {source}} does not exist", + call = caller_env() + ) } file.info(source)$mtime > file.info(target)$mtime diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index aceb87436..13a43f0e2 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -94,7 +94,7 @@ i In index: 1. Caused by error in `purrr::map2()`: i In index: 1. - Caused by error in `.f()`: + Caused by error in `map2_()`: ! Could not find documentation for `rlang::lala()`. # can use a topic from another package diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index 23dd24cee..769719da0 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -13,7 +13,7 @@ Code check_pkgdown(pkg) Condition - Error in `data_articles_index()`: + Error in `check_pkgdown()`: ! Vignettes missing from index: 'articles/nested' and 'width' # informs if everything is ok diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index 0f687d649..f0d2fb04a 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -39,7 +39,7 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `.f()`: + Caused by error in `map_()`: ! \\Sexpr{result=verbatim} not yet supported # bad specs throw errors diff --git a/tests/testthat/_snaps/topics-external.md b/tests/testthat/_snaps/topics-external.md index 4584ff7d2..f2f7ab738 100644 --- a/tests/testthat/_snaps/topics-external.md +++ b/tests/testthat/_snaps/topics-external.md @@ -28,6 +28,6 @@ Condition Error in `purrr::map2()`: i In index: 1. - Caused by error in `.f()`: + Caused by error in `map2_()`: ! Could not find documentation for `base::doesntexist()`. From 6f1ca8e02995e90f2d98c13e6cf37eac78aac4a5 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Thu, 30 Nov 2023 06:45:35 -0700 Subject: [PATCH 20/20] Respond to review --- R/build-articles.R | 5 ++--- R/build-favicons.R | 10 +++------- R/build-reference.R | 2 +- R/build-search-docs.R | 2 +- R/build.R | 6 +++--- R/preview.R | 2 +- R/rd-html.R | 2 +- R/render.R | 7 +++++-- R/rmarkdown.R | 7 +++++-- tests/testthat/_snaps/build-reference.md | 2 +- tests/testthat/_snaps/check.md | 2 +- tests/testthat/_snaps/rd-html.md | 8 ++++---- tests/testthat/_snaps/rmarkdown.md | 3 ++- 13 files changed, 30 insertions(+), 28 deletions(-) diff --git a/R/build-articles.R b/R/build-articles.R index 1f4292512..ceb406d93 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -208,8 +208,7 @@ build_article <- function(name, vig <- match(name, pkg$vignettes$name) if (is.na(vig)) { cli::cli_abort( - "Can't find article {.file {name}}", - call = caller_env() + "Can't find article {.file {name}}" ) } @@ -372,7 +371,7 @@ data_articles_index <- function(pkg = ".") { if (length(missing) > 0) { cli::cli_abort( - "{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}", + "{length(missing)} vignette{?s} missing from index: {.file {missing}}.", call = caller_env() ) } diff --git a/R/build-favicons.R b/R/build-favicons.R index a151c5bf4..066f4dfb7 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -25,8 +25,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { if (is.null(logo_path)) { cli::cli_abort( - "Can't find package logo PNG or SVG to build favicons.", - call = caller_env() + "Can't find package logo PNG or SVG to build favicons." ) } @@ -79,13 +78,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { result <- content$favicon_generation_result if (!identical(result$result$status, "success")) { - cli::cli_abort( - c( + cli::cli_abort(c( "API request failed.", "i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}" - ), - call = caller_env() - ) + )) } tmp <- tempfile() diff --git a/R/build-reference.R b/R/build-reference.R index 3e41e75aa..66a62e23e 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -165,7 +165,7 @@ build_reference <- function(pkg = ".", lifecycle::deprecate_warn( "1.4.0", "build_site(document)", - details = "Please use `build_site(devel)` instead." + details = "build_site(devel)" ) devel <- document } diff --git a/R/build-search-docs.R b/R/build-search-docs.R index c5264ff08..012b93986 100644 --- a/R/build-search-docs.R +++ b/R/build-search-docs.R @@ -86,7 +86,7 @@ url_node <- function(url) { build_search <- function(pkg = ".", override = list()) { pkg <- section_init(pkg, depth = 1L, override = override) - cli::cli_inform("Building search index") + cli::cli_rule("Building search index") search_index <- build_search_index(pkg) jsonlite::write_json( search_index, diff --git a/R/build.R b/R/build.R index b185dc1b2..f455f9b31 100644 --- a/R/build.R +++ b/R/build.R @@ -331,7 +331,7 @@ build_site <- function(pkg = ".", lifecycle::deprecate_warn( "1.4.0", "build_site(document)", - details = "Please use `build_site(devel)` instead." + details = "build_site(devel)" ) devel <- document } @@ -408,7 +408,7 @@ build_site_external <- function(pkg = ".", timeout = getOption('pkgdown.timeout', Inf) ) - cli::cli_rule(paste0("finished building pkgdown site for package ", cli::col_blue(pkg$package))) + cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package))) preview_site(pkg, preview = preview) invisible() @@ -453,6 +453,6 @@ build_site_local <- function(pkg = ".", build_search(pkg, override = override) } - cli::cli_rule(paste0("finished building pkgdown site for package ", cli::col_blue(pkg$package))) + cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package))) preview_site(pkg, preview = preview) } diff --git a/R/preview.R b/R/preview.R index f4e7fc9d6..130392896 100644 --- a/R/preview.R +++ b/R/preview.R @@ -11,7 +11,7 @@ preview_site <- function(pkg = ".", path = ".", preview = NA) { } if (preview) { - cli::cli_alert("Previewing site") + cli::cli_alert_info("Previewing site") utils::browseURL(path(pkg$dst_path, path, "index.html")) } diff --git a/R/rd-html.R b/R/rd-html.R index 2cf26a412..712f97501 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -571,7 +571,7 @@ parse_opts <- function(string) { stop_bad_tag <- function(tag, msg = NULL) { bad_tag <- paste0("\\", tag, "{}") msg_abort <- 'Failed to parse tag {.val {bad_tag}}.' - cli::cli_abort(c(msg_abort, i = msg), call = caller_env()) + cli::cli_abort(c(msg_abort, i = msg), call = NULL) } is_newline <- function(x, trim = FALSE) { diff --git a/R/render.R b/R/render.R index ec90fcb96..81ebb5a00 100644 --- a/R/render.R +++ b/R/render.R @@ -150,7 +150,7 @@ check_open_graph <- function(og) { if (!is.list(og)) { fog <- friendly_type_of(og) cli::cli_abort( - "{.var opengraph} must be a list, not {.val fog}", + "{.var opengraph} must be a list, not {.val fog}.", call = caller_env() ) } @@ -169,7 +169,10 @@ check_open_graph <- function(og) { ) } if (!is.list(og$twitter)) { - cli::cli_abort("The {.var opengraph: twitter} option must be a list.") + cli::cli_abort( + "The {.var opengraph: twitter} option must be a list.", + call = caller_env() + ) } if (is.null(og$twitter$creator) && is.null(og$twitter$site)) { cli::cli_abort( diff --git a/R/rmarkdown.R b/R/rmarkdown.R index 52c937f37..4f1b8308f 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -7,7 +7,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet output_path <- path_abs(output, pkg$dst_path) if (!file_exists(input_path)) { - cli::cli_abort("Can't find {src_path(input)", call = caller_env()) + cli::cli_abort("Can't find {src_path(input).", call = caller_env()) } cli::cli_inform("Reading {src_path(input)}") @@ -39,7 +39,10 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ), error = function(cnd) { cli::cli_abort( - "Failed to render RMarkdown document", + c( + "Failed to render RMarkdown document.", + x = gsub("\r", "", cnd$stderr, fixed = TRUE) + ), parent = cnd ) } diff --git a/tests/testthat/_snaps/build-reference.md b/tests/testthat/_snaps/build-reference.md index 9a9574a20..31f9b6a92 100644 --- a/tests/testthat/_snaps/build-reference.md +++ b/tests/testthat/_snaps/build-reference.md @@ -13,7 +13,7 @@ ! Failed to parse Rd in 'f.Rd' Caused by error in `purrr::map()`: i In index: 4. - Caused by error in `.f()`: + Caused by error: ! Failed to parse tag "\\url{}". i Check for empty \url{} tags. diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index 769719da0..d90010d88 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -14,7 +14,7 @@ check_pkgdown(pkg) Condition Error in `check_pkgdown()`: - ! Vignettes missing from index: 'articles/nested' and 'width' + ! 2 vignettes missing from index: 'articles/nested' and 'width'. # informs if everything is ok diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index f0d2fb04a..16c6be23d 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -49,7 +49,7 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `.f()`: + Caused by error: ! Failed to parse tag "\\url{}". i Check for empty \url{} tags. Code @@ -57,7 +57,7 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `.f()`: + Caused by error: ! Failed to parse tag "\\url{}". i This may be caused by a \url tag that spans a line break. Code @@ -65,7 +65,7 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `.f()`: + Caused by error: ! Failed to parse tag "\\email{}". i empty Code @@ -73,7 +73,7 @@ Condition Error in `purrr::map_chr()`: i In index: 1. - Caused by error in `.f()`: + Caused by error: ! Failed to parse tag "\\linkS4class{}". # \describe items can contain multiple paragraphs diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md index e5f92a0f7..adee21568 100644 --- a/tests/testthat/_snaps/rmarkdown.md +++ b/tests/testthat/_snaps/rmarkdown.md @@ -15,7 +15,8 @@ Reading assets/pandoc-fail.Rmd Condition Error in `render_rmarkdown()`: - ! Failed to render RMarkdown document + ! Failed to render RMarkdown document. + x [WARNING] Could not fetch resource path-to-image.png Failing because there were warnings. Caused by error: ! in callr subprocess. Caused by error: