예제 #1
0
func TestCatchAll(t *testing.T) {
	mu := &sync.Mutex{}
	i := 0
	wg := &sync.WaitGroup{}

	handler := func(info sanepanic.Info) bool {
		blankInfo := sanepanic.Info{}
		if info == blankInfo {
			t.Errorf("No panic info exists")
		} else {
			t.Logf("Received valid panic data: %v", info)
		}

		mu.Lock()
		defer mu.Unlock()
		i++

		return true
	}

	sanepanic.SetHandlerFunc(handler)
	wg.Add(5)
	for i := 0; i < 5; i++ {
		go func() {
			defer wg.Done()
			defer sanepanic.Forward()
			panic("Arghlbarg")
		}()
	}

	wg.Wait()
}
예제 #2
0
func TestBasic(t *testing.T) {
	quit := make(chan struct{})
	handler := func(sanepanic.Info) bool {
		close(quit)
		return false
	}

	sanepanic.SetHandlerFunc(handler)

	go func() {
		defer sanepanic.Forward()
		panic("Oh no!")
	}()

	<-quit // Will deadlock if test fails
}