@@ -7,6 +7,7 @@ package utils
7
7
import (
8
8
"bytes"
9
9
"fmt"
10
+ "log"
10
11
"os"
11
12
"path/filepath"
12
13
"reflect"
@@ -139,11 +140,16 @@ func AssertEqual(t testing.TB, a interface{}, b interface{}, description ...stri
139
140
bType = reflect .TypeOf (b ).Name ()
140
141
}
141
142
143
+ testName := "AssertEqual"
144
+ if t != nil {
145
+ testName = t .Name ()
146
+ }
147
+
142
148
_ , file , line , _ := runtime .Caller (1 )
143
149
144
150
var buf bytes.Buffer
145
151
w := tabwriter .NewWriter (& buf , 0 , 0 , 5 , ' ' , 0 )
146
- fmt .Fprintf (w , "\n Test:\t %s" , t . Name () )
152
+ fmt .Fprintf (w , "\n Test:\t %s" , testName )
147
153
fmt .Fprintf (w , "\n Trace:\t %s:%d" , filepath .Base (file ), line )
148
154
fmt .Fprintf (w , "\n Error:\t Not equal" )
149
155
fmt .Fprintf (w , "\n Expect:\t %v\t [%s]" , a , aType )
@@ -153,11 +159,16 @@ func AssertEqual(t testing.TB, a interface{}, b interface{}, description ...stri
153
159
fmt .Fprintf (w , "\n Description:\t %s" , description [0 ])
154
160
}
155
161
156
- err := w .Flush ()
157
- if err != nil {
158
- t .Fatal (err )
162
+ result := ""
163
+ if err := w .Flush (); err != nil {
164
+ result = err .Error ()
165
+ } else {
166
+ result = buf .String ()
167
+ }
168
+ if t != nil {
169
+ t .Fatal (result )
159
170
} else {
160
- t .Fatal (buf . String () )
171
+ log .Fatal (result )
161
172
}
162
173
}
163
174
0 commit comments