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