Skip to content

Commit 8300480

Browse files
authored
cmd/testscript: remove redundant use of Failed (rogpeppe#257)
The call to `T.Failed` and its associated comment are a legacy of previous implementation. The comment isn't accurate and the call isn't necessary (`FailNow` is always called even when `ContinueOnError` is set). Deprecate the associated `TFailed` type rather than removing it.
1 parent ee2fcaa commit 8300480

File tree

3 files changed

+1
-19
lines changed

3 files changed

+1
-19
lines changed

cmd/testscript/main.go

-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"os/exec"
1414
"path/filepath"
1515
"strings"
16-
"sync/atomic"
1716

1817
"github.com/rogpeppe/go-internal/goproxytest"
1918
"github.com/rogpeppe/go-internal/gotooltest"
@@ -293,12 +292,6 @@ func (tr *testRunner) run(runDir, filename string) error {
293292
}
294293
}()
295294
testscript.RunT(r, p)
296-
297-
// When continueOnError is true, FailNow does not call panic(failedRun).
298-
// We still want err to be set, as the script resulted in a failure.
299-
if r.Failed() {
300-
err = failedRun
301-
}
302295
}()
303296

304297
if err != nil {
@@ -348,7 +341,6 @@ func renderFilename(filename string) string {
348341
// runT implements testscript.T and is used in the call to testscript.Run
349342
type runT struct {
350343
verbose bool
351-
failed int32
352344
}
353345

354346
func (r *runT) Skip(is ...interface{}) {
@@ -370,14 +362,9 @@ func (r *runT) Log(is ...interface{}) {
370362
}
371363

372364
func (r *runT) FailNow() {
373-
atomic.StoreInt32(&r.failed, 1)
374365
panic(failedRun)
375366
}
376367

377-
func (r *runT) Failed() bool {
378-
return atomic.LoadInt32(&r.failed) != 0
379-
}
380-
381368
func (r *runT) Run(n string, f func(t testscript.T)) {
382369
// For now we we don't top/tail the run of a subtest. We are currently only
383370
// running a single script in a testscript instance, which means that we

testscript/testscript.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ type T interface {
219219
Verbose() bool
220220
}
221221

222-
// TFailed holds optional extra methods implemented on T.
223-
// It's defined as a separate type for backward compatibility reasons.
222+
// Deprecated: this type is unused.
224223
type TFailed interface {
225224
Failed() bool
226225
}

testscript/testscript_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,3 @@ func (t *fakeT) Run(name string, f func(T)) {
508508
func (t *fakeT) Verbose() bool {
509509
return t.verbose
510510
}
511-
512-
func (t *fakeT) Failed() bool {
513-
return t.failed
514-
}

0 commit comments

Comments
 (0)