@@ -25,7 +25,7 @@ type defInd = uint32
25
25
//
26
26
// assert.NotEmpty(c.PoolName, "pool name cannot be empty")
27
27
//
28
- // Note, that Plain is only asserter that override auto-generated assertion
28
+ // Note that Plain is only asserter that override auto-generated assertion
29
29
// messages with given arguments like 'pool name cannot be empty'. Others add
30
30
// given arguments at the end of the auto-generated assert message.
31
31
//
@@ -56,15 +56,15 @@ type defInd = uint32
56
56
//
57
57
// [TestFull] asserter (test default). The TestFull asserter includes the caller
58
58
// info and the call stack for unit testing, similarly like err2's error traces.
59
- // Note, that [PushTester] set's TestFull if it's not yet set.
59
+ // Note that [PushTester] set's TestFull if it's not yet set.
60
60
//
61
61
// The call stack produced by the test asserts can be used over Go module
62
62
// boundaries. For example, if your app and it's sub packages both use
63
63
// err2/assert for unit testing and runtime checks, the runtime assertions will
64
64
// be automatically converted to test asserts. If any of the runtime asserts of
65
65
// the sub packages fails during the app tests, the app test fails as well.
66
66
//
67
- // Note, that the cross-module assertions produce long file names (path
67
+ // Note that the cross-module assertions produce long file names (path
68
68
// included), and some of the Go test result parsers cannot handle that. A
69
69
// proper test result parser like [nvim-go] (fork) works very well. Also most of
70
70
// the make result parsers can process the output properly and allow traverse of
@@ -179,7 +179,7 @@ const (
179
179
// PushTester allows you to change the current default asserter by accepting it
180
180
// as a second argument.
181
181
//
182
- // Note, that the second argument, if given, changes the default asserter for
182
+ // Note that the second argument, if given, changes the default asserter for
183
183
// whole package. The argument is mainly for temporary development use and isn't
184
184
// not preferred API usage.
185
185
func PushTester (t testing.TB , a ... defInd ) function {
@@ -241,15 +241,15 @@ func PopTester() {
241
241
msg = "test panic catch"
242
242
}
243
243
244
- // First, print the call stack. Note, that we aren't support full error
244
+ // First, print the call stack. Note that we aren't support full error
245
245
// tracing with unit test logging. However, using it has proved the top
246
246
// level error stack as more enough. Even so that we could consider using
247
247
// it for normal error stack traces if it would be possible.
248
248
const stackLvl = 6 // amount of functions before we're here
249
249
debug .PrintStackForTest (os .Stderr , stackLvl )
250
250
251
251
// Now that call stack errors are printed, if any. Let's print the actual
252
- // line that caused the error, i.e., was throwing the error. Note, that we
252
+ // line that caused the error, i.e., was throwing the error. Note that we
253
253
// are here in the 'catch-function'.
254
254
const framesToSkip = 4 // how many fn calls there is before FuncName call
255
255
fatal ("assertion catching: " + msg , framesToSkip )
@@ -837,15 +837,16 @@ func current() asserter {
837
837
return defAsserter [def ]
838
838
}
839
839
840
- // SetDefault set the current default asserter for assert pkg.
840
+ // SetDefault sets the current default asserter for assert pkg. It also returns
841
+ // the previous asserter.
841
842
//
842
- // Note, that you should use this in TestMain function, and use Flag package to
843
+ // Note that you should use this in TestMain function, and use [flag] package to
843
844
// set it for the app. For the tests you can set it to panic about every
844
845
// assertion fault, or to throw an error, or/and print the call stack
845
846
// immediately when assert occurs. The err2 package helps you to catch and
846
847
// report all types of the asserts.
847
848
//
848
- // Note, that if you are using tracers you might get two call stacks, so test
849
+ // Note that if you are using tracers you might get two call stacks, so test
849
850
// what's best for your case.
850
851
//
851
852
// Tip. If our own packages (client packages for assert) have lots of parallel
@@ -854,15 +855,21 @@ func current() asserter {
854
855
//
855
856
// func TestMain(m *testing.M) {
856
857
// SetDefault(assert.TestFull)
857
- func SetDefault (i defInd ) defInd {
858
- // pkg lvl lock to allow only one pkg client call this at the time
858
+ func SetDefault (i defInd ) (old defInd ) {
859
+ // pkg lvl lock to allow only one pkg client call this at one of the time
860
+ // together with the indexing, i.e we don't need to switch asserter
861
+ // variable or pointer to it but just index to array they are stored.
862
+ // All of this make race detector happy at the client pkgs.
859
863
mu .Lock ()
860
864
defer mu .Unlock ()
861
865
862
- // to make this fully thread safe the def var should be atomic, BUT it
863
- // would be owerkill. We need only defaults to be set at once.
866
+ old = def
867
+ // theoretically, to make this fully thread safe the def var should be
868
+ // atomic, BUT it would be overkill. We need only defaults to be set at
869
+ // once. AND because we use indexing to actual asserter the thread-safety
870
+ // and performance are guaranteed,
864
871
def = i
865
- return def
872
+ return
866
873
}
867
874
868
875
// mapDefInd runtime asserters, that's why test asserts are removed for now.
0 commit comments