@@ -2,11 +2,10 @@ package assert
22
33import (
44 "testing"
5- "time"
65)
76
87type Assertion struct {
9- t * testing.T
8+ * testing.T
109}
1110
1211// New returns an assertion instance for verifying invariants.
@@ -16,154 +15,7 @@ func New(t *testing.T) *Assertion {
1615 if t == nil {
1716 panic ("parameter t is required" )
1817 }
19- a .t = t
18+ a .T = t
2019
2120 return a
2221}
23-
24- // ##########################
25- // ## Delegation Functions ##
26- // ##########################
27-
28- // Cleanup registers a function to be called when the test (or subtest) and all its subtests
29- // complete. Cleanup functions will be called in last added, first called order.
30- func (a * Assertion ) Cleanup (f func ()) {
31- a .t .Cleanup (f )
32- }
33-
34- // Deadline reports the time at which the test binary will have exceeded the timeout specified by
35- // the -timeout flag.
36- //
37- // The ok result is false if the -timeout flag indicates “no timeout” (0).
38- func (a * Assertion ) Deadline () (deadline time.Time , ok bool ) {
39- return a .t .Deadline ()
40- }
41-
42- // Error is equivalent to Log followed by Fail.
43- func (a * Assertion ) Error (args ... any ) {
44- a .t .Error (args ... )
45- }
46-
47- // Errorf is equivalent to Logf followed by Fail.
48- func (a * Assertion ) Errorf (format string , args ... any ) {
49- a .t .Errorf (format , args ... )
50- }
51-
52- // Fail marks the function as having failed but continues execution.
53- func (a * Assertion ) Fail () {
54- a .t .Fail ()
55- }
56-
57- // FailNow marks the function as having failed and stops its execution by calling runtime.Goexit
58- // (which then runs all deferred calls in the current goroutine). Execution will continue at the
59- // next test or benchmark. FailNow must be called from the goroutine running the test or benchmark
60- // function, not from other goroutines created during the test. Calling FailNow does not stop
61- // those other goroutines.
62- func (a * Assertion ) FailNow () {
63- a .t .FailNow ()
64- }
65-
66- // Failed reports whether the function has failed.
67- func (a * Assertion ) Failed () bool {
68- return a .t .Failed ()
69- }
70-
71- // Fatal is equivalent to Log followed by FailNow.
72- func (a * Assertion ) Fatal (args ... any ) {
73- a .t .Fatal (args ... )
74- }
75-
76- // Fatalf is equivalent to Logf followed by FailNow.
77- func (a * Assertion ) Fatalf (format string , args ... any ) {
78- a .t .Fatalf (format , args ... )
79- }
80-
81- // Helper marks the calling function as a test helper function. When printing file and line
82- // information, that function will be skipped. Helper may be called simultaneously from multiple
83- // goroutines.
84- func (a * Assertion ) Helper () {
85- a .t .Helper ()
86- }
87-
88- // Log formats its arguments using default formatting, analogous to Println, and records the text
89- // in the error log. For tests, the text will be printed only if the test fails or the -test.v
90- // flag is set. For benchmarks, the text is always printed to avoid having performance depend on
91- // the value of the -test.v flag.
92- func (a * Assertion ) Log (args ... any ) {
93- a .t .Log (args ... )
94- }
95-
96- // Logf formats its arguments according to the format, analogous to Printf, and records the text in
97- // the error log. A final newline is added if not provided. For tests, the text will be printed
98- // only if the test fails or the -test.v flag is set. For benchmarks, the text is always printed to
99- // avoid having performance depend on the value of the -test.v flag.
100- func (a * Assertion ) Logf (format string , args ... any ) {
101- a .t .Logf (format , args ... )
102- }
103-
104- // Name returns the name of the running (sub-) test or benchmark.
105- //
106- // The name will include the name of the test along with the names of any nested sub-tests. If two
107- // sibling sub-tests have the same name, Name will append a suffix to guarantee the returned name
108- // is unique.
109- func (a * Assertion ) Name () string {
110- return a .t .Name ()
111- }
112-
113- // Parallel signals that this test is to be run in parallel with (and only with) other parallel
114- // tests. When a test is run multiple times due to use of -test.count or -test.cpu, multiple
115- // instances of a single test never run in parallel with each other.
116- func (a * Assertion ) Parallel () {
117- a .t .Parallel ()
118- }
119-
120- // Run runs f as a subtest of t called name. It runs f in a separate goroutine and blocks until f
121- // returns or calls t.Parallel to become a parallel test. Run reports whether f succeeded (or at
122- // least did not fail before calling t.Parallel).
123- //
124- // Run may be called simultaneously from multiple goroutines, but all such calls must return before
125- // the outer test function for t returns.
126- func (a * Assertion ) Run (name string , f func (* testing.T )) bool {
127- return a .t .Run (name , f )
128- }
129-
130- // Setenv calls os.Setenv(key, value) and uses Cleanup to restore the environment variable to its
131- // original value after the test.
132- //
133- // Because Setenv affects the whole process, it cannot be used in parallel tests or tests with
134- // parallel ancestors.
135- func (a * Assertion ) Setenv (key , value string ) {
136- a .t .Setenv (key , value )
137- }
138-
139- // Skip is equivalent to Log followed by SkipNow.
140- func (a * Assertion ) Skip (args ... any ) {
141- a .t .Skip (args ... )
142- }
143-
144- // SkipNow marks the test as having been skipped and stops its execution by calling runtime.Goexit.
145- // If a test fails (see Error, Errorf, Fail) and is then skipped, it is still considered to have
146- // failed. Execution will continue at the next test or benchmark. See also FailNow. SkipNow must be
147- // called from the goroutine running the test, not from other goroutines created during the test.
148- // Calling SkipNow does not stop those other goroutines.
149- func (a * Assertion ) SkipNow () {
150- a .t .SkipNow ()
151- }
152-
153- // Skipf is equivalent to Logf followed by SkipNow.
154- func (a * Assertion ) Skipf (format string , args ... any ) {
155- a .t .Skipf (format , args ... )
156- }
157-
158- // Skipped reports whether the test was skipped.
159- func (a * Assertion ) Skipped () bool {
160- return a .t .Skipped ()
161- }
162-
163- // TempDir returns a temporary directory for the test to use. The directory is automatically
164- // removed by Cleanup when the test and all its subtests complete. Each subsequent call to
165- // t.TempDir returns a unique directory; if the directory creation fails, TempDir terminates the
166- // test by calling Fatal.
167- func (a * Assertion ) TempDir () string {
168- return a .t .TempDir ()
169- }
0 commit comments