Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions assert/assertion_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestCompare(t *testing.T) {
t.Parallel()

type customString string
type customInt int
type customInt8 int8
Expand Down Expand Up @@ -127,6 +129,8 @@ func callerName(skip int) string {
}

func TestGreater(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !Greater(mockT, 2, 1) {
Expand Down Expand Up @@ -171,6 +175,8 @@ func TestGreater(t *testing.T) {
}

func TestGreaterOrEqual(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !GreaterOrEqual(mockT, 2, 1) {
Expand Down Expand Up @@ -215,6 +221,8 @@ func TestGreaterOrEqual(t *testing.T) {
}

func TestLess(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !Less(mockT, 1, 2) {
Expand Down Expand Up @@ -259,6 +267,8 @@ func TestLess(t *testing.T) {
}

func TestLessOrEqual(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !LessOrEqual(mockT, 1, 2) {
Expand Down Expand Up @@ -303,6 +313,8 @@ func TestLessOrEqual(t *testing.T) {
}

func TestPositive(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !Positive(mockT, 1) {
Expand Down Expand Up @@ -342,6 +354,8 @@ func TestPositive(t *testing.T) {
}

func TestNegative(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !Negative(mockT, -1) {
Expand Down Expand Up @@ -381,6 +395,8 @@ func TestNegative(t *testing.T) {
}

func Test_compareTwoValuesDifferentValuesTypes(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

for _, currCase := range []struct {
Expand All @@ -399,6 +415,8 @@ func Test_compareTwoValuesDifferentValuesTypes(t *testing.T) {
}

func Test_compareTwoValuesNotComparableValues(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

type CompareStruct struct {
Expand All @@ -418,6 +436,8 @@ func Test_compareTwoValuesNotComparableValues(t *testing.T) {
}

func Test_compareTwoValuesCorrectCompareResult(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

for _, currCase := range []struct {
Expand All @@ -438,6 +458,8 @@ func Test_compareTwoValuesCorrectCompareResult(t *testing.T) {
}

func Test_containsValue(t *testing.T) {
t.Parallel()

for _, currCase := range []struct {
values []compareResult
value compareResult
Expand Down
10 changes: 10 additions & 0 deletions assert/assertion_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestIsIncreasing(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !IsIncreasing(mockT, []int{1, 2}) {
Expand Down Expand Up @@ -51,6 +53,8 @@ func TestIsIncreasing(t *testing.T) {
}

func TestIsNonIncreasing(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !IsNonIncreasing(mockT, []int{2, 1}) {
Expand Down Expand Up @@ -96,6 +100,8 @@ func TestIsNonIncreasing(t *testing.T) {
}

func TestIsDecreasing(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !IsDecreasing(mockT, []int{2, 1}) {
Expand Down Expand Up @@ -141,6 +147,8 @@ func TestIsDecreasing(t *testing.T) {
}

func TestIsNonDecreasing(t *testing.T) {
t.Parallel()

mockT := new(testing.T)

if !IsNonDecreasing(mockT, []int{1, 2}) {
Expand Down Expand Up @@ -186,6 +194,8 @@ func TestIsNonDecreasing(t *testing.T) {
}

func TestOrderingMsgAndArgsForwarding(t *testing.T) {
t.Parallel()

msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
expectedOutput := "format this c001\n"
collection := []int{1, 2, 1}
Expand Down
22 changes: 18 additions & 4 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
if !same {
// both are pointers but not the same type & pointing to the same address
return Fail(t, fmt.Sprintf("Not same: \n"+
"expected: %p %#v\n"+
"actual : %p %#v", expected, expected, actual, actual), msgAndArgs...)
"expected: %p %#[1]v\n"+
"actual : %p %#[2]v",
expected, actual), msgAndArgs...)
}

return true
Expand All @@ -569,8 +570,8 @@ func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}

if same {
return Fail(t, fmt.Sprintf(
"Expected and actual point to the same object: %p %#v",
expected, expected), msgAndArgs...)
"Expected and actual point to the same object: %p %#[1]v",
expected), msgAndArgs...)
}
return true
}
Expand Down Expand Up @@ -1852,6 +1853,11 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
}

// Shortcut if same bytes
if actual == expected {
return true
}

if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
}
Expand All @@ -1870,6 +1876,11 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
}

// Shortcut if same bytes
if actual == expected {
return true
}

if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil {
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
}
Expand Down Expand Up @@ -2008,6 +2019,9 @@ type CollectT struct {
errors []error
}

// Helper is like [testing.T.Helper] but does nothing.
func (CollectT) Helper() {}

// Errorf collects the error.
func (c *CollectT) Errorf(format string, args ...interface{}) {
c.errors = append(c.errors, fmt.Errorf(format, args...))
Expand Down
Loading