Skip to content

Commit 8b904c9

Browse files
committed
don't try to keep stack trace in snapshot, just hide it
1 parent 0ea6e11 commit 8b904c9

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

tests/testthat/_snaps/quarto.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@
2020
ERROR: Book chapter 'intro.qmd' not found
2121
2222
Stack trace:
23-
at throwInputNotFound (<quarto.js full path with location>)
24-
at findInputs (<quarto.js full path with location>)
25-
at eventLoopTick (ext:core/01_core.js:178:7)
26-
at async findChapters (<quarto.js full path with location>)
27-
at async bookRenderItems (<quarto.js full path with location>)
28-
at async Object.bookProjectConfig [as config] (<quarto.js full path with location>)
29-
at async projectContext (<quarto.js full path with location>)
30-
at async inspectConfig (<quarto.js full path with location>)
31-
at async _Command.actionHandler (<quarto.js full path with location>)
32-
at async _Command.execute (<quarto.js full path with location>)
23+
<stack trace>
3324
3425
Caused by error:
3526
! System command 'quarto' failed

tests/testthat/helper.R

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ expect_snapshot_qmd_output <- function(name, input, output_file = NULL, ...) {
134134
transform_quarto_cli_in_output <- function(
135135
full_path = FALSE,
136136
version = FALSE,
137-
dir_only = FALSE
137+
dir_only = FALSE,
138+
hide_stack = FALSE
138139
) {
139140
hide_path <- function(lines, real_path) {
140141
gsub(
@@ -147,6 +148,38 @@ transform_quarto_cli_in_output <- function(
147148

148149
return(
149150
function(lines) {
151+
if (hide_stack) {
152+
# Hide possible stack first
153+
stack_trace_index <- which(grepl("\\s*Stack trace\\:", lines))
154+
if (
155+
length(stack_trace_index) > 0 && stack_trace_index < length(lines)
156+
) {
157+
at_lines_indices <- which(grepl("^\\s*at ", lines))
158+
at_lines_after_stack <- at_lines_indices[
159+
at_lines_indices > stack_trace_index
160+
]
161+
if (length(at_lines_after_stack) > 0) {
162+
# Find the continuous sequence (no gaps)
163+
gaps <- diff(at_lines_after_stack) > 1
164+
end_pos <- if (any(gaps)) which(gaps)[1] else
165+
length(at_lines_after_stack)
166+
consecutive_indices <- at_lines_after_stack[1:end_pos]
167+
168+
stack_line <- lines[stack_trace_index]
169+
indentation <- regmatches(stack_line, regexpr("^\\s*", stack_line))
170+
lines[consecutive_indices[1]] <- paste0(
171+
indentation,
172+
"<stack trace>"
173+
)
174+
if (length(consecutive_indices) > 1) {
175+
lines <- lines[
176+
-consecutive_indices[2:length(consecutive_indices)]
177+
]
178+
}
179+
}
180+
}
181+
}
182+
150183
if (full_path) {
151184
quarto_found <- find_quarto()
152185
if (dir_only) {

tests/testthat/test-quarto.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ test_that("quarto_run report full quarto cli error message", {
2929
quarto_inspect(),
3030
transform = transform_quarto_cli_in_output(
3131
full_path = TRUE,
32-
dir_only = TRUE
32+
dir_only = TRUE,
33+
hide_stack = TRUE
3334
)
3435
)
3536
})

0 commit comments

Comments
 (0)