From e3d906b28c1a0b6ff746257e095230d44b93dbfb Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 25 Jul 2020 17:11:53 +0000 Subject: [PATCH] setup steps are in correct subtest now --- tea/tree.go | 15 ++++++++++++++- tea_test.go | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tea/tree.go b/tea/tree.go index 8ed10e4..c9eddf0 100644 --- a/tea/tree.go +++ b/tea/tree.go @@ -7,6 +7,20 @@ import ( // 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 + + 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) if t.Failed() || t.Skipped() { @@ -17,7 +31,6 @@ func Run(t *testing.T, tree *Tree) { } for _, child := range tree.children { - tree.Test.Run(t) Run(t, child) } }) diff --git a/tea_test.go b/tea_test.go index 834f3f3..0eaa6bf 100644 --- a/tea_test.go +++ b/tea_test.go @@ -14,6 +14,7 @@ type testThingSetup struct { } func (test *testThingSetup) Run(t *testing.T) { + t.Logf("[%s] running testThingSetup", t.Name()) test.thing = new(Thing) } @@ -30,6 +31,7 @@ func (test setKey) String() string { } func (test *setKey) Run(t *testing.T) { + t.Logf("[%s] running setKey key: %q value: %q", t.Name(), test.key, test.value) thing := new(Thing) err := thing.Set(test.key, test.value)