-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathtest.go
More file actions
45 lines (40 loc) · 1.62 KB
/
test.go
File metadata and controls
45 lines (40 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// package ct contains wrappers and interfaces around testing.T
//
// The intention is that _all_ complement functions deal with these wrapper interfaces
// rather than the literal testing.T. This enables Complement to be run in environments
// that aren't strictly via `go test`.
package ct
// TestLike is an interface that testing.T satisfies. All client functions accept a TestLike interface,
// with the intention of a `testing.T` being passed into them. However, the client may be used in non-test
// scenarios e.g benchmarks, which can then use the same client by just implementing this interface.
type TestLike interface {
Helper()
Logf(msg string, args ...interface{})
Skipf(msg string, args ...interface{})
Error(args ...interface{})
Errorf(msg string, args ...interface{})
Fatal(msg string)
Fatalf(msg string, args ...interface{})
Failed() bool
Name() string
}
const ansiRedForeground = "\x1b[31m"
const ansiResetForeground = "\x1b[39m"
// Errorf is a wrapper around t.Errorf which prints the failing error message in red.
func Errorf(t TestLike, format string, args ...any) {
t.Helper()
format = ansiRedForeground + format + ansiResetForeground
t.Errorf(format, args...)
}
// Fatal is a wrapper around t.Fatal which prints the failing error message in red.
func Fatal(t TestLike, format string) {
t.Helper()
format = ansiRedForeground + format + ansiResetForeground
t.Fatal(format)
}
// Fatalf is a wrapper around t.Fatalf which prints the failing error message in red.
func Fatalf(t TestLike, format string, args ...any) {
t.Helper()
format = ansiRedForeground + format + ansiResetForeground
t.Fatalf(format, args...)
}