test: cover Run-with-no-arguments paths (#2406) - #2407
Merged
Conversation
Add a TestRunWithNoOsArgs case combining empty arguments with an empty
Name and EnableShellCompletion, the only path that exercises both the
setupDefaults empty-name guard and the buildCompletionCommand("") append
together. Also assert the root command keeps an empty Name after Run for
the unnamed cases, locking in the documented no-arg behavior.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this?
What this PR does / why we need it:
Follow-up to #2401 (index out of range panic fix). Hardens coverage of the Run-with-no-arguments paths:
command_test.go: adds aTestRunWithNoOsArgscase combining empty arguments with an emptyNameandEnableShellCompletion— the only path where both new guards fire together (setupDefaultsempty-name guard plus the shell-completionbuildCompletionCommand("")append). Verified to panic without the Fix index out of range panic when Run is given no arguments #2401 fix and pass with it.command_test.go:TestRunWithNoOsArgsnow assertscmd.Name == ""afterRunfor the unnamed cases, locking in the documented behavior that a root command keeps an empty Name rather than panicking.Which issue(s) this PR fixes:
Fixes #2406
Special notes for your reviewer:
No behavior change; pure test/robustness hardening.
Testing
go test -count=1 -run "TestRunWithNoOsArgs" -race .passes.go vet ., gofmt, and goimports are clean.go test .passes.Release Notes