Skip to content

Commit

Permalink
Another test
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Nov 22, 2024
1 parent ed545dd commit 577e6bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
15 changes: 7 additions & 8 deletions R/vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,17 @@ valid_vignette_name <- function(x) {
}

check_vignette_extension <- function(ext) {
valid_exts <- c("Rmd", "rmd", "qmd")
valid_exts_cli <- cli::cli_vec(
valid_exts,
style = list("vec-last" = ", or ")
)
if (! ext %in% valid_exts) {
# Quietly accept "rmd" here, tho we'll always write ".Rmd" in such a filepath
if (! ext %in% c("Rmd", "rmd", "qmd")) {
valid_exts_cli <- cli::cli_vec(
c("Rmd", "qmd"),
style = list("vec-last" = ", or ")
)
ui_abort(c(
"Invalid file extension: {.val {ext}}",
"Unsupported file extension: {.val {ext}}",
"usethis can only create a vignette or article with one of these
extensions: {.val {valid_exts_cli}}."
))

}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/vignette.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
i Start with a letter.
i Contain only letters, numbers, '_', and '-'.

# we error informatively for bad vignette extension

Code
check_vignette_extension("Rnw")
Condition
Error in `check_vignette_extension()`:
x Unsupported file extension: "Rnw"
i usethis can only create a vignette or article with one of these extensions: "Rmd" or "qmd".

7 changes: 7 additions & 0 deletions tests/testthat/test-vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ test_that("valid_vignette_name() works", {
expect_false(valid_vignette_name("01-test"))
expect_false(valid_vignette_name("test.1"))
})

test_that("we error informatively for bad vignette extension", {
expect_snapshot(
error = TRUE,
check_vignette_extension("Rnw")
)
})

0 comments on commit 577e6bb

Please sign in to comment.