(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestRegister(t *testing.T) { |
| 15 | current := len(handlers) |
| 16 | |
| 17 | var results []string |
| 18 | |
| 19 | h1 := func() { results = append(results, "first") } |
| 20 | h2 := func() { results = append(results, "second") } |
| 21 | |
| 22 | RegisterExitHandler(h1) |
| 23 | RegisterExitHandler(h2) |
| 24 | |
| 25 | if len(handlers) != current+2 { |
| 26 | t.Fatalf("expected %d handlers, got %d", current+2, len(handlers)) |
| 27 | } |
| 28 | |
| 29 | runHandlers() |
| 30 | |
| 31 | if len(results) != 2 { |
| 32 | t.Fatalf("expected 2 handlers to be run, ran %d", len(results)) |
| 33 | } |
| 34 | |
| 35 | if results[0] != "first" { |
| 36 | t.Fatal("expected handler h1 to be run first, but it wasn't") |
| 37 | } |
| 38 | |
| 39 | if results[1] != "second" { |
| 40 | t.Fatal("expected handler h2 to be run second, but it wasn't") |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestDefer(t *testing.T) { |
| 45 | current := len(handlers) |
nothing calls this directly
no test coverage detected