|
@@ -16,12 +16,12 @@ package driver
|
16
|
16
|
|
17
|
17
|
import (
|
18
|
18
|
"fmt"
|
19
|
|
- "io"
|
20
|
19
|
"math/rand"
|
21
|
20
|
"strings"
|
22
|
21
|
"testing"
|
23
|
22
|
|
24
|
23
|
"github.com/google/pprof/internal/plugin"
|
|
24
|
+ "github.com/google/pprof/internal/proftest"
|
25
|
25
|
"github.com/google/pprof/internal/report"
|
26
|
26
|
"github.com/google/pprof/profile"
|
27
|
27
|
)
|
|
@@ -70,6 +70,21 @@ func TestShell(t *testing.T) {
|
70
|
70
|
t.Error("second shortcut attempt:", err)
|
71
|
71
|
}
|
72
|
72
|
|
|
73
|
+ // Group with invalid value
|
|
74
|
+ pprofVariables = testVariables(savedVariables)
|
|
75
|
+ ui := &proftest.TestUI{
|
|
76
|
+ T: t,
|
|
77
|
+ Input: []string{"cumulative=this"},
|
|
78
|
+ AllowRx: `Unrecognized value for cumulative: "this". Use one of cum, flat`,
|
|
79
|
+ }
|
|
80
|
+ o.UI = ui
|
|
81
|
+ if err := interactive(p, o); err != nil {
|
|
82
|
+ t.Error("invalid group value:", err)
|
|
83
|
+ }
|
|
84
|
+ // Confirm error message written out once.
|
|
85
|
+ if ui.NumAllowRxMatches != 1 {
|
|
86
|
+ t.Errorf("want error message to be printed 1 time, got %v", ui.NumAllowRxMatches)
|
|
87
|
+ }
|
73
|
88
|
// Verify propagation of IO errors
|
74
|
89
|
pprofVariables = testVariables(savedVariables)
|
75
|
90
|
o.UI = newUI(t, []string{"**error**"})
|
|
@@ -144,45 +159,10 @@ func makeShortcuts(input []string, seed int) (shortcuts, []string) {
|
144
|
159
|
}
|
145
|
160
|
|
146
|
161
|
func newUI(t *testing.T, input []string) plugin.UI {
|
147
|
|
- return &testUI{
|
148
|
|
- t: t,
|
149
|
|
- input: input,
|
150
|
|
- }
|
151
|
|
-}
|
152
|
|
-
|
153
|
|
-type testUI struct {
|
154
|
|
- t *testing.T
|
155
|
|
- input []string
|
156
|
|
- index int
|
157
|
|
-}
|
158
|
|
-
|
159
|
|
-func (ui *testUI) ReadLine(_ string) (string, error) {
|
160
|
|
- if ui.index >= len(ui.input) {
|
161
|
|
- return "", io.EOF
|
|
162
|
+ return &proftest.TestUI{
|
|
163
|
+ T: t,
|
|
164
|
+ Input: input,
|
162
|
165
|
}
|
163
|
|
- input := ui.input[ui.index]
|
164
|
|
- if input == "**error**" {
|
165
|
|
- return "", fmt.Errorf("Error: %s", input)
|
166
|
|
- }
|
167
|
|
- ui.index++
|
168
|
|
- return input, nil
|
169
|
|
-}
|
170
|
|
-
|
171
|
|
-func (ui *testUI) Print(args ...interface{}) {
|
172
|
|
-}
|
173
|
|
-
|
174
|
|
-func (ui *testUI) PrintErr(args ...interface{}) {
|
175
|
|
- output := fmt.Sprint(args)
|
176
|
|
- if output != "" {
|
177
|
|
- ui.t.Error(output)
|
178
|
|
- }
|
179
|
|
-}
|
180
|
|
-
|
181
|
|
-func (ui *testUI) IsTerminal() bool {
|
182
|
|
- return false
|
183
|
|
-}
|
184
|
|
-
|
185
|
|
-func (ui *testUI) SetAutoComplete(func(string) string) {
|
186
|
166
|
}
|
187
|
167
|
|
188
|
168
|
func checkValue(p *profile.Profile, cmd []string, vars variables, o *plugin.Options) error {
|