@@ -134,7 +134,8 @@ expect_snapshot_qmd_output <- function(name, input, output_file = NULL, ...) {
134134transform_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 ) {
0 commit comments