https://github.com/thehungry-dev/asserting
Output verification library for asserting in go test
https://github.com/thehungry-dev/asserting
assert assertions go golang testing
Last synced: 29 days ago
JSON representation
Output verification library for asserting in go test
- Host: GitHub
- URL: https://github.com/thehungry-dev/asserting
- Owner: thehungry-dev
- License: mit
- Created: 2020-07-19T00:47:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-19T03:47:57.000Z (over 5 years ago)
- Last Synced: 2023-12-19T10:59:37.710Z (about 2 years ago)
- Topics: assert, assertions, go, golang, testing
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Asserting
Output verification library for asserting in `go test`
## Usage
```go
package my_test
import (
"testing"
. "github.com/Fire-Dragon-DoL/lab/asserting"
)
func TestAssert(t *testing.T) {
Assert(t, 1 == 1) // Test is successful
}
func TestAssertPanic(t *testing.T) {
Assert.Panic(t, func() {
panic("A panic")
}) // Test is successful
}
func TestAssertPanicMsg(t *testing.T) {
panicFn := func() { panic("A panic") }
Assert.Panic(t, panicFn, func(msg interface{}) bool {
prose, ok := msg.(string)
return ok && prose == "A panic"
}) // Test is successful
}
func TestAssertDifferentPanicMsg(t *testing.T) {
panicFn := func() { panic("A panic") }
Assert.Panic(t, panicFn, func(msg interface{}) bool {
prose, ok := msg.(string)
return ok && prose == "Other panic"
}) // Test fails
}
```