@@ -561,6 +561,12 @@ func (ts *TestScript) run() {
561561 }
562562
563563 failed := false
564+
565+ // lastBlockFailed tracks the failure state of the last block.
566+ // This allows us to rewind the last block if it didn't fail,
567+ // but an earlier block _did_ fail, in the case of ContinueOnError.
568+ lastBlockFailed := false
569+
564570 defer func () {
565571 // On a normal exit from the test loop, background processes are cleaned up
566572 // before we print PASS. If we return early (e.g., due to a test failure),
@@ -629,6 +635,7 @@ func (ts *TestScript) run() {
629635 // in error, do not needlessly show verbose output because of an
630636 // earlier block that was in error.
631637 verbose = ts .t .Verbose ()
638+ lastBlockFailed = false
632639
633640 // Print phase heading and mark start of phase output.
634641 fmt .Fprintf (& ts .log , "%s\n " , line )
@@ -640,6 +647,7 @@ func (ts *TestScript) run() {
640647 ok := ts .runLine (line )
641648 if ! ok {
642649 failed = true
650+ lastBlockFailed = true
643651 if ts .params .ContinueOnError {
644652 verbose = true
645653 } else {
@@ -664,14 +672,17 @@ func (ts *TestScript) run() {
664672 // Once we've reached the end of the script, ignore the status of background commands.
665673 ts .waitBackground (false )
666674
675+ if ! lastBlockFailed {
676+ rewind ()
677+ }
678+
667679 // If we reached here but we've failed (probably because ContinueOnError
668680 // was set), don't wipe the log and print "PASS".
669681 if failed {
670682 ts .t .FailNow ()
671683 }
672684
673685 // Final phase ended.
674- rewind ()
675686 markTime ()
676687 if ! ts .stopped {
677688 fmt .Fprintf (& ts .log , "PASS\n " )
0 commit comments