Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions onpar.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ func (t *GroupTable[T, U, V]) Entry(name string, entry V) *GroupTable[T, U, V] {
return t
}

// FnEntry adds an entry to t that calls setup in order to get its entry value.
// The value from the BeforeEach will be passed to setup, and then both values
// will be passed to the table spec.
func (t *GroupTable[T, U, V]) FnEntry(name string, setup func(U) V) *GroupTable[T, U, V] {
return t
}

// Onpar stores the state of the specs and groups
type Onpar[T, U any] struct {
t TestRunner
Expand Down Expand Up @@ -386,9 +379,9 @@ func (s serialSpec[T]) name() string {

func (s serialSpec[T]) run(t *testing.T, scope func() testScope[T]) {
sc := scope()
t.Cleanup(sc.after)
v := sc.before(t)
s.f(v)
sc.after()
}

type levelScope[T, U any] struct {
Expand Down
25 changes: 25 additions & 0 deletions onpar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ func TestSingleNestedSpec(t *testing.T) {
}
}

func TestAfterEachAfterCleanup(t *testing.T) {
t.Parallel()

var lastRun string
t.Run("FakeSpecs", func(t *testing.T) {
o := onpar.BeforeEach(onpar.New(t), func(t *testing.T) *testing.T {
t.Cleanup(func() {
lastRun = "cleanup"
})
return t
})
defer o.Run()

o.AfterEach(func(t *testing.T) {
lastRun = "afterEach"
})

o.Spec("foo", func(t *testing.T) {})
})

if lastRun != "afterEach" {
t.Fatalf("expected afterEach to be the very last function to run, after all other test cleanup")
}
}

func TestInvokeFirstChildAndPeerSpec(t *testing.T) {
t.Parallel()
c := createScaffolding(t)
Expand Down