MCPcopy Create free account
hub / github.com/google/pprof / TestShell

Function TestShell

internal/driver/interactive_test.go:30–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestShell(t *testing.T) {
31 p := &profile.Profile{}
32 generateReportWrapper = checkValue
33 defer func() { generateReportWrapper = generateReport }()
34
35 // Use test commands and variables to exercise interactive processing
36 var savedCommands commands
37 savedCommands, pprofCommands = pprofCommands, testCommands
38 defer func() { pprofCommands = savedCommands }()
39
40 savedConfig := currentConfig()
41 defer setCurrentConfig(savedConfig)
42
43 shortcuts1, scScript1 := makeShortcuts(interleave(script, 2), 1)
44 shortcuts2, scScript2 := makeShortcuts(interleave(script, 1), 2)
45
46 var testcases = []struct {
47 name string
48 input []string
49 shortcuts shortcuts
50 allowRx string
51 numAllowRxMatches int
52 propagateError bool
53 }{
54 {"Random interleave of independent scripts 1", interleave(script, 0), pprofShortcuts, "", 0, false},
55 {"Random interleave of independent scripts 2", interleave(script, 1), pprofShortcuts, "", 0, false},
56 {"Random interleave of independent scripts with shortcuts 1", scScript1, shortcuts1, "", 0, false},
57 {"Random interleave of independent scripts with shortcuts 2", scScript2, shortcuts2, "", 0, false},
58 {"Group with invalid value", []string{"sort=this"}, pprofShortcuts, `invalid "sort" value`, 1, false},
59 {"No special value provided for the option", []string{"sample_index"}, pprofShortcuts, `please specify a value, e.g. sample_index=<val>`, 1, false},
60 {"No string value provided for the option", []string{"focus"}, pprofShortcuts, `please specify a value, e.g. focus=<val>`, 1, false},
61 {"No float value provided for the option", []string{"divide_by"}, pprofShortcuts, `please specify a value, e.g. divide_by=<val>`, 1, false},
62 {"Helpful input format reminder", []string{"sample_index 0"}, pprofShortcuts, `did you mean: sample_index=0`, 1, false},
63 {"Verify propagation of IO errors", []string{"**error**"}, pprofShortcuts, "", 0, true},
64 }
65
66 o := setDefaults(&plugin.Options{HTTPTransport: transport.New(nil)})
67 for _, tc := range testcases {
68 t.Run(tc.name, func(t *testing.T) {
69 setCurrentConfig(savedConfig)
70 pprofShortcuts = tc.shortcuts
71 ui := &proftest.TestUI{
72 T: t,
73 Input: tc.input,
74 AllowRx: tc.allowRx,
75 }
76 o.UI = ui
77
78 err := interactive(p, o)
79 if (tc.propagateError && err == nil) || (!tc.propagateError && err != nil) {
80 t.Errorf("%s: %v", tc.name, err)
81 }
82
83 // Confirm error message written out once.
84 if tc.numAllowRxMatches != ui.NumAllowRxMatches {
85 t.Errorf("want error message to be printed %d time(s), got %d",
86 tc.numAllowRxMatches, ui.NumAllowRxMatches)
87 }

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
currentConfigFunction · 0.85
setCurrentConfigFunction · 0.85
makeShortcutsFunction · 0.85
interleaveFunction · 0.85
setDefaultsFunction · 0.85
interactiveFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…