we gettin crazy now

g-counter
Jordan Orelli 4 years ago
parent 96d2a13aa7
commit e1fc2529e9

@ -2,6 +2,7 @@ package tea
import (
"fmt"
"reflect"
"testing"
)
@ -31,3 +32,21 @@ func (f failure) Run(t *testing.T) {
type empty struct{}
func (e empty) Run(t *testing.T) {}
// parseName parses the name for a given test
func parseName(test Test) string {
if s, ok := test.(interface{ String() string }); ok {
return s.String()
}
tv := reflect.ValueOf(test)
switch tv.Type().Kind() {
case reflect.Ptr:
tv = tv.Elem()
}
name := tv.Type().Name()
if name == "" {
return "unknown-test"
}
return name
}

@ -0,0 +1,34 @@
package tea
import (
"testing"
)
type nameless struct{}
func (nameless) Run(t *testing.T) {}
func TestNames(t *testing.T) {
testTests := []struct {
testToTest Test
expectedName string
}{
{
testToTest: nameless{},
expectedName: "nameless",
},
{
testToTest: &nameless{},
expectedName: "nameless",
},
}
for _, doubleTest := range testTests {
name := parseName(doubleTest.testToTest)
if name != doubleTest.expectedName {
t.Errorf("saw name %q expecting %q", name, doubleTest.expectedName)
} else {
t.Logf("test %v has expected name %q", doubleTest.testToTest, name)
}
}
}

@ -130,12 +130,3 @@ func isLoadField(f reflect.StructField) bool {
}
return false
}
// parseName parses the name for a given test
func parseName(test Test) string {
if s, ok := test.(interface{ String() string }); ok {
return s.String()
}
iv := reflect.ValueOf(test)
return iv.Type().Name()
}

Loading…
Cancel
Save