alternative to PR "improve code quality" (#21464)

This PR doesn't require new git version, and can be backported easily.

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
wxiaoguang 2022-10-15 18:49:26 +08:00 committed by GitHub
parent 7917123209
commit d98c5db58f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 25 deletions

View file

@ -26,4 +26,21 @@ func TestRunWithContextStd(t *testing.T) {
assert.Contains(t, err.Error(), "exit status 129 - unknown option:")
assert.Empty(t, stdout)
}
assert.Panics(t, func() {
cmd = NewCommand(context.Background())
cmd.AddDynamicArguments("-test")
})
assert.Panics(t, func() {
cmd = NewCommand(context.Background())
cmd.AddDynamicArguments("--test")
})
subCmd := "version"
cmd = NewCommand(context.Background()).AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production
stdout, stderr, err = cmd.RunStdString(&RunOpts{})
assert.NoError(t, err)
assert.Empty(t, stderr)
assert.Contains(t, stdout, "git version")
}