Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions testscript/testdata/testscript_logging.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ printargs section3
status 1

# comment 4
printargs section3
printargs section4

# comment 5
printargs section5
status 1

# comment 6
printargs section6

-- expect-stdout.txt --
** RUN testscript **
# comment 1 (0.000s)
Expand Down Expand Up @@ -79,6 +82,7 @@ FAIL: $$WORK${/}scripts${/}testscript.txt:9: unexpected command failure
> status 1
[exit status 1]
FAIL: $$WORK${/}scripts${/}testscript.txt:16: unexpected command failure
# comment 6 (0.000s)
-- expect-stdout-vc.txt --
** RUN testscript **
# comment 1 (0.000s)
Expand All @@ -97,13 +101,17 @@ FAIL: $$WORK${/}scripts${/}testscript.txt:16: unexpected command failure
[exit status 1]
FAIL: $$WORK${/}scripts${/}testscript.txt:9: unexpected command failure
# comment 4 (0.000s)
> printargs section3
> printargs section4
[stdout]
["printargs" "section3"]
["printargs" "section4"]
# comment 5 (0.000s)
> printargs section5
[stdout]
["printargs" "section5"]
> status 1
[exit status 1]
FAIL: $$WORK${/}scripts${/}testscript.txt:16: unexpected command failure
# comment 6 (0.000s)
> printargs section6
[stdout]
["printargs" "section6"]
13 changes: 12 additions & 1 deletion testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ func (ts *TestScript) run() {
}

failed := false

// lastBlockFailed tracks the failure state of the last block.
// This allows us to rewind the last block if it didn't fail,
// but an earlier block _did_ fail, in the case of ContinueOnError.
lastBlockFailed := false

defer func() {
// On a normal exit from the test loop, background processes are cleaned up
// before we print PASS. If we return early (e.g., due to a test failure),
Expand Down Expand Up @@ -629,6 +635,7 @@ func (ts *TestScript) run() {
// in error, do not needlessly show verbose output because of an
// earlier block that was in error.
verbose = ts.t.Verbose()
lastBlockFailed = false

// Print phase heading and mark start of phase output.
fmt.Fprintf(&ts.log, "%s\n", line)
Expand All @@ -640,6 +647,7 @@ func (ts *TestScript) run() {
ok := ts.runLine(line)
if !ok {
failed = true
lastBlockFailed = true
if ts.params.ContinueOnError {
verbose = true
} else {
Expand All @@ -664,14 +672,17 @@ func (ts *TestScript) run() {
// Once we've reached the end of the script, ignore the status of background commands.
ts.waitBackground(false)

if !lastBlockFailed {
rewind()
}

// If we reached here but we've failed (probably because ContinueOnError
// was set), don't wipe the log and print "PASS".
if failed {
ts.t.FailNow()
}

// Final phase ended.
rewind()
markTime()
if !ts.stopped {
fmt.Fprintf(&ts.log, "PASS\n")
Expand Down