MCPcopy
hub / github.com/sirupsen/logrus / TestDefer

Function TestDefer

alt_exit_test.go:44–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func 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
74func TestHandler(t *testing.T) {
75 testprog := testprogleader

Callers

nothing calls this directly

Calls 4

DeferExitHandlerFunction · 0.85
runHandlersFunction · 0.85
FatalfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected