cli.Main no longer calls SetOut or SetErr. SetOut also moved the usage and an unknown help topic, which cobra writes to stderr, onto stdout. execute now takes the command tree, so the tests build it, set its arguments and output streams, and run it; the exit line goes to the command's error stream, which outside a test is stderr as before. Model: opus-5-5
This commit is contained in:
@@ -14,7 +14,12 @@ func TestVersionPrintsVersion(t *testing.T) {
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
status := cli.Execute("1.2.3", []string{"version"}, &stdout, &stderr)
|
||||
root := cli.RootCmd("1.2.3")
|
||||
root.SetArgs([]string{"version"})
|
||||
root.SetOut(&stdout)
|
||||
root.SetErr(&stderr)
|
||||
|
||||
status := cli.Execute(root)
|
||||
if status != 0 {
|
||||
t.Fatalf("status = %d, want 0; stderr: %q", status, stderr.String())
|
||||
}
|
||||
@@ -30,7 +35,12 @@ func TestUnknownCommandFails(t *testing.T) {
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
status := cli.Execute("1.2.3", []string{"frobnicate"}, &stdout, &stderr)
|
||||
root := cli.RootCmd("1.2.3")
|
||||
root.SetArgs([]string{"frobnicate"})
|
||||
root.SetOut(&stdout)
|
||||
root.SetErr(&stderr)
|
||||
|
||||
status := cli.Execute(root)
|
||||
if status == 0 {
|
||||
t.Fatal("status = 0, want non-zero")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user