(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func TestDefer(t *testing.T) { |
| 45 | current := len(handlers) |
| 46 | |
| 47 | var results []string |
| 48 | |
| 49 | h1 := func() { results = append(results, "first") } |
| 50 | h2 := func() { results = append(results, "second") } |
| 51 | |
| 52 | DeferExitHandler(h1) |
| 53 | DeferExitHandler(h2) |
| 54 | |
| 55 | if len(handlers) != current+2 { |
| 56 | t.Fatalf("expected %d handlers, got %d", current+2, len(handlers)) |
| 57 | } |
| 58 | |
| 59 | runHandlers() |
| 60 | |
| 61 | if len(results) != 2 { |
| 62 | t.Fatalf("expected 2 handlers to be run, ran %d", len(results)) |
| 63 | } |
| 64 | |
| 65 | if results[0] != "second" { |
| 66 | t.Fatal("expected handler h2 to be run first, but it wasn't") |
| 67 | } |
| 68 | |
| 69 | if results[1] != "first" { |
| 70 | t.Fatal("expected handler h1 to be run second, but it wasn't") |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func TestHandler(t *testing.T) { |
| 75 | testprog := testprogleader |
nothing calls this directly
no test coverage detected