Skip to content

Commit

Permalink
no use variadic expanse in internals
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Feb 17, 2024
1 parent 097ce05 commit ddb444c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
74 changes: 37 additions & 37 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func tester() (t testing.TB) {

// NotImplemented always panics with 'not implemented' assertion message.
func NotImplemented(a ...any) {
Default().reportAssertionFault("not implemented", a...)
Default().reportAssertionFault("not implemented", a)
}

// ThatNot asserts that the term is NOT true. If is it panics with the given
Expand All @@ -269,7 +269,7 @@ func NotImplemented(a ...any) {
func ThatNot(term bool, a ...any) {
if term {
defMsg := "ThatNot: " + assertionMsg
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -279,7 +279,7 @@ func ThatNot(term bool, a ...any) {
func That(term bool, a ...any) {
if !term {
defMsg := "That: " + assertionMsg
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -288,7 +288,7 @@ func That(term bool, a ...any) {
func NotNil[P ~*T, T any](p P, a ...any) {
if p == nil {
defMsg := assertionMsg + ": pointer shouldn't be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -297,7 +297,7 @@ func NotNil[P ~*T, T any](p P, a ...any) {
func Nil[T any](p *T, a ...any) {
if p != nil {
defMsg := assertionMsg + ": pointer should be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -311,7 +311,7 @@ func Nil[T any](p *T, a ...any) {
func INil(i any, a ...any) {
if i != nil {
defMsg := assertionMsg + ": interface should be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -325,7 +325,7 @@ func INil(i any, a ...any) {
func INotNil(i any, a ...any) {
if i == nil {
defMsg := assertionMsg + ": interface shouldn't be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -334,7 +334,7 @@ func INotNil(i any, a ...any) {
func SNil[S ~[]T, T any](s S, a ...any) {
if s != nil {
defMsg := assertionMsg + ": slice should be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -343,7 +343,7 @@ func SNil[S ~[]T, T any](s S, a ...any) {
func SNotNil[S ~[]T, T any](s S, a ...any) {
if s == nil {
defMsg := assertionMsg + ": slice shouldn't be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -352,7 +352,7 @@ func SNotNil[S ~[]T, T any](s S, a ...any) {
func CNotNil[C ~chan T, T any](c C, a ...any) {
if c == nil {
defMsg := assertionMsg + ": channel shouldn't be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -361,7 +361,7 @@ func CNotNil[C ~chan T, T any](c C, a ...any) {
func MNotNil[M ~map[T]U, T comparable, U any](m M, a ...any) {
if m == nil {
defMsg := assertionMsg + ": map shouldn't be nil"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -371,7 +371,7 @@ func MNotNil[M ~map[T]U, T comparable, U any](m M, a ...any) {
func NotEqual[T comparable](val, want T, a ...any) {
if want == val {
defMsg := fmt.Sprintf(assertionMsg+": got '%v' want (!= '%v')", val, want)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -381,7 +381,7 @@ func NotEqual[T comparable](val, want T, a ...any) {
func Equal[T comparable](val, want T, a ...any) {
if want != val {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, val, want)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -392,7 +392,7 @@ func Equal[T comparable](val, want T, a ...any) {
func DeepEqual(val, want any, a ...any) {
if !reflect.DeepEqual(val, want) {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, val, want)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -408,7 +408,7 @@ func DeepEqual(val, want any, a ...any) {
func NotDeepEqual(val, want any, a ...any) {
if reflect.DeepEqual(val, want) {
defMsg := fmt.Sprintf(assertionMsg+": got '%v', want (!= '%v')", val, want)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -424,7 +424,7 @@ func Len(obj string, length int, a ...any) {

if l != length {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -440,7 +440,7 @@ func Longer(obj string, length int, a ...any) {

if l > length {
defMsg := fmt.Sprintf(assertionMsg+gotWantLongerFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -456,7 +456,7 @@ func Shorter(obj string, length int, a ...any) {

if l <= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantShorterFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -472,7 +472,7 @@ func SLen[S ~[]T, T any](obj S, length int, a ...any) {

if l != length {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -488,7 +488,7 @@ func SLonger[S ~[]T, T any](obj S, length int, a ...any) {

if l <= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantLongerFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -504,7 +504,7 @@ func SShorter[S ~[]T, T any](obj S, length int, a ...any) {

if l >= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantShorterFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -520,7 +520,7 @@ func MLen[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {

if l != length {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -536,7 +536,7 @@ func MLonger[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {

if l <= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantLongerFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -552,7 +552,7 @@ func MShorter[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {

if l >= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantShorterFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -568,7 +568,7 @@ func CLen[C ~chan T, T any](obj C, length int, a ...any) {

if l != length {
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -584,7 +584,7 @@ func CLonger[C ~chan T, T any](obj C, length int, a ...any) {

if l <= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantLongerFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -600,7 +600,7 @@ func CShorter[C ~chan T, T any](obj C, length int, a ...any) {

if l >= length {
defMsg := fmt.Sprintf(assertionMsg+gotWantShorterFmt, l, length)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -612,7 +612,7 @@ func MKeyExists[M ~map[T]U, T comparable, U any](obj M, key T, a ...any) (val U)

if !ok {
defMsg := fmt.Sprintf(assertionMsg+": key '%v' doesn't exist", key)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
return val
}
Expand All @@ -623,7 +623,7 @@ func MKeyExists[M ~map[T]U, T comparable, U any](obj M, key T, a ...any) (val U)
func NotEmpty(obj string, a ...any) {
if obj == "" {
defMsg := assertionMsg + ": string shouldn't be empty"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -633,7 +633,7 @@ func NotEmpty(obj string, a ...any) {
func Empty(obj string, a ...any) {
if obj != "" {
defMsg := assertionMsg + ": string should be empty"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -648,7 +648,7 @@ func SNotEmpty[S ~[]T, T any](obj S, a ...any) {

if l == 0 {
defMsg := assertionMsg + ": slice shouldn't be empty"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -665,7 +665,7 @@ func MNotEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {

if l == 0 {
defMsg := assertionMsg + ": map shouldn't be empty"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -681,7 +681,7 @@ func MNotEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {
func NoError(err error, a ...any) {
if err != nil {
defMsg := "NoError:" + assertionMsg + conCatErrStr + err.Error()
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -691,7 +691,7 @@ func NoError(err error, a ...any) {
func Error(err error, a ...any) {
if err == nil {
defMsg := "Error:" + assertionMsg + ": missing error"
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -701,7 +701,7 @@ func Error(err error, a ...any) {
func Zero[T Number](val T, a ...any) {
if val != 0 {
defMsg := fmt.Sprintf(assertionMsg+": got '%v', want (== '0')", val)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand All @@ -711,7 +711,7 @@ func Zero[T Number](val T, a ...any) {
func NotZero[T Number](val T, a ...any) {
if val == 0 {
defMsg := fmt.Sprintf(assertionMsg+": got '%v', want (!= 0)", val)
Default().reportAssertionFault(defMsg, a...)
Default().reportAssertionFault(defMsg, a)
}
}

Expand Down Expand Up @@ -793,7 +793,7 @@ func newDefInd(v string) defInd {
func combineArgs(format string, a []any) []any {
args := make([]any, 1, len(a)+1)
args[0] = format
args = append(args, a...)
args = append(args, a)
return args
}

Expand Down
2 changes: 1 addition & 1 deletion assert/asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const officialTestOutputPrefix = " "
// Note. We use the pattern where we build defaultMsg argument reaady in cases
// like 'got: X, want: Y'. This hits two birds with one stone: we have automatic
// and correct assert messages, and we can add information to it if we want to.
func (asserter Asserter) reportAssertionFault(defaultMsg string, a ...any) {
func (asserter Asserter) reportAssertionFault(defaultMsg string, a []any) {
if asserter.hasStackTrace() {
if asserter.isUnitTesting() {
// Note. that the assert in the test function is printed in
Expand Down

0 comments on commit ddb444c

Please sign in to comment.