Skip to content

Commit c432749

Browse files
committed
assert pkg documentation for asserters
1 parent 049027f commit c432749

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

assert/assert.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,45 @@ import (
1616
type defInd = uint32
1717

1818
const (
19-
// Production is the best asserter for most uses. The assertion violations
20-
// are treated as Go error values. And only a pragmatic caller info is
21-
// automatically included into the error message like file name, line
22-
// number, and caller function.
19+
// Production (pkg default) is the best asserter for most uses. The
20+
// assertion violations are treated as Go error values. And only a
21+
// pragmatic caller info is automatically included into the error message
22+
// like file name, line number, and caller function, all in one line:
23+
//
24+
// copy file: main.go:37: CopyFile(): assertion violation: string shouldn't be empty
2325
Production defInd = 0 + iota
2426

2527
// Development is the best asserter for most development uses. The
2628
// assertion violations are treated as Go error values. And a formatted
2729
// caller info is automatically included to the error message like file
28-
// name, line number, and caller function.
30+
// name, line number, and caller function. Everything in a beautiful
31+
// multi-line message:
32+
//
33+
// --------------------------------
34+
// Assertion Fault at:
35+
// main.go:37 CopyFile():
36+
// assertion violation: string shouldn't be empty
37+
// --------------------------------
2938
Development
3039

3140
// Test minimalistic asserter for unit test use. More pragmatic is the
32-
// TestFull asserter (default).
41+
// TestFull asserter (test default).
3342
//
34-
// Use this asserter if your IDE/editor doesn't support long file names, or
35-
// for temporary problem solving for your programming environment.
43+
// Use this asserter if your IDE/editor doesn't support full file names and
44+
// it relies a relative path (Go standard). You can use this also if you
45+
// need temporary problem solving for your programming environment.
3646
Test
3747

38-
// TestFull asserter (default). The TestFull asserter includes caller info
39-
// and call stack for unit testing, similarly like err2's error traces.
48+
// TestFull asserter (test default). The TestFull asserter includes the
49+
// caller info and the call stack for unit testing, similarly like err2's
50+
// error traces.
4051
//
4152
// The call stack produced by the test asserts can be used over Go module
4253
// boundaries. For example, if your app and it's sub packages both use
4354
// err2/assert for unit testing and runtime checks, the runtime assertions
44-
// will be automatically converted to test asserts on the fly. If any of
45-
// the runtime asserts in sub packages fails during the app tests, the
46-
// current app test fails too.
55+
// will be automatically converted to test asserts. If any of the runtime
56+
// asserts of the sub packages fails during the app tests, the app test
57+
// fails as well.
4758
//
4859
// Note, that the cross-module assertions produce long file names (path
4960
// included), and some of the Go test result parsers cannot handle that.
@@ -53,7 +64,7 @@ const (
5364
TestFull
5465

5566
// Debug asserter transforms assertion violations to panics which is the
56-
// patter that e.g. Go's standard library uses:
67+
// pattern that e.g. Go's standard library uses:
5768
//
5869
// if p == nil {
5970
// panic("pkg: ptr cannot be nil")

0 commit comments

Comments
 (0)