Skip to content

Commit

Permalink
Merge pull request #233 from dnephin/improve-godoc
Browse files Browse the repository at this point in the history
assert: document that filename and line number are included
  • Loading branch information
dnephin authored Apr 16, 2022
2 parents dbe78a8 + 5666354 commit fac3030
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ values in tests. When an assertion fails a helpful error message is printed.
Example usage
All the assertions in this package use testing.T.Helper to mark themselves as
test helpers. This allows the testing package to print the filename and line
number of the file function that failed.
assert.NilError(t, err)
// filename_test.go:212: assertion failed: error is not nil: file not found
If any assertion is called from a helper function, make sure to call t.Helper
from the helper function so that the filename and line number remain correct.
The examples below show assert used with some common types and the failure
messages it produces.
messages it produces. The filename and line number portion of the failure
message is omitted from these examples for brevity.
// booleans
Expand Down Expand Up @@ -171,7 +182,7 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
// values.
//
// assert.Equal(t, actual, expected)
// // assertion failed: 1 (actual int) != 21 (expected int32)
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
//
// If either x or y are a multi-line string the failure message will include a
// unified diff of the two values. If the values only differ by whitespace
Expand Down

0 comments on commit fac3030

Please sign in to comment.