Skip to content

Commit c5ef1b2

Browse files
committed
doc: update readme.
1 parent c4b112e commit c5ef1b2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ A collection of Golang assertion functions for verifying invariants.
1616
- [String](#string)
1717
- [Slice or Array](#slice-or-array)
1818
- [Error Handling](#error-handling)
19+
- [Custom Error Message](#custom-error-message)
1920
- [License](#license)
2021

2122
## Installation
@@ -204,6 +205,25 @@ func TestExample(t *testing.T) {
204205

205206
> Since v0.1.0
206207
208+
## Custom Error Message
209+
210+
You can customize the error message if you don't like the default message. Every assertion function accepts an optional message arguments list, and the first argument is the argument is the format string of the custom message.
211+
212+
```go
213+
actual := 1
214+
expect := 2
215+
assert.Equal(actual, expect)
216+
// assert error: 1 != 2
217+
218+
assert.Equal(actual, expect, "unexpected result")
219+
// unexpected result
220+
221+
assert.Equal(actual, expect, "actual = %v, expect = %v", actual, expect)
222+
// actual = 1, expect = 2
223+
```
224+
225+
For custom error messages, the first argument of messages must be the format string, it'll fall back to the default error message if not a string.
226+
207227
## License
208228

209229
This project was published under the MIT license, you can see [LICENSE](./LICENSE) file to get more information.

doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package assert implements assertion functions for verifying invariants to extend the built-in
2+
// testing package.
3+
package assert

0 commit comments

Comments
 (0)