mirror of
https://github.com/spf13/cobra
synced 2025-05-07 22:07:23 +00:00
style(command_test)
This commit is contained in:
parent
cc49679e54
commit
576d6e4fb0
1 changed files with 49 additions and 52 deletions
101
command_test.go
101
command_test.go
|
@ -125,7 +125,7 @@ func TestSubcommandExecuteC(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Name() != "child" {
|
if c.Name() != "child" {
|
||||||
t.Errorf(`invalid command returned from ExecuteC: expected "child"', got %q`, c.Name())
|
t.Errorf(`invalid command returned from ExecuteC: expected "child"', got: %q`, c.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ func TestPersistentFlagsOnSameCommand(t *testing.T) {
|
||||||
|
|
||||||
got := strings.Join(rootCmdArgs, " ")
|
got := strings.Join(rootCmdArgs, " ")
|
||||||
if got != onetwo {
|
if got != onetwo {
|
||||||
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
t.Errorf("rootCmdArgs expected: %q, got %q", onetwo, got)
|
||||||
}
|
}
|
||||||
if flagValue != 7 {
|
if flagValue != 7 {
|
||||||
t.Errorf("flagValue expected: %v, got %v", 7, flagValue)
|
t.Errorf("flagValue expected: %v, got %v", 7, flagValue)
|
||||||
|
@ -1068,20 +1068,19 @@ func TestHooks(t *testing.T) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if persPreArgs != onetwo {
|
for _, v := range []struct {
|
||||||
t.Errorf("Expected persPreArgs %q, got %q", onetwo, persPreArgs)
|
name string
|
||||||
}
|
got string
|
||||||
if preArgs != onetwo {
|
}{
|
||||||
t.Errorf("Expected preArgs %q, got %q", onetwo, preArgs)
|
{"persPreArgs", persPreArgs},
|
||||||
}
|
{"preArgs", preArgs},
|
||||||
if runArgs != onetwo {
|
{"runArgs", runArgs},
|
||||||
t.Errorf("Expected runArgs %q, got %q", onetwo, runArgs)
|
{"postArgs", postArgs},
|
||||||
}
|
{"persPostArgs", persPostArgs},
|
||||||
if postArgs != onetwo {
|
} {
|
||||||
t.Errorf("Expected postArgs %q, got %q", onetwo, postArgs)
|
if v.got != onetwo {
|
||||||
}
|
t.Errorf("Expected %s %q, got %q", v.name, onetwo, v.got)
|
||||||
if persPostArgs != onetwo {
|
}
|
||||||
t.Errorf("Expected persPostArgs %q, got %q", onetwo, persPostArgs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,44 +1148,42 @@ func TestPersistentHooks(t *testing.T) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: currently PersistenPreRun* defined in parent does not
|
for _, v := range []struct {
|
||||||
// run if the matchin child subcommand has PersistenPreRun.
|
name string
|
||||||
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
got string
|
||||||
// this test must be fixed.
|
}{
|
||||||
if parentPersPreArgs != "" {
|
// TODO: currently PersistenPreRun* defined in parent does not
|
||||||
t.Errorf("Expected blank parentPersPreArgs, got %q", parentPersPreArgs)
|
// run if the matchin child subcommand has PersistenPreRun.
|
||||||
}
|
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
||||||
if parentPreArgs != "" {
|
// this test must be fixed.
|
||||||
t.Errorf("Expected blank parentPreArgs, got %q", parentPreArgs)
|
{"parentPersPreArgs", parentPersPreArgs},
|
||||||
}
|
{"parentPreArgs", parentPreArgs},
|
||||||
if parentRunArgs != "" {
|
{"parentRunArgs", parentRunArgs},
|
||||||
t.Errorf("Expected blank parentRunArgs, got %q", parentRunArgs)
|
{"parentPostArgs", parentPostArgs},
|
||||||
}
|
// TODO: currently PersistenPostRun* defined in parent does not
|
||||||
if parentPostArgs != "" {
|
// run if the matchin child subcommand has PersistenPostRun.
|
||||||
t.Errorf("Expected blank parentPostArgs, got %q", parentPostArgs)
|
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
||||||
}
|
// this test must be fixed.
|
||||||
// TODO: currently PersistenPostRun* defined in parent does not
|
{"parentPersPostArgs", parentPersPostArgs},
|
||||||
// run if the matchin child subcommand has PersistenPostRun.
|
} {
|
||||||
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
if v.got != "" {
|
||||||
// this test must be fixed.
|
t.Errorf("Expected blank %s, got %q", v.name, v.got)
|
||||||
if parentPersPostArgs != "" {
|
}
|
||||||
t.Errorf("Expected blank parentPersPostArgs, got %q", parentPersPostArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if childPersPreArgs != onetwo {
|
for _, v := range []struct {
|
||||||
t.Errorf("Expected childPersPreArgs %q, got %q", onetwo, childPersPreArgs)
|
name string
|
||||||
}
|
got string
|
||||||
if childPreArgs != onetwo {
|
}{
|
||||||
t.Errorf("Expected childPreArgs %q, got %q", onetwo, childPreArgs)
|
{"childPersPreArgs", childPersPreArgs},
|
||||||
}
|
{"childPreArgs", childPreArgs},
|
||||||
if childRunArgs != onetwo {
|
{"childRunArgs", childRunArgs},
|
||||||
t.Errorf("Expected childRunArgs %q, got %q", onetwo, childRunArgs)
|
{"childPostArgs", childPostArgs},
|
||||||
}
|
{"childPersPostArgs", childPersPostArgs},
|
||||||
if childPostArgs != onetwo {
|
} {
|
||||||
t.Errorf("Expected childPostArgs %q, got %q", onetwo, childPostArgs)
|
if v.got != onetwo {
|
||||||
}
|
t.Errorf("Expected %s %q, got %q", v.name, onetwo, v.got)
|
||||||
if childPersPostArgs != onetwo {
|
}
|
||||||
t.Errorf("Expected childPersPostArgs %q, got %q", onetwo, childPersPostArgs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue