Skip to content

Commit

Permalink
Fix windows env error
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Oct 14, 2022
1 parent 729a7c4 commit e320fd8
Showing 1 changed file with 23 additions and 60 deletions.
83 changes: 23 additions & 60 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &StringFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_FOO"}}
output := fl.String()

expectedSuffix := " [$APP_FOO]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_FOO%]"
}
expectedSuffix := suffixForEnv("APP_FOO")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -599,10 +596,7 @@ func TestPathFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &PathFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_PATH"}}
output := fl.String()

expectedSuffix := " [$APP_PATH]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_PATH%]"
}
expectedSuffix := suffixForEnv("APP_PATH")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -696,10 +690,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_QWWX"}}
output := fl.String()

expectedSuffix := " [$APP_QWWX]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_QWWX%]"
}
expectedSuffix := suffixForEnv("APP_QWWX")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -797,10 +788,7 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
output := fl.String()

expectedSuffix := " [$APP_BAR]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAR%]"
}
expectedSuffix := suffixForEnv("APP_BAR")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -859,16 +847,21 @@ func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
fl := IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
output := fl.String()

expectedSuffix := " [$APP_BAR]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAR%]"
}
expectedSuffix := suffixForEnv("APP_BAR")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
}
}

func suffixForEnv(s string) string {
expectedSuffix := fmt.Sprintf(" [$%s]", s)
if runtime.GOOS == "windows" {
expectedSuffix = fmt.Sprintf(" [%s%s%s]", "%", s, "%")
}
return expectedSuffix
}

func TestInt64FlagValueFromContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int64("myflag", 42, "doc")
Expand Down Expand Up @@ -910,10 +903,7 @@ func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
output := fl.String()

expectedSuffix := " [$APP_BAR]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAR%]"
}
expectedSuffix := suffixForEnv("APP_BAR")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -961,10 +951,7 @@ func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
output := fl.String()

expectedSuffix := " [$APP_BAR]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAR%]"
}
expectedSuffix := suffixForEnv("APP_BAR")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1012,10 +999,7 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &DurationFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
output := fl.String()

expectedSuffix := " [$APP_BAR]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAR%]"
}
expectedSuffix := suffixForEnv("APP_BAR")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1072,10 +1056,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_SMURF"}}
output := fl.String()

expectedSuffix := " [$APP_SMURF]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_SMURF%]"
}
expectedSuffix := suffixForEnv("APP_SMURF")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1211,10 +1192,7 @@ func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := Int64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
output := fl.String()

expectedSuffix := " [$APP_SMURF]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_SMURF%]"
}
expectedSuffix := suffixForEnv("APP_SMURF")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1365,10 +1343,7 @@ func TestUintSliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := UintSliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
output := fl.String()

expectedSuffix := " [$APP_SMURF]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_SMURF%]"
}
expectedSuffix := suffixForEnv("APP_SMURF")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1511,10 +1486,7 @@ func TestUint64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := Uint64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
output := fl.String()

expectedSuffix := " [$APP_SMURF]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_SMURF%]"
}
expectedSuffix := suffixForEnv("APP_SMURF")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1653,10 +1625,7 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
fl := &Float64Flag{Name: test.name, EnvVars: []string{"APP_BAZ"}}
output := fl.String()

expectedSuffix := " [$APP_BAZ]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_BAZ%]"
}
expectedSuffix := suffixForEnv("APP_BAZ")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1713,10 +1682,7 @@ func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
fl := Float64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
output := fl.String()

expectedSuffix := " [$APP_SMURF]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_SMURF%]"
}
expectedSuffix := suffixForEnv("APP_SMURF")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%q does not end with"+expectedSuffix, output)
}
Expand Down Expand Up @@ -1836,10 +1802,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
fl := &GenericFlag{Name: test.name, EnvVars: []string{"APP_ZAP"}}
output := fl.String()

expectedSuffix := " [$APP_ZAP]"
if runtime.GOOS == "windows" {
expectedSuffix = " [%APP_ZAP%]"
}
expectedSuffix := suffixForEnv("APP_ZAP")
if !strings.HasSuffix(output, expectedSuffix) {
t.Errorf("%s does not end with"+expectedSuffix, output)
}
Expand Down

0 comments on commit e320fd8

Please sign in to comment.