@@ -367,18 +367,12 @@ expect_snapshot_helper <- function(
367367 } else {
368368 variant_lab <- " "
369369 }
370- if (in_check_reporter()) {
371- hint <- " "
372- } else {
373- hint <- snapshot_accept_hint(variant , snapshotter $ file )
374- }
375370
376371 if (length(comp ) != 0 ) {
377- msg <- sprintf(
378- " Snapshot of %s has changed%s:\n %s\n\n %s" ,
379- lab ,
380- variant_lab ,
381- paste0(comp , collapse = " \n\n " ),
372+ hint <- snapshot_hint(NULL , variant , snapshotter $ file )
373+ msg <- c(
374+ sprintf(" Snapshot of %s has changed%s:" , lab , variant_lab ),
375+ comp ,
382376 hint
383377 )
384378 return (snapshot_fail(msg , trace_env = trace_env ))
@@ -387,18 +381,25 @@ expect_snapshot_helper <- function(
387381 pass(NULL )
388382}
389383
390- snapshot_accept_hint <- function (variant , file , reset_output = TRUE ) {
384+ snapshot_hint <- function (
385+ file ,
386+ variant ,
387+ name ,
388+ show_accept = TRUE ,
389+ reset_output = TRUE
390+ ) {
391+ if (in_check_reporter()) {
392+ return (" " )
393+ }
394+
391395 if (reset_output ) {
392396 local_reporter_output()
393397 }
394398
395- if (is.null(variant ) || variant == " _default" ) {
396- name <- file
397- } else {
398- name <- file.path(variant , file )
399- }
399+ id <- c(file , if (! identical(variant , " _default" )) variant , name )
400+ full_name <- paste0(id , collapse = " /" )
400401
401- args <- encodeString(name , quote = ' "' )
402+ args <- encodeString(full_name , quote = ' "' )
402403 # Include path argument if we're in a different working directory
403404 wd <- Sys.getenv(" TESTTHAT_WD" , unset = " " )
404405 if (wd != " " ) {
@@ -408,17 +409,23 @@ snapshot_accept_hint <- function(variant, file, reset_output = TRUE) {
408409 }
409410 }
410411
411- paste0(
412- cli :: format_inline(
413- " * Run {.run testthat::snapshot_accept({args})} to accept the change."
414- ),
415- " \n " ,
416- cli :: format_inline(
417- " * Run {.run testthat::snapshot_review({args})} to review the change."
418- )
412+ accept_link <- cli :: format_inline(" {.run testthat::snapshot_accept({args})}" )
413+ review_link <- cli :: format_inline(" {.run testthat::snapshot_review({args})}" )
414+
415+ out <- c(
416+ if (show_accept ) sprintf(" * Run %s to accept the change." , accept_link ),
417+ sprintf(" * Run %s to review the change." , review_link )
419418 )
419+ structure(out , class = " testthat_hint" )
420420}
421421
422+ # ' @export
423+ print.testthat_hint <- function (x , ... ) {
424+ cat(paste0(x , " \n " , collapse = " " ))
425+ invisible (x )
426+ }
427+
428+
422429snapshot_not_available <- function (message ) {
423430 local_reporter_output()
424431
0 commit comments