|
|
@ -1,59 +1,52 @@
|
|
|
|
package tea
|
|
|
|
package tea
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
// "reflect"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Run runs a tree of tests, starting from its root.
|
|
|
|
// Run runs a tree of tests, starting from its root.
|
|
|
|
func Run(t *testing.T, tree *Tree) {
|
|
|
|
func Run(t *testing.T, tree *Tree) {
|
|
|
|
t.Run(tree.name, func(t *testing.T) {
|
|
|
|
t.Run(tree.name, func(t *testing.T) {
|
|
|
|
var setup []Test
|
|
|
|
setup(t, tree)
|
|
|
|
|
|
|
|
|
|
|
|
for root := tree; root.parent != nil; root = root.parent {
|
|
|
|
tree.test.Run(t)
|
|
|
|
setup = append(setup, root.parent.Test)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, j := 0, len(setup)-1; i < j; i, j = i+1, j-1 {
|
|
|
|
|
|
|
|
setup[i], setup[j] = setup[j], setup[i]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range setup {
|
|
|
|
|
|
|
|
test.Run(t)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tree.Test.Run(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if t.Failed() || t.Skipped() {
|
|
|
|
for _, child := range tree.children {
|
|
|
|
for _, child := range tree.children {
|
|
|
|
if t.Failed() || t.Skipped() {
|
|
|
|
skip(t, child)
|
|
|
|
skip(t, child)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Run(t, child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, child := range tree.children {
|
|
|
|
|
|
|
|
Run(t, child)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setup(t *testing.T, tree *Tree) {
|
|
|
|
|
|
|
|
if tree.parent != nil {
|
|
|
|
|
|
|
|
setup(t, tree.parent)
|
|
|
|
|
|
|
|
tree.parent.test.Run(t)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func skip(t *testing.T, tree *Tree) {
|
|
|
|
func skip(t *testing.T, tree *Tree) {
|
|
|
|
t.Run(tree.name, func(t *testing.T) {
|
|
|
|
t.Run(tree.name, func(t *testing.T) {
|
|
|
|
t.Skip("tea skipped: dependency failed")
|
|
|
|
|
|
|
|
for _, child := range tree.children {
|
|
|
|
for _, child := range tree.children {
|
|
|
|
skip(t, child)
|
|
|
|
skip(t, child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Skip("tea skipped: dependency failed")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func New(test Test) *Tree {
|
|
|
|
func New(test Test) *Tree {
|
|
|
|
return &Tree{
|
|
|
|
return &Tree{
|
|
|
|
Test: test,
|
|
|
|
test: test,
|
|
|
|
name: parseName(test),
|
|
|
|
name: parseName(test),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Tree struct {
|
|
|
|
type Tree struct {
|
|
|
|
Test
|
|
|
|
test Test
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
parent *Tree
|
|
|
|
parent *Tree
|
|
|
|
children []*Tree
|
|
|
|
children []*Tree
|
|
|
@ -66,6 +59,13 @@ func (t *Tree) Child(test Test) *Tree {
|
|
|
|
return child
|
|
|
|
return child
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// func clone(t Test) Test {
|
|
|
|
|
|
|
|
// T := reflect.TypeOf(t)
|
|
|
|
|
|
|
|
// switch T.Kind() {
|
|
|
|
|
|
|
|
// case reflect.Struct:
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
func parseName(test Test) string {
|
|
|
|
func parseName(test Test) string {
|
|
|
|
if s, ok := test.(interface{ String() string }); ok {
|
|
|
|
if s, ok := test.(interface{ String() string }); ok {
|
|
|
|
return s.String()
|
|
|
|
return s.String()
|
|
|
|