fix skip recursion

g-counter
Jordan Orelli 4 years ago
parent e3d906b28c
commit 6ef7afe907

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

@ -15,6 +15,9 @@ type testThingSetup struct {
func (test *testThingSetup) Run(t *testing.T) {
t.Logf("[%s] running testThingSetup", t.Name())
if test.thing != nil {
// t.Fatal("should be nil")
}
test.thing = new(Thing)
}
@ -55,7 +58,8 @@ func TestThing(t *testing.T) {
{
bob := root.Child(&setKey{key: "b ob", value: "banana"})
bob.Child(&setKey{key: "car-el", value: "cherry"})
bob.Child(&setKey{key: "dave", value: "durian"})
dave := bob.Child(&setKey{key: "dave", value: "durian"})
dave.Child(&setKey{key: "evan", value: "elderberry"})
}
{

Loading…
Cancel
Save