Skip to content

Commit dfe3157

Browse files
committed
fix SetDefault docs
1 parent e3fa9c2 commit dfe3157

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

assert/assert.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,24 +1021,17 @@ func current() (curAsserter asserter) {
10211021
return curAsserter
10221022
}
10231023

1024-
// SetDefault sets the current default [Asserter] for assert pkg. It also
1025-
// returns the previous [Asserter].
1024+
// SetDefault sets the new default [Asserter] for the assert pkg instance you're
1025+
// currently using. It also returns the previous [Asserter]. The default
1026+
// asserter is [Production] that's best for most use cases and packages.
10261027
//
1027-
// Note that you should use this in TestMain function, and use [flag] package to
1028-
// set it for the app. For the tests you can set it to panic about every
1029-
// assertion fault, or to throw an error, or/and print the call stack
1030-
// immediately when assert occurs. The err2 package helps you to catch and
1031-
// report all types of the asserts.
1028+
// Note that for most cases [PushAsserter] is most suitable. [PushAsserter]
1029+
// allows you to set [Asserter] per goroutine or function, i.e., until you pop
1030+
// the asserter out, and the assert package uses the current default [Asserter]
1031+
// set by [SetDefault].
10321032
//
1033-
// Note that if you are using tracers you might get two call stacks, so test
1034-
// what's best for your case.
1035-
//
1036-
// Tip. If our own packages (client packages for assert) have lots of parallel
1037-
// testing and race detection, please try to use same [Asserter] for all of them
1038-
// and set [Asserter] only one in TestMain, or in init.
1039-
//
1040-
// func TestMain(m *testing.M) {
1041-
// SetDefault(assert.TestFull)
1033+
// Note that if you are using tracers you might get overlapping call stacks, so
1034+
// test what's best for your case.
10421035
func SetDefault(i Asserter) (old Asserter) {
10431036
// pkg lvl lock to allow only one pkg client call this at one of the time
10441037
// together with the indexing, i.e we don't need to switch asserter

0 commit comments

Comments
 (0)