mirror of
https://github.com/spf13/cobra
synced 2025-07-03 17:47:18 +00:00
make 'one two' a constant
This commit is contained in:
parent
826340688f
commit
0be19cdea6
1 changed files with 44 additions and 53 deletions
|
@ -44,6 +44,8 @@ func checkStringOmits(t *testing.T, got, expected string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onetwo = "one two"
|
||||||
|
|
||||||
func TestSingleCommand(t *testing.T) {
|
func TestSingleCommand(t *testing.T) {
|
||||||
var rootCmdArgs []string
|
var rootCmdArgs []string
|
||||||
rootCmd := &Command{
|
rootCmd := &Command{
|
||||||
|
@ -64,9 +66,8 @@ func TestSingleCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(rootCmdArgs, " ")
|
got := strings.Join(rootCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("rootCmdArgs expected: %q, got: %q", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +91,8 @@ func TestChildCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(child1CmdArgs, " ")
|
got := strings.Join(child1CmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("child1CmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("child1CmdArgs expected: %q, got: %q", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,9 +173,8 @@ func TestCommandAlias(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(timesCmdArgs, " ")
|
got := strings.Join(timesCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("timesCmdArgs expected: %v, got: %v", onetwo, got)
|
||||||
t.Errorf("timesCmdArgs expected: %v, got: %v", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,9 +200,8 @@ func TestEnablePrefixMatching(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(aCmdArgs, " ")
|
got := strings.Join(aCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("aCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("aCmdArgs expected: %q, got: %q", expected, got)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EnablePrefixMatching = false
|
EnablePrefixMatching = false
|
||||||
|
@ -237,9 +235,8 @@ func TestAliasPrefixMatching(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(timesCmdArgs, " ")
|
got := strings.Join(timesCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("timesCmdArgs expected: %v, got: %v", onetwo, got)
|
||||||
t.Errorf("timesCmdArgs expected: %v, got: %v", expected, got)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EnablePrefixMatching = false
|
EnablePrefixMatching = false
|
||||||
|
@ -268,9 +265,8 @@ func TestChildSameName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(fooCmdArgs, " ")
|
got := strings.Join(fooCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("fooCmdArgs expected: %v, got: %v", onetwo, got)
|
||||||
t.Errorf("fooCmdArgs expected: %v, got: %v", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,9 +294,8 @@ func TestGrandChildSameName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(fooCmdArgs, " ")
|
got := strings.Join(fooCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("fooCmdArgs expected: %v, got: %v", onetwo, got)
|
||||||
t.Errorf("fooCmdArgs expected: %v, got: %v", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,9 +331,8 @@ func TestFlagLong(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(cArgs, " ")
|
got := strings.Join(cArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("Expected arguments: %q, got %q", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,9 +365,8 @@ func TestFlagShort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(cArgs, " ")
|
got := strings.Join(cArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("Expected arguments: %q, got %q", expected, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,9 +568,8 @@ func TestPersistentFlagsOnSameCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(rootCmdArgs, " ")
|
got := strings.Join(rootCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("rootCmdArgs expected: %q, got %q", expected, 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)
|
||||||
|
@ -661,9 +653,8 @@ func TestPersistentFlagsOnChild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
got := strings.Join(childCmdArgs, " ")
|
got := strings.Join(childCmdArgs, " ")
|
||||||
expected := "one two"
|
if got != onetwo {
|
||||||
if got != expected {
|
t.Errorf("rootCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
t.Errorf("childCmdArgs expected: %q, got %q", expected, got)
|
|
||||||
}
|
}
|
||||||
if parentFlagValue != 8 {
|
if parentFlagValue != 8 {
|
||||||
t.Errorf("parentFlagValue expected: %v, got %v", 8, parentFlagValue)
|
t.Errorf("parentFlagValue expected: %v, got %v", 8, parentFlagValue)
|
||||||
|
@ -1083,20 +1074,20 @@ func TestHooks(t *testing.T) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if persPreArgs != "one two" {
|
if persPreArgs != onetwo {
|
||||||
t.Errorf("Expected persPreArgs %q, got %q", "one two", persPreArgs)
|
t.Errorf("Expected persPreArgs %q, got %q", onetwo, persPreArgs)
|
||||||
}
|
}
|
||||||
if preArgs != "one two" {
|
if preArgs != onetwo {
|
||||||
t.Errorf("Expected preArgs %q, got %q", "one two", preArgs)
|
t.Errorf("Expected preArgs %q, got %q", onetwo, preArgs)
|
||||||
}
|
}
|
||||||
if runArgs != "one two" {
|
if runArgs != onetwo {
|
||||||
t.Errorf("Expected runArgs %q, got %q", "one two", runArgs)
|
t.Errorf("Expected runArgs %q, got %q", onetwo, runArgs)
|
||||||
}
|
}
|
||||||
if postArgs != "one two" {
|
if postArgs != onetwo {
|
||||||
t.Errorf("Expected postArgs %q, got %q", "one two", postArgs)
|
t.Errorf("Expected postArgs %q, got %q", onetwo, postArgs)
|
||||||
}
|
}
|
||||||
if persPostArgs != "one two" {
|
if persPostArgs != onetwo {
|
||||||
t.Errorf("Expected persPostArgs %q, got %q", "one two", persPostArgs)
|
t.Errorf("Expected persPostArgs %q, got %q", onetwo, persPostArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1188,20 +1179,20 @@ func TestPersistentHooks(t *testing.T) {
|
||||||
t.Errorf("Expected blank parentPersPostArgs, got %q", parentPersPostArgs)
|
t.Errorf("Expected blank parentPersPostArgs, got %q", parentPersPostArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if childPersPreArgs != "one two" {
|
if childPersPreArgs != onetwo {
|
||||||
t.Errorf("Expected childPersPreArgs %q, got %q", "one two", childPersPreArgs)
|
t.Errorf("Expected childPersPreArgs %q, got %q", onetwo, childPersPreArgs)
|
||||||
}
|
}
|
||||||
if childPreArgs != "one two" {
|
if childPreArgs != onetwo {
|
||||||
t.Errorf("Expected childPreArgs %q, got %q", "one two", childPreArgs)
|
t.Errorf("Expected childPreArgs %q, got %q", onetwo, childPreArgs)
|
||||||
}
|
}
|
||||||
if childRunArgs != "one two" {
|
if childRunArgs != onetwo {
|
||||||
t.Errorf("Expected childRunArgs %q, got %q", "one two", childRunArgs)
|
t.Errorf("Expected childRunArgs %q, got %q", onetwo, childRunArgs)
|
||||||
}
|
}
|
||||||
if childPostArgs != "one two" {
|
if childPostArgs != onetwo {
|
||||||
t.Errorf("Expected childPostArgs %q, got %q", "one two", childPostArgs)
|
t.Errorf("Expected childPostArgs %q, got %q", onetwo, childPostArgs)
|
||||||
}
|
}
|
||||||
if childPersPostArgs != "one two" {
|
if childPersPostArgs != onetwo {
|
||||||
t.Errorf("Expected childPersPostArgs %q, got %q", "one two", childPersPostArgs)
|
t.Errorf("Expected childPersPostArgs %q, got %q", onetwo, childPersPostArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue