Skip to content
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ However, at `go-openapi` we would like to address the well-known issues in `test
1. [x] The first release comes with zero dependencies and an unstable API (see below [our use case](#usage-at-go-openapi))
2. |x] This project is going to be injected as the main and sole test dependency of the `go-openapi` libraries
2. [ ] ... and the `go-swagger` tool
3. [ ) Valuable pending pull requests from the original project could be merged (e.g. `JSONEqBytes`) or transformed as "enable" modules (e.g. colorized output)
3. [x] Valuable pending pull requests from the original project could be merged (e.g. `JSONEqBytes`) or transformed as "enable" modules (e.g. colorized output)
4. [ ] Unclear assertions may be provided an alternative verb (e.g. `InDelta`)
5. [ ] Since we have leveled the go requirements to the rest of the go-openapi (currently go1.24) there is quite a bit of relinting lying ahead.

Expand Down Expand Up @@ -200,14 +200,15 @@ some adaptations into this fork:
* github.com/stretchr/testify#1356 - panic(nil) handling for Go 1.21+
* github.com/stretchr/testify#1825 - Fix panic when using EqualValues with uncomparable types [merged]
* github.com/stretchr/testify#1818 - Fix panic on invalid regex in Regexp/NotRegexp assertions [merged]
* github.com/stretchr/testify#1223 - Display uint values in decimal instead of hex in diffs [merged]

### Planned merges

#### Critical safety fixes (high priority)

* Follow / adapt https://github.com/stretchr/testify/pull/1824

Not PRs, but reported issues in the original repo:
Not PRs, but reported issues in the original repo (need to investigate):

* https://github.com/stretchr/testify/issues/1826
* https://github.com/stretchr/testify/issues/1611
Expand All @@ -223,7 +224,7 @@ These improvements apply to the internalized and modernized copies of dependenci

#### UX improvements

* github.com/stretchr/testify#1223 - Display uint values in decimal instead of hex in diffs
* diff rendering

### Under consideration

Expand Down
4 changes: 2 additions & 2 deletions internal/assertions/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func formatUnequalValues(expected, actual any) (e string, a string) {
fmt.Sprintf("%T(%s)", actual, truncatingFormat("%#v", actual))
}
switch expected.(type) {
case time.Duration:
return fmt.Sprintf("%v", expected), fmt.Sprintf("%v", actual)
case time.Duration, uint, uint8, uint16, uint32, uint64:
return fmt.Sprint(expected), fmt.Sprint(actual)
default:
return truncatingFormat("%#v", expected), truncatingFormat("%#v", actual)
}
Expand Down
63 changes: 42 additions & 21 deletions internal/assertions/equal_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package assertions
import (
"errors"
"fmt"
"iter"
"slices"
"testing"
"time"
)
Expand Down Expand Up @@ -39,29 +41,15 @@ func testFormatUnequalValues() func(*testing.T) {
return func(t *testing.T) {
t.Parallel()

expected, actual := formatUnequalValues("foo", "bar")
Equal(t, `"foo"`, expected, "value should not include type")
Equal(t, `"bar"`, actual, "value should not include type")

expected, actual = formatUnequalValues(123, 123)
Equal(t, `123`, expected, "value should not include type")
Equal(t, `123`, actual, "value should not include type")

expected, actual = formatUnequalValues(int64(123), int32(123))
Equal(t, `int64(123)`, expected, "value should include type")
Equal(t, `int32(123)`, actual, "value should include type")

expected, actual = formatUnequalValues(int64(123), nil)
Equal(t, `int64(123)`, expected, "value should include type")
Equal(t, `<nil>(<nil>)`, actual, "value should include type")
for tt := range formatUnequalCases() {
t.Run(tt.testName, func(t *testing.T) {
t.Parallel()

type testStructType struct {
Val string
expected, actual := formatUnequalValues(tt.unequalExpected, tt.unequalActual)
Equal(t, tt.expectedExpected, expected, tt.testName)
Equal(t, tt.expectedActual, actual, tt.testName)
})
}

expected, actual = formatUnequalValues(&testStructType{Val: "test"}, &testStructType{Val: "test"})
Equal(t, fmt.Sprintf(`&%s.testStructType{Val:"test"}`, shortpkg), expected, "value should not include type annotation")
Equal(t, fmt.Sprintf(`&%s.testStructType{Val:"test"}`, shortpkg), actual, "value should not include type annotation")
}
}

Expand Down Expand Up @@ -207,3 +195,36 @@ func testValidateEqualArgs() func(*testing.T) {
}
}
}

type formatUnequalCase struct {
unequalExpected any
unequalActual any
expectedExpected string
expectedActual string
testName string
}

func formatUnequalCases() iter.Seq[formatUnequalCase] {
type testStructType struct {
Val string
}

return slices.Values([]formatUnequalCase{
{"foo", "bar", `"foo"`, `"bar"`, "value should not include type"},
{123, 123, `123`, `123`, "value should not include type"},
{int64(123), int32(123), `int64(123)`, `int32(123)`, "value should include type"},
{int64(123), nil, `int64(123)`, `<nil>(<nil>)`, "value should include type"},
{
unequalExpected: &testStructType{Val: "test"},
unequalActual: &testStructType{Val: "test"},
expectedExpected: fmt.Sprintf(`&%s.testStructType{Val:"test"}`, shortpkg),
expectedActual: fmt.Sprintf(`&%s.testStructType{Val:"test"}`, shortpkg),
testName: "value should not include type annotation",
},
{uint(123), uint(124), `123`, `124`, "uint should print clean"},
{uint8(123), uint8(124), `123`, `124`, "uint8 should print clean"},
{uint16(123), uint16(124), `123`, `124`, "uint16 should print clean"},
{uint32(123), uint32(124), `123`, `124`, "uint32 should print clean"},
{uint64(123), uint64(124), `123`, `124`, "uint64 should print clean"},
})
}
1 change: 1 addition & 0 deletions internal/assertions/equal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func equalCases() iter.Seq[equalCase] {

// A case that might be confusing, especially with numeric literals
{10, uint(10), false, ""},
{int(1), uint(1), false, ""},
})
}

Expand Down
Loading