10 func TestRegister(t *testing.T) {
11 current := len(handlers)
12 RegisterExitHandler(func() {})
13 if len(handlers) != current+1 {
14 t.Fatalf("can't add handler")
18 func TestHandler(t *testing.T) {
19 gofile := "/tmp/testprog.go"
20 if err := ioutil.WriteFile(gofile, testprog, 0666); err != nil {
21 t.Fatalf("can't create go file")
24 outfile := "/tmp/testprog.out"
25 arg := time.Now().UTC().String()
26 err := exec.Command("go", "run", gofile, outfile, arg).Run()
28 t.Fatalf("completed normally, should have failed")
31 data, err := ioutil.ReadFile(outfile)
33 t.Fatalf("can't read output file %s", outfile)
36 if string(data) != arg {
41 var testprog = []byte(`
42 // Test program for atexit, gets output file and data as arguments and writes
43 // data to output file in atexit handler.
47 "github.com/Sirupsen/logrus"
57 ioutil.WriteFile(outfile, []byte(data), 0666)
70 logrus.RegisterExitHandler(handler)
71 logrus.RegisterExitHandler(badHandler)
72 logrus.Fatal("Bye bye")