-
Notifications
You must be signed in to change notification settings - Fork 640
Provide more helpful error message and require input for every non-bool option. #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a9ea908
Provide more helpful error message and require input for every non-bo…
wyk9787 2a191ba
Merge branch 'master' into helpful_error
nolanmar511 a2e56b4
Improve the Option groups' help message
wyk9787 f3c38ed
Rearrange TestShell to table driven tests
wyk9787 8563fb1
Merge branch 'helpful_error' of github.com:wyk9787/pprof into helpful…
wyk9787 99ff77d
Remove unused function
wyk9787 b6459a5
Remove space around equal sign in usage
wyk9787 7483e19
Standardize the help message for all options
wyk9787 a0929fd
Fix tests
wyk9787 2434176
Mention option <s> in help
wyk9787 68e3bcf
Rename the function from addVariablesPostFix to variablesPostFix
wyk9787 fee78be
Improve the help message on individual option
wyk9787 71ef91f
Fix a few nits
wyk9787 c882260
Fix formatting
wyk9787 54872a3
Merge branch 'master' into helpful_error
wyk9787 a7a638d
Revert all changed made to help text
wyk9787 cebe0e4
Fix merge conflicts
wyk9787 cbe760c
Solve merge conflicts
wyk9787 091f3d9
Change format string to be more idomatic
wyk9787 05e747c
Fix typo
wyk9787 cfc1286
Fix flags
wyk9787 fc94335
Fix wording
wyk9787 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,62 +40,53 @@ func TestShell(t *testing.T) { | |
| savedVariables := pprofVariables | ||
| defer func() { pprofVariables = savedVariables }() | ||
|
|
||
| // Random interleave of independent scripts | ||
| pprofVariables = testVariables(savedVariables) | ||
| shortcuts1, scScript1 := makeShortcuts(interleave(script, 2), 1) | ||
| shortcuts2, scScript2 := makeShortcuts(interleave(script, 1), 2) | ||
|
|
||
| // pass in HTTPTransport when setting defaults, because otherwise default | ||
| // transport will try to add flags to the default flag set. | ||
| o := setDefaults(&plugin.Options{HTTPTransport: transport.New(nil)}) | ||
| o.UI = newUI(t, interleave(script, 0)) | ||
| if err := interactive(p, o); err != nil { | ||
| t.Error("first attempt:", err) | ||
| } | ||
| // Random interleave of independent scripts | ||
| pprofVariables = testVariables(savedVariables) | ||
| o.UI = newUI(t, interleave(script, 1)) | ||
| if err := interactive(p, o); err != nil { | ||
| t.Error("second attempt:", err) | ||
| var testcases = []struct { | ||
| name string | ||
| input []string | ||
| shortcuts shortcuts | ||
| allowRx string | ||
| numAllowRxMatches int | ||
| propagateError bool | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag seems to be false in all test cases, is this expected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now fixed. |
||
| }{ | ||
| {"Random interleave of independent scripts 1", interleave(script, 0), pprofShortcuts, "", 0, false}, | ||
| {"Random interleave of independent scripts 2", interleave(script, 1), pprofShortcuts, "", 0, false}, | ||
| {"Random interleave of independent scripts with shortcuts 1", scScript1, shortcuts1, "", 0, false}, | ||
| {"Random interleave of independent scripts with shortcuts 2", scScript2, shortcuts2, "", 0, false}, | ||
| {"Group with invalid value", []string{"cumulative=this"}, pprofShortcuts, `unrecognized value for cumulative: "this". Use one of cum, flat`, 1, false}, | ||
| {"No special value provided for the option", []string{"sample_index"}, pprofShortcuts, `please input a value, e.g. sample_index=<val>`, 1, false}, | ||
| {"No string value provided for the option", []string{"focus="}, pprofShortcuts, `please input a value, e.g. focus=<val>`, 1, false}, | ||
| {"No float value provided for the option", []string{"divide_by"}, pprofShortcuts, `please input a value, e.g. divide_by=<val>`, 1, false}, | ||
| {"Helpful input format reminder", []string{"sample_index 0"}, pprofShortcuts, `did you mean: sample_index=0`, 1, false}, | ||
| {"Verify propagation of IO errors", []string{"**error**"}, pprofShortcuts, "", 0, true}, | ||
| } | ||
|
|
||
nolanmar511 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Random interleave of independent scripts with shortcuts | ||
| pprofVariables = testVariables(savedVariables) | ||
| var scScript []string | ||
| pprofShortcuts, scScript = makeShortcuts(interleave(script, 2), 1) | ||
| o.UI = newUI(t, scScript) | ||
| if err := interactive(p, o); err != nil { | ||
| t.Error("first shortcut attempt:", err) | ||
| } | ||
| o := setDefaults(&plugin.Options{HTTPTransport: transport.New(nil)}) | ||
| for _, tc := range testcases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| pprofVariables = testVariables(savedVariables) | ||
| pprofShortcuts = tc.shortcuts | ||
| ui := &proftest.TestUI{ | ||
| T: t, | ||
| Input: tc.input, | ||
| AllowRx: tc.allowRx, | ||
| } | ||
| o.UI = ui | ||
|
|
||
| // Random interleave of independent scripts with shortcuts | ||
| pprofVariables = testVariables(savedVariables) | ||
| pprofShortcuts, scScript = makeShortcuts(interleave(script, 1), 2) | ||
| o.UI = newUI(t, scScript) | ||
| if err := interactive(p, o); err != nil { | ||
| t.Error("second shortcut attempt:", err) | ||
| } | ||
| err := interactive(p, o) | ||
| if (tc.propagateError && err == nil) || (!tc.propagateError && err != nil) { | ||
| t.Errorf("%s: %v", tc.name, err) | ||
| } | ||
|
|
||
| // Group with invalid value | ||
| pprofVariables = testVariables(savedVariables) | ||
| ui := &proftest.TestUI{ | ||
| T: t, | ||
| Input: []string{"cumulative=this"}, | ||
| AllowRx: `unrecognized value for cumulative: "this". Use one of cum, flat`, | ||
| } | ||
| o.UI = ui | ||
| if err := interactive(p, o); err != nil { | ||
| t.Error("invalid group value:", err) | ||
| } | ||
| // Confirm error message written out once. | ||
| if ui.NumAllowRxMatches != 1 { | ||
| t.Errorf("want error message to be printed 1 time, got %v", ui.NumAllowRxMatches) | ||
| } | ||
| // Verify propagation of IO errors | ||
| pprofVariables = testVariables(savedVariables) | ||
| o.UI = newUI(t, []string{"**error**"}) | ||
| if err := interactive(p, o); err == nil { | ||
| t.Error("expected IO error, got nil") | ||
| // Confirm error message written out once. | ||
| if tc.numAllowRxMatches != ui.NumAllowRxMatches { | ||
| t.Errorf("want error message to be printed %d time(s), got %d", | ||
| tc.numAllowRxMatches, ui.NumAllowRxMatches) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| var testCommands = commands{ | ||
|
|
@@ -132,7 +123,7 @@ var script = []string{ | |
| "f=-1;f=-2.5;check f=-2.5;f=0.0001;check f=0.0001", | ||
| "check ff=0;ff=-1.01;check ff=-1.01;ff=100;check ff=100", | ||
| "s=one;s=two;check s=two", | ||
| "ss=tree;check ss=tree;ss=;check ss;ss=forest;check ss=forest", | ||
| "ss=tree;check ss=tree;ss=forest;check ss=forest", | ||
nolanmar511 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "ta=true;check ta=true;check tb=false;check tc=false;tb=1;check tb=true;check ta=false;check tc=false;tc=yes;check tb=false;check ta=false;check tc=true", | ||
| } | ||
|
|
||
|
|
@@ -162,13 +153,6 @@ func makeShortcuts(input []string, seed int) (shortcuts, []string) { | |
| return s, output | ||
| } | ||
|
|
||
| func newUI(t *testing.T, input []string) plugin.UI { | ||
| return &proftest.TestUI{ | ||
| T: t, | ||
| Input: input, | ||
| } | ||
| } | ||
|
|
||
| func checkValue(p *profile.Profile, cmd []string, vars variables, o *plugin.Options) error { | ||
| if len(cmd) != 2 { | ||
| return fmt.Errorf("expected len(cmd)==2, got %v", cmd) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> specify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.