Skip to content

Commit 8aec034

Browse files
committed
Convenience method for performing assertions via should package.
1 parent 682befc commit 8aec034

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

should/should.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ var (
6969
StartWith = assertions.ShouldStartWith
7070
Wrap = assertions.ShouldWrap
7171
)
72+
73+
// So is a variation on other such functions/methods in this module.
74+
// Since it is defined alongside all these assertion definitions it allows
75+
// performing assertions in tests with a single import of this package.
76+
// Example:
77+
// should.So(t, 1, should.Equal, 1)
78+
func So(t testingT, actual any, assertion assertions.SoFunc, expected ...any) {
79+
if ok, result := assertions.So(actual, assertion, expected...); !ok {
80+
t.Helper()
81+
t.Errorf("\n%s", result)
82+
}
83+
}
84+
85+
type testingT interface {
86+
Helper()
87+
Errorf(string, ...any)
88+
}

0 commit comments

Comments
 (0)