1package test
2
3import (
4 "fmt"
5 "testing"
6)
7
8const (
9 RecorderFailNow int = iota
10)
11
12type recorder struct {
13 testing.TB
14 fail func(string)
15 fatal func(string)
16 failed bool
17}
18
19func (r *recorder) Error(args ...any) {
20 r.failed = true
21 r.fail(fmt.Sprint(args...))
22}
23
24func (r *recorder) Errorf(format string, args ...any) {
25 r.failed = true
26 r.fail(fmt.Sprintf(format, args...))
27}
28
29func (r *recorder) Fail() {
30 r.failed = true
31}
32
33func (r *recorder) FailNow() {
34 r.failed = true
35 panic(RecorderFailNow)
36}
37
38func (r *recorder) Failed() bool {
39 return r.failed
40}
41
42func (r *recorder) Fatal(args ...any) {
43 r.failed = true
44 r.fatal(fmt.Sprint(args...))
45}
46
47func (r *recorder) Fatalf(format string, args ...any) {
48 r.failed = true
49 r.fatal(fmt.Sprintf(format, args...))
50}