Skip to content

Commit

Permalink
snapshot inspect error tests and other minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aronatkins committed Jan 26, 2024
1 parent 6487066 commit 40a64b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
5 changes: 2 additions & 3 deletions R/appMetadata-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/_snaps/appMetadata-quarto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

24 changes: 18 additions & 6 deletions tests/testthat/test-appMetadata-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
)
})

Expand All @@ -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
)
})

0 comments on commit 40a64b4

Please sign in to comment.