@@ -1204,32 +1204,38 @@ type tHelper interface {
1204
1204
func assertOpts (expected , actual interface {}) (expectedFmt , actualFmt string ) {
1205
1205
expectedOpts := reflect .ValueOf (expected )
1206
1206
actualOpts := reflect .ValueOf (actual )
1207
+
1208
+ var expectedFuncs []* runtime.Func
1207
1209
var expectedNames []string
1208
1210
for i := 0 ; i < expectedOpts .Len (); i ++ {
1209
- expectedNames = append (expectedNames , funcName (expectedOpts .Index (i ).Interface ()))
1211
+ f := runtimeFunc (expectedOpts .Index (i ).Interface ())
1212
+ expectedFuncs = append (expectedFuncs , f )
1213
+ expectedNames = append (expectedNames , funcName (f ))
1210
1214
}
1215
+ var actualFuncs []* runtime.Func
1211
1216
var actualNames []string
1212
1217
for i := 0 ; i < actualOpts .Len (); i ++ {
1213
- actualNames = append (actualNames , funcName (actualOpts .Index (i ).Interface ()))
1218
+ f := runtimeFunc (actualOpts .Index (i ).Interface ())
1219
+ actualFuncs = append (actualFuncs , f )
1220
+ actualNames = append (actualNames , funcName (f ))
1214
1221
}
1215
- if ! assert .ObjectsAreEqual (expectedNames , actualNames ) {
1222
+
1223
+ if expectedOpts .Len () != actualOpts .Len () {
1216
1224
expectedFmt = fmt .Sprintf ("%v" , expectedNames )
1217
1225
actualFmt = fmt .Sprintf ("%v" , actualNames )
1218
1226
return
1219
1227
}
1220
1228
1221
1229
for i := 0 ; i < expectedOpts .Len (); i ++ {
1222
- expectedOpt := expectedOpts .Index (i ).Interface ()
1223
- actualOpt := actualOpts .Index (i ).Interface ()
1224
-
1225
- expectedFunc := expectedNames [i ]
1226
- actualFunc := actualNames [i ]
1227
- if expectedFunc != actualFunc {
1228
- expectedFmt = expectedFunc
1229
- actualFmt = actualFunc
1230
+ if ! isFuncSame (expectedFuncs [i ], actualFuncs [i ]) {
1231
+ expectedFmt = expectedNames [i ]
1232
+ actualFmt = actualNames [i ]
1230
1233
return
1231
1234
}
1232
1235
1236
+ expectedOpt := expectedOpts .Index (i ).Interface ()
1237
+ actualOpt := actualOpts .Index (i ).Interface ()
1238
+
1233
1239
ot := reflect .TypeOf (expectedOpt )
1234
1240
var expectedValues []reflect.Value
1235
1241
var actualValues []reflect.Value
@@ -1247,9 +1253,9 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
1247
1253
reflect .ValueOf (actualOpt ).Call (actualValues )
1248
1254
1249
1255
for i := 0 ; i < ot .NumIn (); i ++ {
1250
- if ! assert . ObjectsAreEqual ( expectedValues [i ].Interface (), actualValues [i ].Interface ()) {
1251
- expectedFmt = fmt .Sprintf ("%s %+ v" , expectedNames [i ], expectedValues [ i ]. Interface () )
1252
- actualFmt = fmt .Sprintf ("%s %+ v" , expectedNames [i ], actualValues [ i ]. Interface () )
1256
+ if expectedArg , actualArg := expectedValues [i ].Interface (), actualValues [i ].Interface (); ! assert . ObjectsAreEqual ( expectedArg , actualArg ) {
1257
+ expectedFmt = fmt .Sprintf ("%s(%T) -> %# v" , expectedNames [i ], expectedArg , expectedArg )
1258
+ actualFmt = fmt .Sprintf ("%s(%T) -> %# v" , expectedNames [i ], actualArg , actualArg )
1253
1259
return
1254
1260
}
1255
1261
}
@@ -1258,7 +1264,25 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
1258
1264
return "" , ""
1259
1265
}
1260
1266
1261
- func funcName (opt interface {}) string {
1262
- n := runtime .FuncForPC (reflect .ValueOf (opt ).Pointer ()).Name ()
1263
- return strings .TrimSuffix (path .Base (n ), path .Ext (n ))
1267
+ func runtimeFunc (opt interface {}) * runtime.Func {
1268
+ return runtime .FuncForPC (reflect .ValueOf (opt ).Pointer ())
1269
+ }
1270
+
1271
+ func funcName (f * runtime.Func ) string {
1272
+ name := f .Name ()
1273
+ trimmed := strings .TrimSuffix (path .Base (name ), path .Ext (name ))
1274
+ splitted := strings .Split (trimmed , "." )
1275
+
1276
+ if len (splitted ) == 0 {
1277
+ return trimmed
1278
+ }
1279
+
1280
+ return splitted [len (splitted )- 1 ]
1281
+ }
1282
+
1283
+ func isFuncSame (f1 , f2 * runtime.Func ) bool {
1284
+ f1File , f1Loc := f1 .FileLine (f1 .Entry ())
1285
+ f2File , f2Loc := f2 .FileLine (f2 .Entry ())
1286
+
1287
+ return f1File == f2File && f1Loc == f2Loc
1264
1288
}
0 commit comments