From 577e6bb486e8cdce8874d33711a43f5ea89dfae6 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 22 Nov 2024 13:00:11 -0800 Subject: [PATCH] Another test --- R/vignette.R | 15 +++++++-------- tests/testthat/_snaps/vignette.md | 9 +++++++++ tests/testthat/test-vignette.R | 7 +++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/R/vignette.R b/R/vignette.R index 389bdb423..f60517bda 100644 --- a/R/vignette.R +++ b/R/vignette.R @@ -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}}." )) - } } diff --git a/tests/testthat/_snaps/vignette.md b/tests/testthat/_snaps/vignette.md index e7359ae1b..dbbd22c5f 100644 --- a/tests/testthat/_snaps/vignette.md +++ b/tests/testthat/_snaps/vignette.md @@ -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". + diff --git a/tests/testthat/test-vignette.R b/tests/testthat/test-vignette.R index c580faa7f..bb2d67633 100644 --- a/tests/testthat/test-vignette.R +++ b/tests/testthat/test-vignette.R @@ -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") + ) +})