Skip to content

Commit fac3030

Browse files
authored
Merge pull request #233 from dnephin/improve-godoc
assert: document that filename and line number are included
2 parents dbe78a8 + 5666354 commit fac3030

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

assert/assert.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ values in tests. When an assertion fails a helpful error message is printed.
33
44
Example usage
55
6+
All the assertions in this package use testing.T.Helper to mark themselves as
7+
test helpers. This allows the testing package to print the filename and line
8+
number of the file function that failed.
9+
10+
assert.NilError(t, err)
11+
// filename_test.go:212: assertion failed: error is not nil: file not found
12+
13+
If any assertion is called from a helper function, make sure to call t.Helper
14+
from the helper function so that the filename and line number remain correct.
15+
616
The examples below show assert used with some common types and the failure
7-
messages it produces.
17+
messages it produces. The filename and line number portion of the failure
18+
message is omitted from these examples for brevity.
819
920
// booleans
1021
@@ -171,7 +182,7 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
171182
// values.
172183
//
173184
// assert.Equal(t, actual, expected)
174-
// // assertion failed: 1 (actual int) != 21 (expected int32)
185+
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
175186
//
176187
// If either x or y are a multi-line string the failure message will include a
177188
// unified diff of the two values. If the values only differ by whitespace

0 commit comments

Comments
 (0)