summaryrefslogtreecommitdiffstats
path: root/src/util/atexit_test.go
blob: 1ff85be857c0beb655e1b6849c5dbacfd0fcb761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package util

import (
	"reflect"
	"testing"
)

func TestAtExit(t *testing.T) {
	want := []int{3, 2, 1, 0}
	var called []int
	for i := 0; i < 4; i++ {
		n := i
		AtExit(func() { called = append(called, n) })
	}
	RunAtExitFuncs()
	if !reflect.DeepEqual(called, want) {
		t.Errorf("AtExit: want call order: %v got: %v", want, called)
	}

	RunAtExitFuncs()
	if !reflect.DeepEqual(called, want) {
		t.Error("AtExit: should only call exit funcs once")
	}
}