fix skip recursion

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

@ -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 { func setup(t *testing.T, tree *Tree) {
Run(t, child) 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()

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