Skip to content

Commit 3c68ac0

Browse files
committed
interface{} -> any
1 parent 0be4a08 commit 3c68ac0

35 files changed

+170
-170
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Smarty
3+
Copyright (c) 2023 Smarty
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

assert/assert.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Result struct {
3636
// if err := assert.So(1, should.Equal, 1).Error(); err != nil {
3737
// // Allows custom handling of the error, which will include the failure message and file:line header.
3838
// }
39-
func So(actual interface{}, assert assertion, expected ...interface{}) *Result {
39+
func So(actual any, assert assertion, expected ...any) *Result {
4040
result := new(Result)
4141
result.stdout = os.Stdout
4242
result.invocation = fmt.Sprintf("So(actual: %v, %v, expected: %v)", actual, assertionName(assert), expected)
@@ -46,7 +46,7 @@ func So(actual interface{}, assert assertion, expected ...interface{}) *Result {
4646
}
4747
return result
4848
}
49-
func assertionName(i interface{}) string {
49+
func assertionName(i any) string {
5050
functionAddress := runtime.FuncForPC(reflect.ValueOf(i).Pointer())
5151
fullNameStartingWithPackage := functionAddress.Name()
5252
parts := strings.Split(fullNameStartingWithPackage, "/")
@@ -114,4 +114,4 @@ func (this *Result) Fatal() *Result {
114114
}
115115

116116
// assertion is a copy of github.com/smartystreets/assertions.assertion.
117-
type assertion func(actual interface{}, expected ...interface{}) string
117+
type assertion func(actual any, expected ...any) string

assert/logger.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func capture() *logger {
3434
}
3535

3636
// Fatal -> log.Fatal (except in testing it uses log.Print)
37-
func (this *logger) Fatal(v ...interface{}) {
37+
func (this *logger) Fatal(v ...any) {
3838
if this == nil {
3939
this.Output(3, fmt.Sprint(v...))
4040
os.Exit(1)
@@ -45,7 +45,7 @@ func (this *logger) Fatal(v ...interface{}) {
4545
}
4646

4747
// Panic -> log.Panic
48-
func (this *logger) Panic(v ...interface{}) {
48+
func (this *logger) Panic(v ...any) {
4949
if this == nil {
5050
s := fmt.Sprint(v...)
5151
this.Output(3, s)
@@ -57,7 +57,7 @@ func (this *logger) Panic(v ...interface{}) {
5757
}
5858

5959
// Print -> log.Print
60-
func (this *logger) Print(v ...interface{}) {
60+
func (this *logger) Print(v ...any) {
6161
if this == nil {
6262
this.Output(3, fmt.Sprint(v...))
6363
} else {

collections.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
// ShouldContain receives exactly two parameters. The first is a slice and the
1111
// second is a proposed member. Membership is determined using ShouldEqual.
12-
func ShouldContain(actual interface{}, expected ...interface{}) string {
12+
func ShouldContain(actual any, expected ...any) string {
1313
if fail := need(1, expected); fail != success {
1414
return fail
1515
}
@@ -27,7 +27,7 @@ func ShouldContain(actual interface{}, expected ...interface{}) string {
2727

2828
// ShouldNotContain receives exactly two parameters. The first is a slice and the
2929
// second is a proposed member. Membership is determined using ShouldEqual.
30-
func ShouldNotContain(actual interface{}, expected ...interface{}) string {
30+
func ShouldNotContain(actual any, expected ...any) string {
3131
if fail := need(1, expected); fail != success {
3232
return fail
3333
}
@@ -44,7 +44,7 @@ func ShouldNotContain(actual interface{}, expected ...interface{}) string {
4444

4545
// ShouldContainKey receives exactly two parameters. The first is a map and the
4646
// second is a proposed key. Keys are compared with a simple '=='.
47-
func ShouldContainKey(actual interface{}, expected ...interface{}) string {
47+
func ShouldContainKey(actual any, expected ...any) string {
4848
if fail := need(1, expected); fail != success {
4949
return fail
5050
}
@@ -63,7 +63,7 @@ func ShouldContainKey(actual interface{}, expected ...interface{}) string {
6363

6464
// ShouldNotContainKey receives exactly two parameters. The first is a map and the
6565
// second is a proposed absent key. Keys are compared with a simple '=='.
66-
func ShouldNotContainKey(actual interface{}, expected ...interface{}) string {
66+
func ShouldNotContainKey(actual any, expected ...any) string {
6767
if fail := need(1, expected); fail != success {
6868
return fail
6969
}
@@ -80,14 +80,14 @@ func ShouldNotContainKey(actual interface{}, expected ...interface{}) string {
8080
return ""
8181
}
8282

83-
func mapKeys(m interface{}) ([]reflect.Value, bool) {
83+
func mapKeys(m any) ([]reflect.Value, bool) {
8484
value := reflect.ValueOf(m)
8585
if value.Kind() != reflect.Map {
8686
return nil, false
8787
}
8888
return value.MapKeys(), true
8989
}
90-
func keyFound(keys []reflect.Value, expectedKey interface{}) bool {
90+
func keyFound(keys []reflect.Value, expectedKey any) bool {
9191
found := false
9292
for _, key := range keys {
9393
if key.Interface() == expectedKey {
@@ -101,7 +101,7 @@ func keyFound(keys []reflect.Value, expectedKey interface{}) bool {
101101
// that is passed in either as the second parameter, or of the collection that consists
102102
// of all the remaining parameters. This assertion ensures that the proposed member is in
103103
// the collection (using ShouldEqual).
104-
func ShouldBeIn(actual interface{}, expected ...interface{}) string {
104+
func ShouldBeIn(actual any, expected ...any) string {
105105
if fail := atLeast(1, expected); fail != success {
106106
return fail
107107
}
@@ -111,7 +111,7 @@ func ShouldBeIn(actual interface{}, expected ...interface{}) string {
111111
}
112112
return shouldBeIn(actual, expected)
113113
}
114-
func shouldBeIn(actual interface{}, expected interface{}) string {
114+
func shouldBeIn(actual any, expected any) string {
115115
if matchError := oglematchers.Contains(actual).Matches(expected); matchError != nil {
116116
return fmt.Sprintf(shouldHaveBeenIn, actual, reflect.TypeOf(expected))
117117
}
@@ -122,7 +122,7 @@ func shouldBeIn(actual interface{}, expected interface{}) string {
122122
// that is passed in either as the second parameter, or of the collection that consists
123123
// of all the remaining parameters. This assertion ensures that the proposed member is NOT in
124124
// the collection (using ShouldEqual).
125-
func ShouldNotBeIn(actual interface{}, expected ...interface{}) string {
125+
func ShouldNotBeIn(actual any, expected ...any) string {
126126
if fail := atLeast(1, expected); fail != success {
127127
return fail
128128
}
@@ -132,7 +132,7 @@ func ShouldNotBeIn(actual interface{}, expected ...interface{}) string {
132132
}
133133
return shouldNotBeIn(actual, expected)
134134
}
135-
func shouldNotBeIn(actual interface{}, expected interface{}) string {
135+
func shouldNotBeIn(actual any, expected any) string {
136136
if matchError := oglematchers.Contains(actual).Matches(expected); matchError == nil {
137137
return fmt.Sprintf(shouldNotHaveBeenIn, actual, reflect.TypeOf(expected))
138138
}
@@ -142,7 +142,7 @@ func shouldNotBeIn(actual interface{}, expected interface{}) string {
142142
// ShouldBeEmpty receives a single parameter (actual) and determines whether
143143
// calling len(actual) would return `0`. It obeys the rules specified by the len
144144
// function for determining length: http://golang.org/pkg/builtin/#len
145-
func ShouldBeEmpty(actual interface{}, expected ...interface{}) string {
145+
func ShouldBeEmpty(actual any, expected ...any) string {
146146
if fail := need(0, expected); fail != success {
147147
return fail
148148
}
@@ -183,7 +183,7 @@ func ShouldBeEmpty(actual interface{}, expected ...interface{}) string {
183183
// ShouldNotBeEmpty receives a single parameter (actual) and determines whether
184184
// calling len(actual) would return a value greater than zero. It obeys the rules
185185
// specified by the `len` function for determining length: http://golang.org/pkg/builtin/#len
186-
func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string {
186+
func ShouldNotBeEmpty(actual any, expected ...any) string {
187187
if fail := need(0, expected); fail != success {
188188
return fail
189189
}
@@ -198,7 +198,7 @@ func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string {
198198
// the length of, the second being the expected length. It obeys the rules
199199
// specified by the len function for determining length:
200200
// http://golang.org/pkg/builtin/#len
201-
func ShouldHaveLength(actual interface{}, expected ...interface{}) string {
201+
func ShouldHaveLength(actual any, expected ...any) string {
202202
if fail := need(1, expected); fail != success {
203203
return fail
204204
}

collections_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (this *AssertionsFixture) TestShouldBeEmpty() {
9191

9292
this.pass(so([]int{}, ShouldBeEmpty)) // empty slice
9393
this.pass(so([][]int{}, ShouldBeEmpty)) // empty slice
94-
this.pass(so([]interface{}{}, ShouldBeEmpty)) // empty slice
94+
this.pass(so([]any{}, ShouldBeEmpty)) // empty slice
9595
this.pass(so(map[string]int{}, ShouldBeEmpty)) // empty map
9696
this.pass(so("", ShouldBeEmpty)) // empty string
9797
this.pass(so(&[]int{}, ShouldBeEmpty)) // pointer to empty slice
@@ -101,7 +101,7 @@ func (this *AssertionsFixture) TestShouldBeEmpty() {
101101

102102
this.fail(so([]int{1}, ShouldBeEmpty), "Expected [1] to be empty (but it wasn't)!") // non-empty slice
103103
this.fail(so([][]int{{1}}, ShouldBeEmpty), "Expected [[1]] to be empty (but it wasn't)!") // non-empty slice
104-
this.fail(so([]interface{}{1}, ShouldBeEmpty), "Expected [1] to be empty (but it wasn't)!") // non-empty slice
104+
this.fail(so([]any{1}, ShouldBeEmpty), "Expected [1] to be empty (but it wasn't)!") // non-empty slice
105105
this.fail(so(map[string]int{"hi": 0}, ShouldBeEmpty), "Expected map[hi:0] to be empty (but it wasn't)!") // non-empty map
106106
this.fail(so("hi", ShouldBeEmpty), "Expected hi to be empty (but it wasn't)!") // non-empty string
107107
this.fail(so(&[]int{1}, ShouldBeEmpty), "Expected &[1] to be empty (but it wasn't)!") // pointer to non-empty slice
@@ -116,7 +116,7 @@ func (this *AssertionsFixture) TestShouldNotBeEmpty() {
116116
this.fail(so(1, ShouldNotBeEmpty, 2, 3), "This assertion requires exactly 0 comparison values (you provided 2).")
117117

118118
this.fail(so([]int{}, ShouldNotBeEmpty), "Expected [] to NOT be empty (but it was)!") // empty slice
119-
this.fail(so([]interface{}{}, ShouldNotBeEmpty), "Expected [] to NOT be empty (but it was)!") // empty slice
119+
this.fail(so([]any{}, ShouldNotBeEmpty), "Expected [] to NOT be empty (but it was)!") // empty slice
120120
this.fail(so(map[string]int{}, ShouldNotBeEmpty), "Expected map[] to NOT be empty (but it was)!") // empty map
121121
this.fail(so("", ShouldNotBeEmpty), "Expected to NOT be empty (but it was)!") // empty string
122122
this.fail(so(&[]int{}, ShouldNotBeEmpty), "Expected &[] to NOT be empty (but it was)!") // pointer to empty slice
@@ -126,7 +126,7 @@ func (this *AssertionsFixture) TestShouldNotBeEmpty() {
126126
this.fail(so(c, ShouldNotBeEmpty), fmt.Sprintf("Expected %+v to NOT be empty (but it was)!", c)) // empty channel
127127

128128
this.pass(so([]int{1}, ShouldNotBeEmpty)) // non-empty slice
129-
this.pass(so([]interface{}{1}, ShouldNotBeEmpty)) // non-empty slice
129+
this.pass(so([]any{1}, ShouldNotBeEmpty)) // non-empty slice
130130
this.pass(so(map[string]int{"hi": 0}, ShouldNotBeEmpty)) // non-empty map
131131
this.pass(so("hi", ShouldNotBeEmpty)) // non-empty string
132132
this.pass(so(&[]int{1}, ShouldNotBeEmpty)) // pointer to non-empty slice
@@ -148,7 +148,7 @@ func (this *AssertionsFixture) TestShouldHaveLength() {
148148
this.fail(so([]int{}, ShouldHaveLength, 1), // empty slice
149149
"Expected collection to have length equal to [1], but its length was [0] instead! contents: []")
150150

151-
this.fail(so([]interface{}{}, ShouldHaveLength, 1), // empty slice
151+
this.fail(so([]any{}, ShouldHaveLength, 1), // empty slice
152152
"Expected collection to have length equal to [1], but its length was [0] instead! contents: []")
153153

154154
this.fail(so(map[string]int{}, ShouldHaveLength, 1), // empty map
@@ -172,7 +172,7 @@ func (this *AssertionsFixture) TestShouldHaveLength() {
172172
"Expected collection to have length equal to [1], but its length was [0] instead! contents: %+v", c))
173173

174174
this.pass(so([]int{1}, ShouldHaveLength, 1)) // non-empty slice
175-
this.pass(so([]interface{}{1}, ShouldHaveLength, 1)) // non-empty slice
175+
this.pass(so([]any{1}, ShouldHaveLength, 1)) // non-empty slice
176176
this.pass(so(map[string]int{"hi": 0}, ShouldHaveLength, 1)) // non-empty map
177177
this.pass(so("hi", ShouldHaveLength, 2)) // non-empty string
178178
this.pass(so(&[]int{1}, ShouldHaveLength, 1)) // pointer to non-empty slice

doc.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func GoConveyMode(yes bool) {
3838
}
3939

4040
type testingT interface {
41-
Error(args ...interface{})
41+
Error(args ...any)
4242
}
4343

4444
type Assertion struct {
@@ -58,7 +58,7 @@ func (this *Assertion) Failed() bool {
5858
}
5959

6060
// So calls the standalone So function and additionally, calls t.Error in failure scenarios.
61-
func (this *Assertion) So(actual interface{}, assert SoFunc, expected ...interface{}) bool {
61+
func (this *Assertion) So(actual any, assert SoFunc, expected ...any) bool {
6262
ok, result := So(actual, assert, expected...)
6363
if !ok {
6464
this.failed = true
@@ -86,7 +86,7 @@ func (this *Assertion) So(actual interface{}, assert SoFunc, expected ...interfa
8686
//
8787
// For an alternative implementation of So (that provides more flexible return options)
8888
// see the `So` function in the package at github.com/smartystreets/assertions/assert.
89-
func So(actual interface{}, assert SoFunc, expected ...interface{}) (bool, string) {
89+
func So(actual any, assert SoFunc, expected ...any) (bool, string) {
9090
if result := so(actual, assert, expected...); len(result) == 0 {
9191
return true, result
9292
} else {
@@ -96,14 +96,14 @@ func So(actual interface{}, assert SoFunc, expected ...interface{}) (bool, strin
9696

9797
// so is like So, except that it only returns the string message, which is blank if the
9898
// assertion passed. Used to facilitate testing.
99-
func so(actual interface{}, assert SoFunc, expected ...interface{}) string {
99+
func so(actual any, assert SoFunc, expected ...any) string {
100100
return assert(actual, expected...)
101101
}
102102

103103
// SoFunc is an alias for a function with a signature that the So()
104104
// function can handle. Any future or custom assertions should conform to this
105105
// method signature. The return value should be an empty string if the SoFunc
106106
// passes and a well-formed failure message if not.
107-
type SoFunc func(actual interface{}, expected ...interface{}) string
107+
type SoFunc func(actual any, expected ...any) string
108108

109109
////////////////////////////////////////////////////////////////////////////

doc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ type FakeT struct {
6969
buffer *bytes.Buffer
7070
}
7171

72-
func (this *FakeT) Error(args ...interface{}) {
72+
func (this *FakeT) Error(args ...any) {
7373
fmt.Fprint(this.buffer, args...)
7474
}

equal_method.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package assertions
33
import "reflect"
44

55
type equalityMethodSpecification struct {
6-
a interface{}
7-
b interface{}
6+
a any
7+
b any
88

99
aType reflect.Type
1010
bType reflect.Type
1111

1212
equalMethod reflect.Value
1313
}
1414

15-
func newEqualityMethodSpecification(a, b interface{}) *equalityMethodSpecification {
15+
func newEqualityMethodSpecification(a, b any) *equalityMethodSpecification {
1616
return &equalityMethodSpecification{
1717
a: a,
1818
b: b,

0 commit comments

Comments
 (0)