Compare commits

...

2 Commits

Author SHA1 Message Date
cd9406900a v0.0.266 fix tst showing wrong file:line
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m22s
2023-09-21 13:08:13 +02:00
6c81f7f6bc fix tst showing wrong file:line, add DeepEqual 2023-09-21 13:07:55 +02:00
2 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.265"
const GoextVersion = "0.0.266"
const GoextVersionTimestamp = "2023-09-18T12:57:27+0200"
const GoextVersionTimestamp = "2023-09-21T13:08:13+0200"

View File

@ -2,23 +2,41 @@ package tst
import (
"encoding/hex"
"reflect"
"runtime/debug"
"testing"
)
func AssertEqual[T comparable](t *testing.T, actual T, expected T) {
t.Helper()
if actual != expected {
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actual, expected)
}
}
func AssertNotEqual[T comparable](t *testing.T, actual T, expected T) {
t.Helper()
if actual == expected {
t.Errorf("values do not differ: Actual: '%v', Expected: '%v'", actual, expected)
}
}
func AssertDeepEqual[T comparable](t *testing.T, actual T, expected T) {
t.Helper()
if reflect.DeepEqual(actual, expected) {
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actual, expected)
}
}
func AssertNotDeepEqual[T comparable](t *testing.T, actual T, expected T) {
t.Helper()
if !reflect.DeepEqual(actual, expected) {
t.Errorf("values do not differ: Actual: '%v', Expected: '%v'", actual, expected)
}
}
func AssertDeRefEqual[T comparable](t *testing.T, actual *T, expected T) {
t.Helper()
if actual == nil {
t.Errorf("values differ: Actual: NIL, Expected: '%v'", expected)
}
@ -28,6 +46,7 @@ func AssertDeRefEqual[T comparable](t *testing.T, actual *T, expected T) {
}
func AssertPtrEqual[T comparable](t *testing.T, actual *T, expected *T) {
t.Helper()
if actual == nil && expected == nil {
return
}
@ -47,6 +66,7 @@ func AssertPtrEqual[T comparable](t *testing.T, actual *T, expected *T) {
}
func AssertHexEqual(t *testing.T, expected string, actual []byte) {
t.Helper()
actualStr := hex.EncodeToString(actual)
if actualStr != expected {
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actualStr, expected)
@ -54,18 +74,21 @@ func AssertHexEqual(t *testing.T, expected string, actual []byte) {
}
func AssertTrue(t *testing.T, value bool) {
t.Helper()
if !value {
t.Error("value should be true\n" + string(debug.Stack()))
}
}
func AssertFalse(t *testing.T, value bool) {
t.Helper()
if value {
t.Error("value should be false\n" + string(debug.Stack()))
}
}
func AssertNoErr(t *testing.T, anerr error) {
t.Helper()
if anerr != nil {
t.Error("Function returned an error: " + anerr.Error() + "\n" + string(debug.Stack()))
}