1// Copyright 2023 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package trace
6
7import "testing"
8
9func TestPanicEvent(t *testing.T) {
10	// Use a sync event for this because it doesn't have any extra metadata.
11	ev := syncEvent(nil, 0)
12
13	mustPanic(t, func() {
14		_ = ev.Range()
15	})
16	mustPanic(t, func() {
17		_ = ev.Metric()
18	})
19	mustPanic(t, func() {
20		_ = ev.Log()
21	})
22	mustPanic(t, func() {
23		_ = ev.Task()
24	})
25	mustPanic(t, func() {
26		_ = ev.Region()
27	})
28	mustPanic(t, func() {
29		_ = ev.Label()
30	})
31	mustPanic(t, func() {
32		_ = ev.RangeAttributes()
33	})
34}
35
36func mustPanic(t *testing.T, f func()) {
37	defer func() {
38		if r := recover(); r == nil {
39			t.Fatal("failed to panic")
40		}
41	}()
42	f()
43}
44