Skip to content

Commit ee70938

Browse files
committed
testscript: rewind last block if it was not in error
When ContinueOnError is set, we want to rewind the last block if it was not in error.
1 parent a4ecbfb commit ee70938

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

testscript/testdata/testscript_logging.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ FAIL: $$WORK${/}scripts${/}testscript.txt:9: unexpected command failure
8383
[exit status 1]
8484
FAIL: $$WORK${/}scripts${/}testscript.txt:16: unexpected command failure
8585
# comment 6 (0.000s)
86-
> printargs section6
87-
[stdout]
88-
["printargs" "section6"]
8986
-- expect-stdout-vc.txt --
9087
** RUN testscript **
9188
# comment 1 (0.000s)

testscript/testscript.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)