From 40a64b415f224675fbdbf7ea906745d6c93e749c Mon Sep 17 00:00:00 2001 From: Aron Atkins Date: Fri, 26 Jan 2024 15:22:06 -0500 Subject: [PATCH] snapshot inspect error tests and other minor tweaks --- R/appMetadata-quarto.R | 5 ++--- tests/testthat/_snaps/appMetadata-quarto.md | 18 ++++++++++++++++ tests/testthat/test-appMetadata-quarto.R | 24 +++++++++++++++------ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/R/appMetadata-quarto.R b/R/appMetadata-quarto.R index 07cccf93..2c956593 100644 --- a/R/appMetadata-quarto.R +++ b/R/appMetadata-quarto.R @@ -55,13 +55,12 @@ quartoInspect <- function(appDir = NULL, appPrimaryDoc = NULL) { if (!is.null(status)) { cli::cli_abort( c( - "Unable to run `quarto inspect` against your content:", + "Failed to run `quarto inspect` against your content:", json ) ) } - parsed <- jsonlite::fromJSON(json) - return(parsed) + jsonlite::fromJSON(json) } # inlined from quarto::quarto_path() diff --git a/tests/testthat/_snaps/appMetadata-quarto.md b/tests/testthat/_snaps/appMetadata-quarto.md index 62994c8a..994a4808 100644 --- a/tests/testthat/_snaps/appMetadata-quarto.md +++ b/tests/testthat/_snaps/appMetadata-quarto.md @@ -7,3 +7,21 @@ ! `quarto` not found. i Check that it is installed and available on your `PATH`. +# quartoInspect produces an error when a document cannot be inspected + + Code + quartoInspect(dir, "bad.qmd") + Condition + Error in `quartoInspect()`: + ! Failed to run `quarto inspect` against your content: + ERROR: Unknown format unsupported + +# quartoInspect produces an error when a project cannot be inspected + + Code + quartoInspect(dir, "bad.qmd") + Condition + Error in `quartoInspect()`: + ! Failed to run `quarto inspect` against your content: + ERROR: Unsupported project type unsupported + diff --git a/tests/testthat/test-appMetadata-quarto.R b/tests/testthat/test-appMetadata-quarto.R index ecfa88e7..0a6e5448 100644 --- a/tests/testthat/test-appMetadata-quarto.R +++ b/tests/testthat/test-appMetadata-quarto.R @@ -99,6 +99,18 @@ test_that("quartoInspect processes content with filenames containing spaces", { expect_equal(inspect$engines, c("markdown")) }) +# Some versions of Quarto show Quarto stack traces with source references when +# inspect fails. +# +# Only preserve: +# +# Error in `quartoInspect()`: +# ! Failed to run `quarto inspect` against your content: +# ERROR: Unsupported project type unsupported +strip_quarto_trace <- function(lines) { + head(lines, 3) +} + test_that("quartoInspect produces an error when a document cannot be inspected", { skip_if_no_quarto() @@ -108,10 +120,10 @@ test_that("quartoInspect produces an error when a document cannot be inspected", "---", "this is a document using an unsupported format." ))) - expect_error( + expect_snapshot( quartoInspect(dir, "bad.qmd"), - "Unable to run `quarto inspect` against your content", - fixed = TRUE + error = TRUE, + transform = strip_quarto_trace ) }) @@ -132,9 +144,9 @@ test_that("quartoInspect produces an error when a project cannot be inspected", ) ) ) - expect_error( + expect_snapshot( quartoInspect(dir, "bad.qmd"), - "Unable to run `quarto inspect` against your content", - fixed = TRUE + error = TRUE, + transform = strip_quarto_trace ) })