cat ./no_panic/example_test.gopackage example
import (
"testing"
"github.com/dancsecs/sztest"
)
// Passing test.
func Test_PASS_NoPanic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.Panic(
func() {
// Exit function without panicking.
},
"", // Permits a NoPanic wnt to be calculated by the test.
)
}
// Failing test.
func Test_FAIL_NoPanic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.Panic(
func() {
panic("this is the panic generated")
},
// Expecting no panic to be thrown
"",
)
}go test -v -cover ./no_panic
cat ./no_panic_helper/example_test.gopackage example
import (
"testing"
"github.com/dancsecs/sztest"
)
// Passing test.
func Test_PASS_NoPanicHelper(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.NoPanic(
func() {
// Exit function without panicking.
},
)
}
// Failing test.
func Test_FAIL_NoPanicHelper(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.NoPanic(
func() {
panic("panic message") // Unexpected Panic
},
)
}go test -v -cover ./no_panic_helper
cat ./panic/example_test.gopackage example
import (
"testing"
"github.com/dancsecs/sztest"
)
// Passing test.
func Test_PASS_Panic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.Panic(
func() {
panic("expected panic message")
},
"expected panic message",
)
}
// Failing test.
func Test_FAIL_Panic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
// Failure. The invoked function's panic message
// is not what is expected.
chk.Panic(
func() {
panic("this is the panic generated")
},
"this is the panic wanted",
)
}go test -v -cover ./panic
cat ./blank_panic/example_test.gopackage example
import (
"testing"
"github.com/dancsecs/sztest"
)
// Passing test.
func Test_PASS_BlankPanic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.Panic(
func() {
panic("") // Blank panic message.
},
sztest.BlankPanicMessage, // Panic without message is expected.
// Message returned in place of an empty string representing
// that an empty ("") panic was issued by the function.
)
}
// Failing test.
func Test_FAIL_BlankPanic(t *testing.T) {
chk := sztest.CaptureNothing(t)
defer chk.Release()
chk.Panic(
func() {
panic("") // Empty panic message will be flagged.
},
"",
// sztest.BlankPanicMessage will be returned.
)
}go test -v -cover ./blank_panic