Skip to content

Commit d26ee74

Browse files
committed
don't try to keep stack trace in snapshot, just hide it
1 parent 13e0045 commit d26ee74

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:175: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
@@ -145,7 +145,8 @@ expect_snapshot_qmd_output <- function(name, input, output_file = NULL, ...) {
145145
transform_quarto_cli_in_output <- function(
146146
full_path = FALSE,
147147
version = FALSE,
148-
dir_only = FALSE
148+
dir_only = FALSE,
149+
hide_stack = FALSE
149150
) {
150151
hide_path <- function(lines, real_path) {
151152
gsub(
@@ -158,6 +159,38 @@ transform_quarto_cli_in_output <- function(
158159

159160
return(
160161
function(lines) {
162+
if (hide_stack) {
163+
# Hide possible stack first
164+
stack_trace_index <- which(grepl("\\s*Stack trace\\:", lines))
165+
if (
166+
length(stack_trace_index) > 0 && stack_trace_index < length(lines)
167+
) {
168+
at_lines_indices <- which(grepl("^\\s*at ", lines))
169+
at_lines_after_stack <- at_lines_indices[
170+
at_lines_indices > stack_trace_index
171+
]
172+
if (length(at_lines_after_stack) > 0) {
173+
# Find the continuous sequence (no gaps)
174+
gaps <- diff(at_lines_after_stack) > 1
175+
end_pos <- if (any(gaps)) which(gaps)[1] else
176+
length(at_lines_after_stack)
177+
consecutive_indices <- at_lines_after_stack[1:end_pos]
178+
179+
stack_line <- lines[stack_trace_index]
180+
indentation <- regmatches(stack_line, regexpr("^\\s*", stack_line))
181+
lines[consecutive_indices[1]] <- paste0(
182+
indentation,
183+
"<stack trace>"
184+
)
185+
if (length(consecutive_indices) > 1) {
186+
lines <- lines[
187+
-consecutive_indices[2:length(consecutive_indices)]
188+
]
189+
}
190+
}
191+
}
192+
}
193+
161194
if (full_path) {
162195
quarto_found <- find_quarto()
163196
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)