Skip to content

Commit a9218f2

Browse files
committed
Note that without comma, and updated docs
1 parent 08a533d commit a9218f2

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

assert/assert.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type defInd = uint32
2525
//
2626
// assert.NotEmpty(c.PoolName, "pool name cannot be empty")
2727
//
28-
// Note, that Plain is only asserter that override auto-generated assertion
28+
// Note that Plain is only asserter that override auto-generated assertion
2929
// messages with given arguments like 'pool name cannot be empty'. Others add
3030
// given arguments at the end of the auto-generated assert message.
3131
//
@@ -56,15 +56,15 @@ type defInd = uint32
5656
//
5757
// [TestFull] asserter (test default). The TestFull asserter includes the caller
5858
// 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.
6060
//
6161
// The call stack produced by the test asserts can be used over Go module
6262
// boundaries. For example, if your app and it's sub packages both use
6363
// err2/assert for unit testing and runtime checks, the runtime assertions will
6464
// be automatically converted to test asserts. If any of the runtime asserts of
6565
// the sub packages fails during the app tests, the app test fails as well.
6666
//
67-
// Note, that the cross-module assertions produce long file names (path
67+
// Note that the cross-module assertions produce long file names (path
6868
// included), and some of the Go test result parsers cannot handle that. A
6969
// proper test result parser like [nvim-go] (fork) works very well. Also most of
7070
// the make result parsers can process the output properly and allow traverse of
@@ -179,7 +179,7 @@ const (
179179
// PushTester allows you to change the current default asserter by accepting it
180180
// as a second argument.
181181
//
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
183183
// whole package. The argument is mainly for temporary development use and isn't
184184
// not preferred API usage.
185185
func PushTester(t testing.TB, a ...defInd) function {
@@ -241,15 +241,15 @@ func PopTester() {
241241
msg = "test panic catch"
242242
}
243243

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
245245
// tracing with unit test logging. However, using it has proved the top
246246
// level error stack as more enough. Even so that we could consider using
247247
// it for normal error stack traces if it would be possible.
248248
const stackLvl = 6 // amount of functions before we're here
249249
debug.PrintStackForTest(os.Stderr, stackLvl)
250250

251251
// 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
253253
// are here in the 'catch-function'.
254254
const framesToSkip = 4 // how many fn calls there is before FuncName call
255255
fatal("assertion catching: "+msg, framesToSkip)
@@ -837,15 +837,16 @@ func current() asserter {
837837
return defAsserter[def]
838838
}
839839

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.
841842
//
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
843844
// set it for the app. For the tests you can set it to panic about every
844845
// assertion fault, or to throw an error, or/and print the call stack
845846
// immediately when assert occurs. The err2 package helps you to catch and
846847
// report all types of the asserts.
847848
//
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
849850
// what's best for your case.
850851
//
851852
// Tip. If our own packages (client packages for assert) have lots of parallel
@@ -854,15 +855,21 @@ func current() asserter {
854855
//
855856
// func TestMain(m *testing.M) {
856857
// 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.
859863
mu.Lock()
860864
defer mu.Unlock()
861865

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,
864871
def = i
865-
return def
872+
return
866873
}
867874

868875
// mapDefInd runtime asserters, that's why test asserts are removed for now.

err2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ func Handle(err *error, a ...any) {
114114
}
115115

116116
// Catch is a convenient helper to those functions that doesn't return errors.
117-
// Note, that Catch always catch the panics. If you don't want to stop them
117+
// Note that Catch always catch the panics. If you don't want to stop them
118118
// (i.e., use of [recover]) you should add panic handler and continue panicking
119119
// there. There can be only one deferred Catch function per non error returning
120-
// function like main(). There is several ways to use the Catch function. And
121-
// always remember the [defer].
120+
// functions, i.e. goroutine functions like main(). There is several ways to use
121+
// the Catch function. And always remember the [defer].
122122
//
123123
// The deferred Catch is very convenient, because it makes your current
124124
// goroutine panic and error-safe. You can fine tune its 'global' behavior with

internal/str/str.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var (
1515
clean = regexp.MustCompile(`[^\w]`)
1616
)
1717

18-
// DecamelRegexp return the given string as space delimeted. Note! it's slow. Use
19-
// Decamel instead.
18+
// DecamelRegexp return the given string as space delimeted. Note! It's slow.
19+
// Use [Decamel] instead. It's left here for learning purposes.
2020
func DecamelRegexp(str string) string {
2121
str = clean.ReplaceAllString(str, " ")
2222
str = uncamel.ReplaceAllString(str, ` $1`)
@@ -78,7 +78,7 @@ func Decamel(s string) string {
7878
// separated filename, and line number. If frame cannot be found ok is false.
7979
//
8080
// See more information from runtime.Caller. The skip tells how many stack
81-
// frames are skipped. Note, that FuncName calculates itself to skip frames.
81+
// frames are skipped. Note that FuncName calculates itself the skip frames.
8282
func FuncName(skip int, long bool) (n, fname string, ln int, ok bool) {
8383
pc, file, ln, yes := runtime.Caller(skip + 1) // +1 skip ourself
8484
if yes {

0 commit comments

Comments
 (0)