Skip to content

Commit

Permalink
Correctly handle null value
Browse files Browse the repository at this point in the history
And mock function to test no quarto installed
  • Loading branch information
cderv committed Jan 30, 2024
1 parent 1292828 commit a1dbd20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Suggests:
curl,
knitr,
rsconnect (>= 0.8.26),
testthat (>= 3.1.0),
testthat (>= 3.1.7),
withr,
xfun
VignetteBuilder:
Expand Down
4 changes: 3 additions & 1 deletion R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ check_quarto_version <- function(ver, what, url) {
#' @export
quarto_binary_sitrep <- function(verbose = TRUE, debug = FALSE) {

quarto_found <- normalizePath(quarto_path(), mustWork = FALSE)
quarto_found <- quarto_path()
if (is.null(quarto_found)) {
if (verbose) {
cli::cli_alert_danger(quarto_not_found_msg)
}
return(FALSE)
}

quarto_found <- normalizePath(quarto_found, mustWork = FALSE)

same_config <- TRUE
if (debug) verbose <- TRUE

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/quarto.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@
Output
[1] TRUE

---

Code
quarto_binary_sitrep(debug = TRUE)
Message
x Quarto command-line tools path not found! Please make sure you have installed and added Quarto to your PATH or set the QUARTO_PATH environment variable.
Output
[1] FALSE

8 changes: 8 additions & 0 deletions tests/testthat/test-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ test_that("quarto CLI sitrep", {
transform = transform_quarto_cli_in_output(full_path = TRUE, normalize_path = TRUE)
)
)

# Mock no quarto found
with_mocked_bindings(
quarto_path = function(...) NULL,
expect_snapshot(
quarto_binary_sitrep(debug = TRUE)
)
)
})

0 comments on commit a1dbd20

Please sign in to comment.