Skip to content

Commit

Permalink
Review use of expect_snapshot() and friends (#2532)
Browse files Browse the repository at this point in the history
* Don't use it just to suppress output
* Convert `expect_snapshot_error()` to `expect_snapshot()`

Fixes #2528
  • Loading branch information
hadley authored May 13, 2024
1 parent 27eec03 commit 1b2508f
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 244 deletions.
80 changes: 0 additions & 80 deletions tests/testthat/_snaps/build-articles.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@
* kitten.jpg
* missing-images_files/figure-html/unnamed-chunk-1-1.png

# articles don't include header-attrs.js script

Code
path <- build_article("standard", pkg)
Message
Reading vignettes/standard.Rmd
Writing `articles/standard.html`

# can build article that uses html_vignette

Code
Expand All @@ -37,86 +29,14 @@
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
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`

---

Code
build_redirects(pkg)
Message
-- Building redirects ----------------------------------------------------------
Adding redirect from articles/articles/nested.html to articles/nested.html.

# pkgdown deps are included only once in articles

Code
path <- build_article("html-deps", pkg)
Message
Reading vignettes/html-deps.Rmd
Writing `articles/html-deps.html`

# warns about articles missing from index

Code
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/_snaps/build-home-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@

# data_home_sidebar() errors well when no HTML file

home.sidebar.html specifies a file that doesn't exist ('file.html').
i Edit _pkgdown.yml to fix the problem.
Code
data_home_sidebar(pkg)
Condition
Error:
! home.sidebar.html specifies a file that doesn't exist ('file.html').
i Edit _pkgdown.yml to fix the problem.

# data_home_sidebar() can get a custom markdown formatted component

Expand Down
41 changes: 0 additions & 41 deletions tests/testthat/_snaps/build-home.md

This file was deleted.

7 changes: 0 additions & 7 deletions tests/testthat/_snaps/build-logo.md

This file was deleted.

20 changes: 14 additions & 6 deletions tests/testthat/_snaps/build-news.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@

# clear error for bad hierarchy - bad nesting

Invalid NEWS.md: inconsistent use of section headings.
i Top-level headings must be either all <h1> or all <h2>.
i See `?pkgdown::build_news()` for more details.
Code
data_news(temp_pkg)
Condition
Error:
! Invalid NEWS.md: inconsistent use of section headings.
i Top-level headings must be either all <h1> or all <h2>.
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 <h1> or all <h2>.
i See `?pkgdown::build_news()` for more details.
Code
data_news(temp_pkg)
Condition
Error:
! Invalid NEWS.md: inconsistent use of section headings.
i Top-level headings must be either all <h1> or all <h2>.
i See `?pkgdown::build_news()` for more details.

# news can contain footnotes

Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/_snaps/build-reference-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@

# errors well when a content entry is empty

Section "bla": contents 2 is empty.
i Edit _pkgdown.yml to fix the problem.
Code
build_reference_index(pkg)
Condition
Error in `build_reference_index()`:
! Section "bla": contents 2 is empty.
i Edit _pkgdown.yml to fix the problem.

# errors well when a content entry is not a character

Expand Down
30 changes: 0 additions & 30 deletions tests/testthat/_snaps/build-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,6 @@
! Failed to parse tag "\\url{}".
i Check for empty \url{} tags.

# .Rd without usage doesn't get Usage section

Code
build_reference(pkg, topics = "e")
Message
-- Building function reference -------------------------------------------------
Writing `reference/index.html`
Reading man/e.Rd
Writing `reference/e.html`

---

Code
build_reference(pkg, topics = "e")
Message
-- Building function reference -------------------------------------------------
Writing `reference/index.html`
Reading man/e.Rd
Writing `reference/e.html`

# pkgdown html dependencies are suppressed from examples in references

Code
build_reference(pkg, topics = "a")
Message
-- Building function reference -------------------------------------------------
Writing `reference/index.html`
Reading man/a.Rd
Writing `reference/a.html`

# examples are reproducible by default, i.e. 'seed' is respected

Code
Expand Down
20 changes: 0 additions & 20 deletions tests/testthat/_snaps/figure.md

This file was deleted.

8 changes: 6 additions & 2 deletions tests/testthat/_snaps/markdown.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# markdown_text_inline() works with inline markdown

<inline> must supply an inline element, not a block element.
i Edit _pkgdown.yml to fix the problem.
Code
markdown_text_inline("x\n\ny", pkg = pkg)
Condition
Error:
! <inline> must supply an inline element, not a block element.
i Edit _pkgdown.yml to fix the problem.

23 changes: 14 additions & 9 deletions tests/testthat/_snaps/render.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# check_bslib_theme() works

x Can't find Bootswatch/bslib theme preset "paper" (template.bootswatch).
i Using Bootstrap version 4 (template.bootstrap).
i Edit _pkgdown.yml to fix the problem.

---

x Can't find Bootswatch/bslib theme preset "paper" (template and preset).
i Using Bootstrap version 4 (template.bootstrap).
i Edit _pkgdown.yml to fix the problem.
Code
check_bslib_theme("paper", pkg, bs_version = 4)
Condition
Error:
x Can't find Bootswatch/bslib theme preset "paper" (template.bootswatch).
i Using Bootstrap version 4 (template.bootstrap).
i Edit _pkgdown.yml to fix the problem.
Code
check_bslib_theme("paper", pkg, bs_version = 4, field = c("template", "preset"))
Condition
Error:
x Can't find Bootswatch/bslib theme preset "paper" (template and preset).
i Using Bootstrap version 4 (template.bootstrap).
i Edit _pkgdown.yml to fix the problem.

# capture data_template()

Expand Down
12 changes: 9 additions & 3 deletions tests/testthat/_snaps/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

# Warns when Bootstrap theme is specified in multiple locations

Multiple Bootstrap preset themes were set. Using "flatly" from template.bslib.preset.
x Found template.bslib.preset, template.bslib.bootswatch, template.bootswatch, and template.params.bootswatch.
i Remove extraneous theme declarations to avoid this warning.
Code
get_bslib_theme(pkg)
Condition
Warning:
Multiple Bootstrap preset themes were set. Using "flatly" from template.bslib.preset.
x Found template.bslib.preset, template.bslib.bootswatch, template.bootswatch, and template.params.bootswatch.
i Remove extraneous theme declarations to avoid this warning.
Output
[1] "flatly"

Loading

0 comments on commit 1b2508f

Please sign in to comment.