MCPcopy Index your code
hub / github.com/maruel/panicparse / TestPanic

Function TestPanic

stack/context_test.go:1730–1793  ·  view source on GitHub ↗

TestPanic runs github.com/maruel/panicparse/v2/cmd/panic with every supported panic modes.

(t *testing.T)

Source from the content-addressed store, hash-verified

1728// TestPanic runs github.com/maruel/panicparse/v2/cmd/panic with every
1729// supported panic modes.
1730func TestPanic(t *testing.T) {
1731 t.Parallel()
1732 cmds := internaltest.PanicOutputs()
1733 want := map[string]int{
1734 "chan_receive": 2,
1735 "chan_send": 2,
1736 "goroutine_1": 2,
1737 "goroutine_dedupe_pointers": 101,
1738 "goroutine_100": 101,
1739 }
1740
1741 panicParseDir := getPanicParseDir(t)
1742 ppDir := pathJoin(panicParseDir, "cmd", "panic")
1743
1744 // Test runtime code. For those not in "custom", just assert that they
1745 // succeed.
1746 custom := map[string]func(*testing.T, *Snapshot, *bytes.Buffer, string){
1747 "args_elided": testPanicArgsElided,
1748 "mismatched": testPanicMismatched,
1749 "race": testPanicRace,
1750 "str": testPanicStr,
1751 "utf8": testPanicUTF8,
1752 }
1753 // Make sure all custom handlers are showing up in cmds.
1754 for n := range custom {
1755 if _, ok := cmds[n]; !ok {
1756 if n == "race" {
1757 t.Skip("race is unsupported")
1758 }
1759 t.Fatalf("untested mode %q:\n%v", n, cmds[n])
1760 }
1761 }
1762
1763 for cmd, data := range cmds {
1764 cmd := cmd
1765 data := data
1766 t.Run(cmd, func(t *testing.T) {
1767 t.Parallel()
1768 prefix := bytes.Buffer{}
1769 s, suffix, err := ScanSnapshot(bytes.NewReader(data), &prefix, defaultOpts())
1770 if err != nil && err != io.EOF {
1771 t.Fatal(err)
1772 }
1773 if s == nil {
1774 t.Fatal("context is nil")
1775 }
1776 if !s.guessPaths() {
1777 t.Fatal("expected GuessPaths to work")
1778 }
1779 if f := custom[cmd]; f != nil {
1780 f(t, s, &prefix, ppDir)
1781 return
1782 }
1783 e := want[cmd]
1784 if e == 0 {
1785 e = 1
1786 }
1787 if got := len(s.Goroutines); got != e {

Callers

nothing calls this directly

Calls 7

PanicOutputsFunction · 0.92
getPanicParseDirFunction · 0.85
pathJoinFunction · 0.85
ScanSnapshotFunction · 0.85
defaultOptsFunction · 0.85
guessPathsMethod · 0.80
compareStringFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…