fix: use t.Run in tests instead of for{} with i

This commit is contained in:
Adrien Marquès 2019-05-04 10:35:29 +02:00
parent 21f48a65ee
commit be84c86172
4 changed files with 116 additions and 92 deletions

View File

@ -2,6 +2,7 @@ package multipart
import (
"bytes"
"fmt"
"testing"
)
@ -186,17 +187,20 @@ func TestNoName(t *testing.T) {
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
mpr, err := NewReader(bytes.NewReader(test.Input), test.Boundary)
if err != nil {
t.Errorf("%d: unexpected error <%s>", i, err)
continue
t.Errorf("unexpected error <%s>", err)
return
}
if err = mpr.Parse(); err != ErrMissingDataName {
t.Errorf("%d: expected the error <%s>, got <%s>", i, ErrMissingDataName, err)
continue
t.Errorf("expected the error <%s>, got <%s>", ErrMissingDataName, err)
return
}
})
}
@ -225,18 +229,20 @@ func TestNoHeader(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
mpr, err := NewReader(bytes.NewReader(test.Input), test.Boundary)
if err != nil {
t.Errorf("%d: unexpected error <%s>", i, err)
continue
t.Errorf("unexpected error <%s>", err)
return
}
if err = mpr.Parse(); err != ErrNoHeader {
t.Errorf("%d: expected the error <%s>, got <%s>", i, ErrNoHeader, err)
continue
t.Errorf("expected the error <%s>, got <%s>", ErrNoHeader, err)
return
}
})
}

View File

@ -1,6 +1,7 @@
package builtin_test
import (
"fmt"
"testing"
"git.xdrm.io/go/aicra/typecheck/builtin"
@ -74,10 +75,12 @@ func TestAny_AlwaysTrue(t *testing.T) {
}
for i, value := range values {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
if !checker(value) {
t.Errorf("%d: expect value to be valid", i)
t.Errorf("expect value to be valid")
t.Fail()
}
})
}
}

View File

@ -1,6 +1,7 @@
package builtin_test
import (
"fmt"
"math"
"testing"
@ -38,18 +39,21 @@ func TestInt_AvailableTypes(t *testing.T) {
}
for _, test := range tests {
t.Run(test.Type, func(t *testing.T) {
checker := inst.Checker(test.Type)
if checker == nil {
if test.Handled {
t.Errorf("expect %q to be handled", test.Type)
t.Fail()
}
continue
return
}
if !test.Handled {
t.Errorf("expect %q NOT to be handled", test.Type)
t.Fail()
}
})
}
}
@ -96,17 +100,19 @@ func TestInt_Values(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
if checker(test.Value) {
if !test.Valid {
t.Errorf("%d: expect value to be invalid", i)
t.Errorf("expect value to be invalid")
t.Fail()
}
continue
return
}
if test.Valid {
t.Errorf("%d: expect value to be valid", i)
t.Errorf("expect value to be valid")
t.Fail()
}
})
}
}

View File

@ -1,6 +1,7 @@
package builtin_test
import (
"fmt"
"testing"
"git.xdrm.io/go/aicra/typecheck/builtin"
@ -52,18 +53,20 @@ func TestString_AvailableTypes(t *testing.T) {
}
for _, test := range tests {
t.Run(test.Type, func(t *testing.T) {
checker := inst.Checker(test.Type)
if checker == nil {
if test.Handled {
t.Errorf("expect %q to be handled", test.Type)
}
continue
return
}
if !test.Handled {
t.Errorf("expect %q NOT to be handled", test.Type)
}
})
}
}
@ -91,18 +94,20 @@ func TestString_AnyLength(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
if checker(test.Value) {
if !test.Valid {
t.Errorf("%d: expect value to be invalid", i)
t.Errorf("expect value to be invalid")
t.Fail()
}
continue
return
}
if test.Valid {
t.Errorf("%d: expect value to be valid", i)
t.Errorf("expect value to be valid")
t.Fail()
}
})
}
}
@ -128,25 +133,27 @@ func TestString_FixedLength(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
checker := builtin.NewString().Checker(test.Type)
if checker == nil {
t.Errorf("%d: expect %q to be handled", i, test.Type)
t.Errorf("expect %q to be handled", test.Type)
t.Fail()
continue
return
}
if checker(test.Value) {
if !test.Valid {
t.Errorf("%d: expect value to be invalid", i)
t.Errorf("expect value to be invalid")
t.Fail()
}
continue
return
}
if test.Valid {
t.Errorf("%d: expect value to be valid", i)
t.Errorf("expect value to be valid")
t.Fail()
}
})
}
}
@ -187,25 +194,27 @@ func TestString_VariableLength(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
checker := builtin.NewString().Checker(test.Type)
if checker == nil {
t.Errorf("%d: expect %q to be handled", i, test.Type)
t.Errorf("expect %q to be handled", test.Type)
t.Fail()
continue
return
}
if checker(test.Value) {
if !test.Valid {
t.Errorf("%d: expect value to be invalid", i)
t.Errorf("expect value to be invalid")
t.Fail()
}
continue
return
}
if test.Valid {
t.Errorf("%d: expect value to be valid", i)
t.Errorf("expect value to be valid")
t.Fail()
}
})
}
}