diff options
author | sudoforge <no-reply@sudoforge.com> | 2025-05-08 02:43:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-08 02:43:53 -0700 |
commit | 1766f85bf9edba2cccff494a0a41bb30e244a01b (patch) | |
tree | 163bc0258aa954a8198ad7f3825d22b5b21ed122 /internal/test/recorder.go | |
parent | f6e7fb524e3e157f04a5fe90066e55bf1dc692ec (diff) | |
download | git-bug-1766f85bf9edba2cccff494a0a41bb30e244a01b.tar.gz git-bug-1766f85bf9edba2cccff494a0a41bb30e244a01b.zip |
test: implement support for Failed() and FailedNow() (#1399)
This change adds support to //internal/test for Failed() and
FailedNow(), and expands the support for setting and detecting the
failed status on //internal/test%recorder.
Change-Id: I04e7a978cbf0ead8d28722c0a3a0fc34136e72e1
Diffstat (limited to 'internal/test/recorder.go')
-rw-r--r-- | internal/test/recorder.go | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/internal/test/recorder.go b/internal/test/recorder.go index 35ddb0d01..7d9f4a5f2 100644 --- a/internal/test/recorder.go +++ b/internal/test/recorder.go @@ -5,24 +5,46 @@ import ( "testing" ) +const ( + RecorderFailNow int = iota +) + type recorder struct { testing.TB - fail func(string) - fatal func(string) + fail func(string) + fatal func(string) + failed bool +} + +func (r *recorder) Error(args ...any) { + r.failed = true + r.fail(fmt.Sprint(args...)) } func (r *recorder) Errorf(format string, args ...any) { + r.failed = true r.fail(fmt.Sprintf(format, args...)) } -func (r *recorder) Fatalf(format string, args ...any) { - r.fatal(fmt.Sprintf(format, args...)) +func (r *recorder) Fail() { + r.failed = true +} + +func (r *recorder) FailNow() { + r.failed = true + panic(RecorderFailNow) +} + +func (r *recorder) Failed() bool { + return r.failed } func (r *recorder) Fatal(args ...any) { + r.failed = true r.fatal(fmt.Sprint(args...)) } -func (r *recorder) Error(args ...any) { - r.fail(fmt.Sprint(args...)) +func (r *recorder) Fatalf(format string, args ...any) { + r.failed = true + r.fatal(fmt.Sprintf(format, args...)) } |