diff --git a/assert/assert_assertions.go b/assert/assert_assertions.go index b7de4ac76..e87343f96 100644 --- a/assert/assert_assertions.go +++ b/assert/assert_assertions.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -958,6 +959,28 @@ func JSONEqBytes(t T, expected []byte, actual []byte, msgAndArgs ...any) bool { return assertions.JSONEqBytes(t, expected, actual, msgAndArgs...) } +// Kind asserts that the [reflect.Kind] of a given object matches the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.Kind(t, reflect.String, "Hello World") +// +// # Examples +// +// success: reflect.String, "hello" +// failure: reflect.String, 0 +// +// Upon failure, the test [T] is marked as failed and continues execution. +func Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + if h, ok := t.(H); ok { + h.Helper() + } + return assertions.Kind(t, expectedKind, object, msgAndArgs...) +} + // Len asserts that the specified object has specific length. // // Len also fails if the object has a type that len() does not accept. @@ -1329,6 +1352,28 @@ func NotImplements(t T, interfaceObject any, object any, msgAndArgs ...any) bool return assertions.NotImplements(t, interfaceObject, object, msgAndArgs...) } +// NotKind asserts that the [reflect.Kind] of a given object does not match the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.NotKind(t, reflect.Int, "Hello World") +// +// # Examples +// +// success: reflect.String, 0 +// failure: reflect.String, "hello" +// +// Upon failure, the test [T] is marked as failed and continues execution. +func NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + if h, ok := t.(H); ok { + h.Helper() + } + return assertions.NotKind(t, expectedKind, object, msgAndArgs...) +} + // NotNil asserts that the specified object is not nil. // // # Usage diff --git a/assert/assert_assertions_test.go b/assert/assert_assertions_test.go index a67d757e6..8d8377f77 100644 --- a/assert/assert_assertions_test.go +++ b/assert/assert_assertions_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -1056,6 +1057,30 @@ func TestJSONEqBytes(t *testing.T) { }) } +func TestKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + result := Kind(t, reflect.String, "hello") + if !result { + t.Error("Kind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + result := Kind(mock, reflect.String, 0) + if result { + t.Error("Kind should return false on failure") + } + if !mock.failed { + t.Error("Kind should mark test as failed") + } + }) +} + func TestLen(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -1464,6 +1489,30 @@ func TestNotImplements(t *testing.T) { }) } +func TestNotKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + result := NotKind(t, reflect.String, 0) + if !result { + t.Error("NotKind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + result := NotKind(mock, reflect.String, "hello") + if result { + t.Error("NotKind should return false on failure") + } + if !mock.failed { + t.Error("NotKind should mark test as failed") + } + }) +} + func TestNotNil(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/assert/assert_examples_test.go b/assert/assert_examples_test.go index b2ee0c8e8..da17b371b 100644 --- a/assert/assert_examples_test.go +++ b/assert/assert_examples_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert_test @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" @@ -368,6 +369,14 @@ func ExampleJSONEqBytes() { // Output: success: true } +func ExampleKind() { + t := new(testing.T) + success := assert.Kind(t, reflect.String, "hello") + fmt.Printf("success: %t\n", success) + + // Output: success: true +} + func ExampleLen() { t := new(testing.T) success := assert.Len(t, []string{"A", "B"}, 2) @@ -506,6 +515,14 @@ func ExampleNotImplements() { // Output: success: true } +func ExampleNotKind() { + t := new(testing.T) + success := assert.NotKind(t, reflect.String, 0) + fmt.Printf("success: %t\n", success) + + // Output: success: true +} + func ExampleNotNil() { t := new(testing.T) success := assert.NotNil(t, "not nil") diff --git a/assert/assert_format.go b/assert/assert_format.go index a64852e87..e7a88613e 100644 --- a/assert/assert_format.go +++ b/assert/assert_format.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -454,6 +455,16 @@ func JSONEqBytesf(t T, expected []byte, actual []byte, msg string, args ...any) return assertions.JSONEqBytes(t, expected, actual, forwardArgs(msg, args)) } +// Kindf is the same as [Kind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func Kindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool { + if h, ok := t.(H); ok { + h.Helper() + } + return assertions.Kind(t, expectedKind, object, forwardArgs(msg, args)) +} + // Lenf is the same as [Len], but accepts a format msg string to format arguments like [fmt.Printf]. // // Upon failure, the test [T] is marked as failed and continues execution. @@ -624,6 +635,16 @@ func NotImplementsf(t T, interfaceObject any, object any, msg string, args ...an return assertions.NotImplements(t, interfaceObject, object, forwardArgs(msg, args)) } +// NotKindf is the same as [NotKind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func NotKindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool { + if h, ok := t.(H); ok { + h.Helper() + } + return assertions.NotKind(t, expectedKind, object, forwardArgs(msg, args)) +} + // NotNilf is the same as [NotNil], but accepts a format msg string to format arguments like [fmt.Printf]. // // Upon failure, the test [T] is marked as failed and continues execution. diff --git a/assert/assert_format_test.go b/assert/assert_format_test.go index 17e3d4f7f..c682dd4e7 100644 --- a/assert/assert_format_test.go +++ b/assert/assert_format_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -1056,6 +1057,30 @@ func TestJSONEqBytesf(t *testing.T) { }) } +func TestKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + result := Kindf(t, reflect.String, "hello", "test message") + if !result { + t.Error("Kindf should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + result := Kindf(mock, reflect.String, 0, "test message") + if result { + t.Error("Kindf should return false on failure") + } + if !mock.failed { + t.Error("Kind should mark test as failed") + } + }) +} + func TestLenf(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -1464,6 +1489,30 @@ func TestNotImplementsf(t *testing.T) { }) } +func TestNotKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + result := NotKindf(t, reflect.String, 0, "test message") + if !result { + t.Error("NotKindf should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + result := NotKindf(mock, reflect.String, "hello", "test message") + if result { + t.Error("NotKindf should return false on failure") + } + if !mock.failed { + t.Error("NotKind should mark test as failed") + } + }) +} + func TestNotNilf(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/assert/assert_forward.go b/assert/assert_forward.go index 1a6f39228..2f139fe11 100644 --- a/assert/assert_forward.go +++ b/assert/assert_forward.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -910,6 +911,26 @@ func (a *Assertions) JSONEqBytesf(expected []byte, actual []byte, msg string, ar return assertions.JSONEqBytes(a.t, expected, actual, forwardArgs(msg, args)) } +// Kind is the same as [Kind], as a method rather than a package-level function. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func (a *Assertions) Kind(expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + if h, ok := a.t.(H); ok { + h.Helper() + } + return assertions.Kind(a.t, expectedKind, object, msgAndArgs...) +} + +// Kindf is the same as [Assertions.Kind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func (a *Assertions) Kindf(expectedKind reflect.Kind, object any, msg string, args ...any) bool { + if h, ok := a.t.(H); ok { + h.Helper() + } + return assertions.Kind(a.t, expectedKind, object, forwardArgs(msg, args)) +} + // Len is the same as [Len], as a method rather than a package-level function. // // Upon failure, the test [T] is marked as failed and continues execution. @@ -1250,6 +1271,26 @@ func (a *Assertions) NotImplementsf(interfaceObject any, object any, msg string, return assertions.NotImplements(a.t, interfaceObject, object, forwardArgs(msg, args)) } +// NotKind is the same as [NotKind], as a method rather than a package-level function. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func (a *Assertions) NotKind(expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + if h, ok := a.t.(H); ok { + h.Helper() + } + return assertions.NotKind(a.t, expectedKind, object, msgAndArgs...) +} + +// NotKindf is the same as [Assertions.NotKind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and continues execution. +func (a *Assertions) NotKindf(expectedKind reflect.Kind, object any, msg string, args ...any) bool { + if h, ok := a.t.(H); ok { + h.Helper() + } + return assertions.NotKind(a.t, expectedKind, object, forwardArgs(msg, args)) +} + // NotNil is the same as [NotNil], as a method rather than a package-level function. // // Upon failure, the test [T] is marked as failed and continues execution. diff --git a/assert/assert_forward_test.go b/assert/assert_forward_test.go index bdf9950ee..7b5d9a072 100644 --- a/assert/assert_forward_test.go +++ b/assert/assert_forward_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -2355,6 +2356,60 @@ func TestAssertionsJSONEqBytesf(t *testing.T) { }) } +func TestAssertionsKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + result := a.Kind(reflect.String, "hello") + if !result { + t.Error("Assertions.Kind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + a := New(mock) + result := a.Kind(reflect.String, 0) + if result { + t.Error("Assertions.Kind should return false on failure") + } + if !mock.failed { + t.Error("Kind should mark test as failed") + } + }) +} + +func TestAssertionsKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + result := a.Kindf(reflect.String, "hello", "test message") + if !result { + t.Error("Assertions.Kind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + a := New(mock) + result := a.Kindf(reflect.String, 0, "test message") + if result { + t.Error("Assertions.Kind should return false on failure") + } + if !mock.failed { + t.Error("Assertions.Kind should mark test as failed") + } + }) +} + func TestAssertionsLen(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -3273,6 +3328,60 @@ func TestAssertionsNotImplementsf(t *testing.T) { }) } +func TestAssertionsNotKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + result := a.NotKind(reflect.String, 0) + if !result { + t.Error("Assertions.NotKind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + a := New(mock) + result := a.NotKind(reflect.String, "hello") + if result { + t.Error("Assertions.NotKind should return false on failure") + } + if !mock.failed { + t.Error("NotKind should mark test as failed") + } + }) +} + +func TestAssertionsNotKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + result := a.NotKindf(reflect.String, 0, "test message") + if !result { + t.Error("Assertions.NotKind should return true on success") + } + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + a := New(mock) + result := a.NotKindf(reflect.String, "hello", "test message") + if result { + t.Error("Assertions.NotKind should return false on failure") + } + if !mock.failed { + t.Error("Assertions.NotKind should mark test as failed") + } + }) +} + func TestAssertionsNotNil(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/assert/assert_helpers.go b/assert/assert_helpers.go index c1792ebd9..b825eaa4a 100644 --- a/assert/assert_helpers.go +++ b/assert/assert_helpers.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert diff --git a/assert/assert_helpers_test.go b/assert/assert_helpers_test.go index 3c7385fb7..f33263283 100644 --- a/assert/assert_helpers_test.go +++ b/assert/assert_helpers_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert diff --git a/assert/assert_types.go b/assert/assert_types.go index 625423771..bd89020a1 100644 --- a/assert/assert_types.go +++ b/assert/assert_types.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package assert diff --git a/docs/doc-site/api/_index.md b/docs/doc-site/api/_index.md index d806fda12..b17f59a6f 100644 --- a/docs/doc-site/api/_index.md +++ b/docs/doc-site/api/_index.md @@ -46,7 +46,7 @@ The `testify` API is organized in 18 domains shown below. - [String](./string.md) - Asserting Strings (2) - [Testing](./testing.md) - Mimicks Methods From The Testing Standard Library (2) - [Time](./time.md) - Asserting Times And Durations (2) -- [Type](./type.md) - Asserting Types Rather Than Values (6) +- [Type](./type.md) - Asserting Types Rather Than Values (8) - [Yaml](./yaml.md) - Asserting Yaml Documents (1) - [Common](./common.md) - Other Uncategorized Helpers (4) @@ -66,5 +66,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/boolean.md b/docs/doc-site/api/boolean.md index ac630d6d7..522ed390a 100644 --- a/docs/doc-site/api/boolean.md +++ b/docs/doc-site/api/boolean.md @@ -133,5 +133,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/collection.md b/docs/doc-site/api/collection.md index 6eef2b795..eecc21bb2 100644 --- a/docs/doc-site/api/collection.md +++ b/docs/doc-site/api/collection.md @@ -419,5 +419,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/common.md b/docs/doc-site/api/common.md index 3bd243d4c..625b0bd16 100644 --- a/docs/doc-site/api/common.md +++ b/docs/doc-site/api/common.md @@ -157,5 +157,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/comparison.md b/docs/doc-site/api/comparison.md index bf88a6209..fd118d26b 100644 --- a/docs/doc-site/api/comparison.md +++ b/docs/doc-site/api/comparison.md @@ -341,5 +341,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/condition.md b/docs/doc-site/api/condition.md index 4457c3714..9073bdbe2 100644 --- a/docs/doc-site/api/condition.md +++ b/docs/doc-site/api/condition.md @@ -287,5 +287,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/equality.md b/docs/doc-site/api/equality.md index e27ebc10d..21365307d 100644 --- a/docs/doc-site/api/equality.md +++ b/docs/doc-site/api/equality.md @@ -656,5 +656,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/error.md b/docs/doc-site/api/error.md index 51f9a1fe9..d9b1b1b40 100644 --- a/docs/doc-site/api/error.md +++ b/docs/doc-site/api/error.md @@ -442,5 +442,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/file.md b/docs/doc-site/api/file.md index f024e3789..31aaadb1f 100644 --- a/docs/doc-site/api/file.md +++ b/docs/doc-site/api/file.md @@ -335,5 +335,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/http.md b/docs/doc-site/api/http.md index b0a9ff4ca..625c37798 100644 --- a/docs/doc-site/api/http.md +++ b/docs/doc-site/api/http.md @@ -373,5 +373,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/json.md b/docs/doc-site/api/json.md index edb9af0bc..41b245104 100644 --- a/docs/doc-site/api/json.md +++ b/docs/doc-site/api/json.md @@ -133,5 +133,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/number.md b/docs/doc-site/api/number.md index 89240172c..a3d2cd378 100644 --- a/docs/doc-site/api/number.md +++ b/docs/doc-site/api/number.md @@ -280,5 +280,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/ordering.md b/docs/doc-site/api/ordering.md index 51e1800b8..a44719b01 100644 --- a/docs/doc-site/api/ordering.md +++ b/docs/doc-site/api/ordering.md @@ -239,5 +239,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/panic.md b/docs/doc-site/api/panic.md index 979d89d41..98dd90e21 100644 --- a/docs/doc-site/api/panic.md +++ b/docs/doc-site/api/panic.md @@ -234,5 +234,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/string.md b/docs/doc-site/api/string.md index 20d95f8d9..3fcf66201 100644 --- a/docs/doc-site/api/string.md +++ b/docs/doc-site/api/string.md @@ -135,5 +135,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/testing.md b/docs/doc-site/api/testing.md index c22d3df75..358f129fa 100644 --- a/docs/doc-site/api/testing.md +++ b/docs/doc-site/api/testing.md @@ -131,5 +131,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/time.md b/docs/doc-site/api/time.md index 4b398bf03..05d928a0a 100644 --- a/docs/doc-site/api/time.md +++ b/docs/doc-site/api/time.md @@ -133,5 +133,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/type.md b/docs/doc-site/api/type.md index 2f05b97ae..4a51b46e2 100644 --- a/docs/doc-site/api/type.md +++ b/docs/doc-site/api/type.md @@ -12,8 +12,12 @@ keywords: - "IsNotTypef" - "IsType" - "IsTypef" + - "Kind" + - "Kindf" - "NotImplements" - "NotImplementsf" + - "NotKind" + - "NotKindf" - "NotZero" - "NotZerof" - "Zero" @@ -29,7 +33,7 @@ Asserting Types Rather Than Values _All links point to _ -This domain exposes 6 functionalities. +This domain exposes 8 functionalities. ### Implements @@ -172,6 +176,56 @@ IsType asserts that the specified objects are of the same type. {{% /tab %}} {{< /tabs >}} +### Kind + +Kind asserts that the [reflect.Kind](https://pkg.go.dev/reflect#Kind) of a given object matches the expected [reflect.Kind](https://pkg.go.dev/reflect#Kind). + +Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +are comparable to [reflect.Invalid](https://pkg.go.dev/reflect#Invalid). See also [reflect.Value.Kind](https://pkg.go.dev/reflect#Value.Kind). + +{{% expand title="Examples" %}} +{{< tabs >}} +{{% tab title="Usage" %}} +```go + assertions.Kind(t, reflect.String, "Hello World") +``` +{{< /tab >}} +{{% tab title="Examples" %}} +```go + success: reflect.String, "hello" + failure: reflect.String, 0 +``` +{{< /tab >}} +{{< /tabs >}} +{{% /expand %}} + +{{< tabs >}} +{{% tab title="assert" style="secondary" %}} +| Signature | Usage | +|--|--| +| [`assert.Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Kind) | package-level function | +| [`assert.Kindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Kindf) | formatted variant | +| [`assert.(*Assertions).Kind(expectedKind reflect.Kind, object any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Assertions.Kind) | method variant | +| [`assert.(*Assertions).Kindf(expectedKind reflect.Kind, object any, msg string, args ..any)`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Assertions.Kindf) | method formatted variant | +{{% /tab %}} +{{% tab title="require" style="secondary" %}} +| Signature | Usage | +|--|--| +| [`require.Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Kind) | package-level function | +| [`require.Kindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Kindf) | formatted variant | +| [`require.(*Assertions).Kind(expectedKind reflect.Kind, object any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Assertions.Kind) | method variant | +| [`require.(*Assertions).Kindf(expectedKind reflect.Kind, object any, msg string, args ..any)`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Assertions.Kindf) | method formatted variant | +{{% /tab %}} + +{{% tab title="internal" style="accent" icon="wrench" %}} +| Signature | Usage | +|--|--| +| [`assertions.Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#Kind) | internal implementation | + +**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Kind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L162) +{{% /tab %}} +{{< /tabs >}} + ### NotImplements NotImplements asserts that an object does not implement the specified interface. @@ -219,6 +273,56 @@ NotImplements asserts that an object does not implement the specified interface. {{% /tab %}} {{< /tabs >}} +### NotKind + +NotKind asserts that the [reflect.Kind](https://pkg.go.dev/reflect#Kind) of a given object does not match the expected [reflect.Kind](https://pkg.go.dev/reflect#Kind). + +Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +are comparable to [reflect.Invalid](https://pkg.go.dev/reflect#Invalid). See also [reflect.Value.Kind](https://pkg.go.dev/reflect#Value.Kind). + +{{% expand title="Examples" %}} +{{< tabs >}} +{{% tab title="Usage" %}} +```go + assertions.NotKind(t, reflect.Int, "Hello World") +``` +{{< /tab >}} +{{% tab title="Examples" %}} +```go + success: reflect.String, 0 + failure: reflect.String, "hello" +``` +{{< /tab >}} +{{< /tabs >}} +{{% /expand %}} + +{{< tabs >}} +{{% tab title="assert" style="secondary" %}} +| Signature | Usage | +|--|--| +| [`assert.NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#NotKind) | package-level function | +| [`assert.NotKindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#NotKindf) | formatted variant | +| [`assert.(*Assertions).NotKind(expectedKind reflect.Kind, object any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Assertions.NotKind) | method variant | +| [`assert.(*Assertions).NotKindf(expectedKind reflect.Kind, object any, msg string, args ..any)`](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#Assertions.NotKindf) | method formatted variant | +{{% /tab %}} +{{% tab title="require" style="secondary" %}} +| Signature | Usage | +|--|--| +| [`require.NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#NotKind) | package-level function | +| [`require.NotKindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#NotKindf) | formatted variant | +| [`require.(*Assertions).NotKind(expectedKind reflect.Kind, object any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Assertions.NotKind) | method variant | +| [`require.(*Assertions).NotKindf(expectedKind reflect.Kind, object any, msg string, args ..any)`](https://pkg.go.dev/github.com/go-openapi/testify/v2/require#Assertions.NotKindf) | method formatted variant | +{{% /tab %}} + +{{% tab title="internal" style="accent" icon="wrench" %}} +| Signature | Usage | +|--|--| +| [`assertions.NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotKind) | internal implementation | + +**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotKind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L195) +{{% /tab %}} +{{< /tabs >}} + ### NotZero NotZero asserts that i is not the zero value for its type. @@ -329,5 +433,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/docs/doc-site/api/yaml.md b/docs/doc-site/api/yaml.md index dc64b84c0..88338c969 100644 --- a/docs/doc-site/api/yaml.md +++ b/docs/doc-site/api/yaml.md @@ -94,5 +94,5 @@ SPDX-License-Identifier: Apache-2.0 Document generated by github.com/go-openapi/testify/codegen/v2 DO NOT EDIT. -Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] --> diff --git a/internal/assertions/type.go b/internal/assertions/type.go index e916c64aa..392a35548 100644 --- a/internal/assertions/type.go +++ b/internal/assertions/type.go @@ -146,6 +146,67 @@ func NotZero(t T, i any, msgAndArgs ...any) bool { return true } +// Kind asserts that the [reflect.Kind] of a given object matches the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.Kind(t, reflect.String, "Hello World") +// +// # Examples +// +// success: reflect.String, "hello" +// failure: reflect.String, 0 +func Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + // Domain: type + if h, ok := t.(H); ok { + h.Helper() + } + + val := reflect.ValueOf(object) + kind := val.Kind() + if kind != expectedKind { + if kind == reflect.Invalid { + // add some explanation when reflect.Invalid does not match the expectation (common gotcha with reflect) + return Fail(t, "object has reflect.Invalid kind: this is nil or an interface with nil value", msgAndArgs...) + } + + return Fail(t, fmt.Sprintf("object expected to be of kind %v, but was %v", expectedKind, kind), msgAndArgs...) + } + + return true +} + +// NotKind asserts that the [reflect.Kind] of a given object does not match the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.NotKind(t, reflect.Int, "Hello World") +// +// # Examples +// +// success: reflect.String, 0 +// failure: reflect.String, "hello" +func NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool { + // Domain: type + if h, ok := t.(H); ok { + h.Helper() + } + + val := reflect.ValueOf(object) + kind := val.Kind() + if kind != expectedKind { + return true + } + + return Fail(t, fmt.Sprintf("object expected not to be of kind %v, but was %v", expectedKind, kind), msgAndArgs...) +} + func isType(expectedType, object any) bool { return ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) } diff --git a/internal/assertions/type_test.go b/internal/assertions/type_test.go index 4da9d1471..08f09be4e 100644 --- a/internal/assertions/type_test.go +++ b/internal/assertions/type_test.go @@ -4,7 +4,9 @@ package assertions import ( + "errors" "iter" + "reflect" "slices" "testing" ) @@ -101,6 +103,39 @@ func TestTypeNotZero(t *testing.T) { } } +func TestTypeKind(t *testing.T) { + t.Parallel() + + for tt := range kindCases() { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + mock := new(mockT) + result := Kind(mock, tt.expectedKind, tt.value) + resultNot := NotKind(mock, tt.expectedKind, tt.value) + + if tt.result { + if !result { + t.Errorf("expected kind of %T to be %q, but Kind reported %t", tt.value, tt.expectedKind, result) + } + if resultNot { + t.Errorf("expected kind of %T to be %q, but NotKind reported %t", tt.value, tt.expectedKind, resultNot) + } + + return + } + + // expected: false + if result { + t.Errorf("expected kind of %T NOT to be %q, but Kind reported %t", tt.value, tt.expectedKind, result) + } + if !resultNot { + t.Errorf("expected kind of %T NOT to be %q, but NotKind reported %t", tt.value, tt.expectedKind, resultNot) + } + }) + } +} + func TestTypeDiffEmptyCases(t *testing.T) { t.Parallel() @@ -216,3 +251,42 @@ func typeNonZeros() iter.Seq[any] { (chan<- any)(make(chan any)), }) } + +type kindCase struct { + expectedKind reflect.Kind + value any + result bool + name string +} + +func kindCases() iter.Seq[kindCase] { + var iface any = "string" + + return slices.Values([]kindCase{ + // True cases + {reflect.String, "Hello World", true, "is string"}, + {reflect.Int, 123, true, "is int"}, + {reflect.Array, [6]int{2, 3, 5, 7, 11, 13}, true, "is array"}, + {reflect.Func, Kind, true, "is func"}, + {reflect.Float64, 0.0345, true, "is float64"}, + {reflect.Map, make(map[string]int), true, "is map"}, + {reflect.Bool, true, true, "is bool"}, + {reflect.Ptr, new(int), true, "is pointer"}, + // False cases + {reflect.String, 13, false, "not string"}, + {reflect.Int, [6]int{2, 3, 5, 7, 11, 13}, false, "not int"}, + {reflect.Float64, 12, false, "not float64"}, + {reflect.Bool, make(map[string]int), false, "not bool"}, + // Edge cases + // True + {reflect.Invalid, any(nil), true, "legitimate expectation of reflect.Invalid (any)"}, + {reflect.Ptr, (*any)(nil), true, "legitimate expectation of reflect.Pointer (*any)"}, + {reflect.Invalid, (error)(nil), true, "legitimate expectation of reflect.Invalid (error)"}, + {reflect.Invalid, nil, true, "legitimate nil input"}, + // False + {reflect.Interface, iface, false, "interface returns concrete type (any)"}, + {reflect.Interface, errors.New("stuff"), false, "interface returns concrete type (error)"}, + {reflect.Invalid, "string", false, "wrong expectation of reflect.Invalid"}, + {reflect.Ptr, nil, false, "nil input"}, + }) +} diff --git a/require/require_assertions.go b/require/require_assertions.go index 2dcdeee9d..d3a0c90eb 100644 --- a/require/require_assertions.go +++ b/require/require_assertions.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -1130,6 +1131,32 @@ func JSONEqBytes(t T, expected []byte, actual []byte, msgAndArgs ...any) { t.FailNow() } +// Kind asserts that the [reflect.Kind] of a given object matches the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.Kind(t, reflect.String, "Hello World") +// +// # Examples +// +// success: reflect.String, "hello" +// failure: reflect.String, 0 +// +// Upon failure, the test [T] is marked as failed and stops execution. +func Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) { + if h, ok := t.(H); ok { + h.Helper() + } + if assertions.Kind(t, expectedKind, object, msgAndArgs...) { + return + } + + t.FailNow() +} + // Len asserts that the specified object has specific length. // // Len also fails if the object has a type that len() does not accept. @@ -1569,6 +1596,32 @@ func NotImplements(t T, interfaceObject any, object any, msgAndArgs ...any) { t.FailNow() } +// NotKind asserts that the [reflect.Kind] of a given object does not match the expected [reflect.Kind]. +// +// Kind reflects the concrete value stored in the object. The nil value (or interface with nil value) +// are comparable to [reflect.Invalid]. See also [reflect.Value.Kind]. +// +// # Usage +// +// assertions.NotKind(t, reflect.Int, "Hello World") +// +// # Examples +// +// success: reflect.String, 0 +// failure: reflect.String, "hello" +// +// Upon failure, the test [T] is marked as failed and stops execution. +func NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) { + if h, ok := t.(H); ok { + h.Helper() + } + if assertions.NotKind(t, expectedKind, object, msgAndArgs...) { + return + } + + t.FailNow() +} + // NotNil asserts that the specified object is not nil. // // # Usage diff --git a/require/require_assertions_test.go b/require/require_assertions_test.go index 48d725061..534c572d2 100644 --- a/require/require_assertions_test.go +++ b/require/require_assertions_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -884,6 +885,26 @@ func TestJSONEqBytes(t *testing.T) { }) } +func TestKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + Kind(t, reflect.String, "hello") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + Kind(mock, reflect.String, 0) + // require functions don't return a value + if !mock.failed { + t.Error("Kind should call FailNow()") + } + }) +} + func TestLen(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -1224,6 +1245,26 @@ func TestNotImplements(t *testing.T) { }) } +func TestNotKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + NotKind(t, reflect.String, 0) + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + NotKind(mock, reflect.String, "hello") + // require functions don't return a value + if !mock.failed { + t.Error("NotKind should call FailNow()") + } + }) +} + func TestNotNil(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/require/require_examples_test.go b/require/require_examples_test.go index 18eeb4555..0dd3d16ad 100644 --- a/require/require_examples_test.go +++ b/require/require_examples_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require_test @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" @@ -369,6 +370,14 @@ func ExampleJSONEqBytes() { // Output: passed } +func ExampleKind() { + t := new(testing.T) + require.Kind(t, reflect.String, "hello") + fmt.Println("passed") + + // Output: passed +} + func ExampleLen() { t := new(testing.T) require.Len(t, []string{"A", "B"}, 2) @@ -507,6 +516,14 @@ func ExampleNotImplements() { // Output: passed } +func ExampleNotKind() { + t := new(testing.T) + require.NotKind(t, reflect.String, 0) + fmt.Println("passed") + + // Output: passed +} + func ExampleNotNil() { t := new(testing.T) require.NotNil(t, "not nil") diff --git a/require/require_format.go b/require/require_format.go index b704fa554..43a939a6f 100644 --- a/require/require_format.go +++ b/require/require_format.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -626,6 +627,20 @@ func JSONEqBytesf(t T, expected []byte, actual []byte, msg string, args ...any) t.FailNow() } +// Kindf is the same as [Kind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func Kindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) { + if h, ok := t.(H); ok { + h.Helper() + } + if assertions.Kind(t, expectedKind, object, forwardArgs(msg, args)) { + return + } + + t.FailNow() +} + // Lenf is the same as [Len], but accepts a format msg string to format arguments like [fmt.Printf]. // // Upon failure, the test [T] is marked as failed and stops execution. @@ -864,6 +879,20 @@ func NotImplementsf(t T, interfaceObject any, object any, msg string, args ...an t.FailNow() } +// NotKindf is the same as [NotKind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func NotKindf(t T, expectedKind reflect.Kind, object any, msg string, args ...any) { + if h, ok := t.(H); ok { + h.Helper() + } + if assertions.NotKind(t, expectedKind, object, forwardArgs(msg, args)) { + return + } + + t.FailNow() +} + // NotNilf is the same as [NotNil], but accepts a format msg string to format arguments like [fmt.Printf]. // // Upon failure, the test [T] is marked as failed and stops execution. diff --git a/require/require_format_test.go b/require/require_format_test.go index a8c1b7528..2dff348ed 100644 --- a/require/require_format_test.go +++ b/require/require_format_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -884,6 +885,26 @@ func TestJSONEqBytesf(t *testing.T) { }) } +func TestKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + Kindf(t, reflect.String, "hello", "test message") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + Kindf(mock, reflect.String, 0, "test message") + // require functions don't return a value + if !mock.failed { + t.Error("Kind should call FailNow()") + } + }) +} + func TestLenf(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -1224,6 +1245,26 @@ func TestNotImplementsf(t *testing.T) { }) } +func TestNotKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + NotKindf(t, reflect.String, 0, "test message") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + NotKindf(mock, reflect.String, "hello", "test message") + // require functions don't return a value + if !mock.failed { + t.Error("NotKind should call FailNow()") + } + }) +} + func TestNotNilf(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/require/require_forward.go b/require/require_forward.go index 416048630..ef46dee5f 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require import ( "net/http" "net/url" + "reflect" "time" "github.com/go-openapi/testify/v2/internal/assertions" @@ -1254,6 +1255,34 @@ func (a *Assertions) JSONEqBytesf(expected []byte, actual []byte, msg string, ar a.t.FailNow() } +// Kind is the same as [Kind], as a method rather than a package-level function. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func (a *Assertions) Kind(expectedKind reflect.Kind, object any, msgAndArgs ...any) { + if h, ok := a.t.(H); ok { + h.Helper() + } + if assertions.Kind(a.t, expectedKind, object, msgAndArgs...) { + return + } + + a.t.FailNow() +} + +// Kindf is the same as [Assertions.Kind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func (a *Assertions) Kindf(expectedKind reflect.Kind, object any, msg string, args ...any) { + if h, ok := a.t.(H); ok { + h.Helper() + } + if assertions.Kind(a.t, expectedKind, object, forwardArgs(msg, args)) { + return + } + + a.t.FailNow() +} + // Len is the same as [Len], as a method rather than a package-level function. // // Upon failure, the test [T] is marked as failed and stops execution. @@ -1730,6 +1759,34 @@ func (a *Assertions) NotImplementsf(interfaceObject any, object any, msg string, a.t.FailNow() } +// NotKind is the same as [NotKind], as a method rather than a package-level function. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func (a *Assertions) NotKind(expectedKind reflect.Kind, object any, msgAndArgs ...any) { + if h, ok := a.t.(H); ok { + h.Helper() + } + if assertions.NotKind(a.t, expectedKind, object, msgAndArgs...) { + return + } + + a.t.FailNow() +} + +// NotKindf is the same as [Assertions.NotKind], but accepts a format msg string to format arguments like [fmt.Printf]. +// +// Upon failure, the test [T] is marked as failed and stops execution. +func (a *Assertions) NotKindf(expectedKind reflect.Kind, object any, msg string, args ...any) { + if h, ok := a.t.(H); ok { + h.Helper() + } + if assertions.NotKind(a.t, expectedKind, object, forwardArgs(msg, args)) { + return + } + + a.t.FailNow() +} + // NotNil is the same as [NotNil], as a method rather than a package-level function. // // Upon failure, the test [T] is marked as failed and stops execution. diff --git a/require/require_forward_test.go b/require/require_forward_test.go index 76a3d146a..f809f75a1 100644 --- a/require/require_forward_test.go +++ b/require/require_forward_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "path/filepath" + "reflect" "testing" "time" ) @@ -2140,6 +2141,55 @@ func TestAssertionsJSONEqBytesf(t *testing.T) { }) } +func TestAssertionsKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + a.Kind(reflect.String, "hello") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + a := New(mock) + a.Kind(reflect.String, 0) + // require functions don't return a value + if !mock.failed { + t.Error("Kind should call FailNow()") + } + }) +} + +func TestAssertionsKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + a.Kindf(reflect.String, "hello", "test message") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + a := New(mock) + a.Kindf(reflect.String, 0, "test message") + // require functions don't return a value + if !mock.failed { + t.Error("Assertions.Kind should mark test as failed") + } + if !mock.failed { + t.Error("Assertions.Kindf should call FailNow()") + } + }) +} + func TestAssertionsLen(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { @@ -2973,6 +3023,55 @@ func TestAssertionsNotImplementsf(t *testing.T) { }) } +func TestAssertionsNotKind(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + a.NotKind(reflect.String, 0) + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + a := New(mock) + a.NotKind(reflect.String, "hello") + // require functions don't return a value + if !mock.failed { + t.Error("NotKind should call FailNow()") + } + }) +} + +func TestAssertionsNotKindf(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + + a := New(t) + a.NotKindf(reflect.String, 0, "test message") + // require functions don't return a value + }) + + t.Run("failure", func(t *testing.T) { + t.Parallel() + + mock := new(mockFailNowT) + a := New(mock) + a.NotKindf(reflect.String, "hello", "test message") + // require functions don't return a value + if !mock.failed { + t.Error("Assertions.NotKind should mark test as failed") + } + if !mock.failed { + t.Error("Assertions.NotKindf should call FailNow()") + } + }) +} + func TestAssertionsNotNil(t *testing.T) { t.Parallel() t.Run("success", func(t *testing.T) { diff --git a/require/require_helpers.go b/require/require_helpers.go index 4a49efac6..bbbbbc772 100644 --- a/require/require_helpers.go +++ b/require/require_helpers.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require diff --git a/require/require_helpers_test.go b/require/require_helpers_test.go index f3fd8b9a5..f4f8ea917 100644 --- a/require/require_helpers_test.go +++ b/require/require_helpers_test.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require diff --git a/require/require_types.go b/require/require_types.go index a15626596..54ef701d8 100644 --- a/require/require_types.go +++ b/require/require_types.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Code generated with github.com/go-openapi/testify/codegen/v2; DO NOT EDIT. -// Generated on 2026-01-11 (version e6b0793) using codegen version v2.1.9-0.20260111152118-e6b0793ba519+dirty [sha: e6b0793ba519fb22dc1887392e1465649a5a95ff] +// Generated on 2026-01-11 (version ca82e58) using codegen version v2.1.9-0.20260111184010-ca82e58db12c+dirty [sha: ca82e58db12cbb61bfcae58c3684b3add9599d10] package require