Skip to content

Commit

Permalink
Add some leak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Jan 3, 2015
1 parent d234f30 commit 142c3e1
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions list/listTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

. "github.com/zimmski/container/test/assert"
"github.com/zimmski/go-leak"
)

// V holds the value for basic list tests
Expand All @@ -19,23 +20,27 @@ type ListTest struct {

// Run executes all basic list tests
func (lt *ListTest) Run(t *testing.T) {
lt.NewFilledList(t)

lt.TestBasic(t)
lt.TestIterator(t)
lt.TestChannels(t)
lt.TestSlice(t)
lt.TestInserts(t)
lt.TestRemove(t)
lt.TestRemoveOccurrence(t)
lt.TestClear(t)
lt.TestCopy(t)
lt.TestIndexOf(t)
lt.TestGetSet(t)
lt.TestAddLists(t)
lt.TestFuncs(t)
lt.TestSwap(t)
lt.TestMoves(t)
Equal(t, 0, leak.GoRoutineLeaks(func() {
lt.NewFilledList(t)

lt.TestBasic(t)
lt.TestIterator(t)
lt.TestChannels(t)
lt.TestSlice(t)
lt.TestInserts(t)
lt.TestRemove(t)
lt.TestRemoveOccurrence(t)
lt.TestClear(t)
lt.TestCopy(t)
lt.TestIndexOf(t)
lt.TestGetSet(t)
lt.TestAddLists(t)
lt.TestFuncs(t)
lt.TestSwap(t)
lt.TestMoves(t)

lt.TestLeaks(t)
}))
}

// FillList fills up a given list with V
Expand Down Expand Up @@ -790,3 +795,26 @@ func (lt *ListTest) TestMoves(t *testing.T) {
Equal(t, l.Slice(), []interface{}{1, 4, 0, 2, 3, 0})
Equal(t, l.Len(), ll+1)
}

// TestLeaks test for leaks
func (lt *ListTest) TestLeaks(t *testing.T) {
l := lt.New(t)

Equal(t, 0, leak.MemoryLeaks(func() {
l.Push(1)
l.Push(2)
l.Push(3)

l.Pop()
l.Pop()
l.Pop()
}))

Equal(t, 0, leak.MemoryLeaks(func() {
l.Push(1)
l.Push(2)
l.Push(3)

l.Clear()
}))
}

0 comments on commit 142c3e1

Please sign in to comment.