|
|
|
@ -162,6 +162,42 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var int64FlagTests = []struct {
|
|
|
|
|
name string
|
|
|
|
|
expected string
|
|
|
|
|
}{
|
|
|
|
|
{"hats", "--hats value\t(default: 8589934592)"},
|
|
|
|
|
{"H", "-H value\t(default: 8589934592)"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInt64FlagHelpOutput(t *testing.T) {
|
|
|
|
|
for _, test := range int64FlagTests {
|
|
|
|
|
flag := Int64Flag{Name: test.name, Value: 8589934592}
|
|
|
|
|
output := flag.String()
|
|
|
|
|
|
|
|
|
|
if output != test.expected {
|
|
|
|
|
t.Errorf("%s does not match %s", output, test.expected)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
os.Setenv("APP_BAR", "2")
|
|
|
|
|
for _, test := range int64FlagTests {
|
|
|
|
|
flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
|
|
|
|
output := flag.String()
|
|
|
|
|
|
|
|
|
|
expectedSuffix := " [$APP_BAR]"
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
expectedSuffix = " [%APP_BAR%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var durationFlagTests = []struct {
|
|
|
|
|
name string
|
|
|
|
|
expected string
|
|
|
|
@ -241,6 +277,49 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var int64SliceFlagTests = []struct {
|
|
|
|
|
name string
|
|
|
|
|
value *Int64Slice
|
|
|
|
|
expected string
|
|
|
|
|
}{
|
|
|
|
|
{"heads", &Int64Slice{}, "--heads value\t"},
|
|
|
|
|
{"H", &Int64Slice{}, "-H value\t"},
|
|
|
|
|
{"H, heads", func() *Int64Slice {
|
|
|
|
|
i := &Int64Slice{}
|
|
|
|
|
i.Set("2")
|
|
|
|
|
i.Set("17179869184")
|
|
|
|
|
return i
|
|
|
|
|
}(), "-H value, --heads value\t(default: 2, 17179869184)"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInt64SliceFlagHelpOutput(t *testing.T) {
|
|
|
|
|
for _, test := range int64SliceFlagTests {
|
|
|
|
|
flag := Int64SliceFlag{Name: test.name, Value: test.value}
|
|
|
|
|
output := flag.String()
|
|
|
|
|
|
|
|
|
|
if output != test.expected {
|
|
|
|
|
t.Errorf("%q does not match %q", output, test.expected)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
os.Setenv("APP_SMURF", "42,17179869184")
|
|
|
|
|
for _, test := range int64SliceFlagTests {
|
|
|
|
|
flag := Int64SliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"}
|
|
|
|
|
output := flag.String()
|
|
|
|
|
|
|
|
|
|
expectedSuffix := " [$APP_SMURF]"
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
expectedSuffix = " [%APP_SMURF%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%q does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var float64FlagTests = []struct {
|
|
|
|
|
name string
|
|
|
|
|
expected string
|
|
|
|
@ -579,6 +658,63 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseMultiInt64Slice(t *testing.T) {
|
|
|
|
|
(&App{
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Int64SliceFlag{Name: "serve, s", Value: &Int64Slice{}},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("serve"), []int64{10, 17179869184}) {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("s"), []int64{10, 17179869184}) {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "17179869184"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseMultiInt64SliceFromEnv(t *testing.T) {
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
|
|
|
|
|
|
|
|
|
(&App{
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("intervals"), []int64{20, 30, 17179869184}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("i"), []int64{20, 30, 17179869184}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) {
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
|
|
|
|
|
|
|
|
|
(&App{
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("intervals"), []int64{20, 30, 17179869184}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.Int64Slice("i"), []int64{20, 30, 17179869184}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseMultiFloat64(t *testing.T) {
|
|
|
|
|
a := App{
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|