test: improve assertions and remove stack traces

Seems like these stack traces are not necessary, as the information which assertion actually failed is already figured out by "go test" in a less convoluted way.
This commit is contained in:
Florian Loch 2022-02-28 12:47:34 +01:00
parent bca0870d92
commit dbd1b5c8a8

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"runtime/debug"
"sync" "sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -492,46 +491,43 @@ func makeTestPinger() *Pinger {
func AssertNoError(t *testing.T, err error) { func AssertNoError(t *testing.T, err error) {
t.Helper() t.Helper()
if err != nil { if err != nil {
t.Errorf("Expected No Error but got %s, Stack:\n%s", t.Errorf("Expected No Error but got %q", err)
err, string(debug.Stack()))
} }
} }
func AssertError(t *testing.T, err error, info string) { func AssertError(t *testing.T, err error, info string) {
t.Helper() t.Helper()
if err == nil { if err == nil {
t.Errorf("Expected Error but got %s, %s, Stack:\n%s", t.Errorf("Expected Error %q but got %q",
err, info, string(debug.Stack())) err, info)
} }
} }
func AssertEqualStrings(t *testing.T, expected, actual string) { func AssertEqualStrings(t *testing.T, expected, actual string) {
t.Helper() t.Helper()
if expected != actual { if expected != actual {
t.Errorf("Expected %s, got %s, Stack:\n%s", t.Errorf("Expected %s, got %s", expected, actual)
expected, actual, string(debug.Stack()))
} }
} }
func AssertNotEqualStrings(t *testing.T, expected, actual string) { func AssertNotEqualStrings(t *testing.T, expected, actual string) {
t.Helper() t.Helper()
if expected == actual { if expected == actual {
t.Errorf("Expected %s, got %s, Stack:\n%s", t.Errorf("Expected %q, got %q", expected, actual)
expected, actual, string(debug.Stack()))
} }
} }
func AssertTrue(t *testing.T, b bool) { func AssertTrue(t *testing.T, b bool) {
t.Helper() t.Helper()
if !b { if !b {
t.Errorf("Expected True, got False, Stack:\n%s", string(debug.Stack())) t.Errorf("Expected True, got False")
} }
} }
func AssertFalse(t *testing.T, b bool) { func AssertFalse(t *testing.T, b bool) {
t.Helper() t.Helper()
if b { if b {
t.Errorf("Expected False, got True, Stack:\n%s", string(debug.Stack())) t.Errorf("Expected False, got True")
} }
} }