|
8 | 8 | "os"
|
9 | 9 | "reflect"
|
10 | 10 | "regexp"
|
11 |
| - "runtime" |
12 | 11 | "strings"
|
13 | 12 | "testing"
|
14 | 13 | "time"
|
@@ -507,7 +506,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
507 | 506 | fl := &StringFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_FOO"}}
|
508 | 507 | output := fl.String()
|
509 | 508 |
|
510 |
| - expectedSuffix := suffixForEnv("APP_FOO") |
| 509 | + expectedSuffix := withEnvHint([]string{"APP_FOO"}, "") |
511 | 510 | if !strings.HasSuffix(output, expectedSuffix) {
|
512 | 511 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
513 | 512 | }
|
@@ -596,7 +595,7 @@ func TestPathFlagWithEnvVarHelpOutput(t *testing.T) {
|
596 | 595 | fl := &PathFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_PATH"}}
|
597 | 596 | output := fl.String()
|
598 | 597 |
|
599 |
| - expectedSuffix := suffixForEnv("APP_PATH") |
| 598 | + expectedSuffix := withEnvHint([]string{"APP_PATH"}, "") |
600 | 599 | if !strings.HasSuffix(output, expectedSuffix) {
|
601 | 600 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
602 | 601 | }
|
@@ -690,7 +689,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
690 | 689 | fl := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_QWWX"}}
|
691 | 690 | output := fl.String()
|
692 | 691 |
|
693 |
| - expectedSuffix := suffixForEnv("APP_QWWX") |
| 692 | + expectedSuffix := withEnvHint([]string{"APP_QWWX"}, "") |
694 | 693 | if !strings.HasSuffix(output, expectedSuffix) {
|
695 | 694 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
696 | 695 | }
|
@@ -788,7 +787,7 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
788 | 787 | fl := &IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
789 | 788 | output := fl.String()
|
790 | 789 |
|
791 |
| - expectedSuffix := suffixForEnv("APP_BAR") |
| 790 | + expectedSuffix := withEnvHint([]string{"APP_BAR"}, "") |
792 | 791 | if !strings.HasSuffix(output, expectedSuffix) {
|
793 | 792 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
794 | 793 | }
|
@@ -847,21 +846,13 @@ func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
847 | 846 | fl := IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
848 | 847 | output := fl.String()
|
849 | 848 |
|
850 |
| - expectedSuffix := suffixForEnv("APP_BAR") |
| 849 | + expectedSuffix := withEnvHint([]string{"APP_BAR"}, "") |
851 | 850 | if !strings.HasSuffix(output, expectedSuffix) {
|
852 | 851 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
853 | 852 | }
|
854 | 853 | }
|
855 | 854 | }
|
856 | 855 |
|
857 |
| -func suffixForEnv(s string) string { |
858 |
| - expectedSuffix := fmt.Sprintf(" [$%s]", s) |
859 |
| - if runtime.GOOS == "windows" { |
860 |
| - expectedSuffix = fmt.Sprintf(" [%s%s%s]", "%", s, "%") |
861 |
| - } |
862 |
| - return expectedSuffix |
863 |
| -} |
864 |
| - |
865 | 856 | func TestInt64FlagValueFromContext(t *testing.T) {
|
866 | 857 | set := flag.NewFlagSet("test", 0)
|
867 | 858 | set.Int64("myflag", 42, "doc")
|
@@ -903,7 +894,7 @@ func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
|
903 | 894 | fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
904 | 895 | output := fl.String()
|
905 | 896 |
|
906 |
| - expectedSuffix := suffixForEnv("APP_BAR") |
| 897 | + expectedSuffix := withEnvHint([]string{"APP_BAR"}, "") |
907 | 898 | if !strings.HasSuffix(output, expectedSuffix) {
|
908 | 899 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
909 | 900 | }
|
@@ -951,7 +942,7 @@ func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
|
951 | 942 | fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
952 | 943 | output := fl.String()
|
953 | 944 |
|
954 |
| - expectedSuffix := suffixForEnv("APP_BAR") |
| 945 | + expectedSuffix := withEnvHint([]string{"APP_BAR"}, "") |
955 | 946 | if !strings.HasSuffix(output, expectedSuffix) {
|
956 | 947 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
957 | 948 | }
|
@@ -999,7 +990,7 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
999 | 990 | fl := &DurationFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
1000 | 991 | output := fl.String()
|
1001 | 992 |
|
1002 |
| - expectedSuffix := suffixForEnv("APP_BAR") |
| 993 | + expectedSuffix := withEnvHint([]string{"APP_BAR"}, "") |
1003 | 994 | if !strings.HasSuffix(output, expectedSuffix) {
|
1004 | 995 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
1005 | 996 | }
|
@@ -1056,7 +1047,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
1056 | 1047 | fl := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
1057 | 1048 | output := fl.String()
|
1058 | 1049 |
|
1059 |
| - expectedSuffix := suffixForEnv("APP_SMURF") |
| 1050 | + expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "") |
1060 | 1051 | if !strings.HasSuffix(output, expectedSuffix) {
|
1061 | 1052 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
1062 | 1053 | }
|
@@ -1192,7 +1183,7 @@ func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
1192 | 1183 | fl := Int64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
1193 | 1184 | output := fl.String()
|
1194 | 1185 |
|
1195 |
| - expectedSuffix := suffixForEnv("APP_SMURF") |
| 1186 | + expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "") |
1196 | 1187 | if !strings.HasSuffix(output, expectedSuffix) {
|
1197 | 1188 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
1198 | 1189 | }
|
@@ -1343,7 +1334,7 @@ func TestUintSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
1343 | 1334 | fl := UintSliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
1344 | 1335 | output := fl.String()
|
1345 | 1336 |
|
1346 |
| - expectedSuffix := suffixForEnv("APP_SMURF") |
| 1337 | + expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "") |
1347 | 1338 | if !strings.HasSuffix(output, expectedSuffix) {
|
1348 | 1339 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
1349 | 1340 | }
|
@@ -1486,7 +1477,7 @@ func TestUint64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
1486 | 1477 | fl := Uint64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
1487 | 1478 | output := fl.String()
|
1488 | 1479 |
|
1489 |
| - expectedSuffix := suffixForEnv("APP_SMURF") |
| 1480 | + expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "") |
1490 | 1481 | if !strings.HasSuffix(output, expectedSuffix) {
|
1491 | 1482 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
1492 | 1483 | }
|
@@ -1625,7 +1616,7 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
1625 | 1616 | fl := &Float64Flag{Name: test.name, EnvVars: []string{"APP_BAZ"}}
|
1626 | 1617 | output := fl.String()
|
1627 | 1618 |
|
1628 |
| - expectedSuffix := suffixForEnv("APP_BAZ") |
| 1619 | + expectedSuffix := withEnvHint([]string{"APP_BAZ"}, "") |
1629 | 1620 | if !strings.HasSuffix(output, expectedSuffix) {
|
1630 | 1621 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
1631 | 1622 | }
|
@@ -1682,7 +1673,7 @@ func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
1682 | 1673 | fl := Float64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
1683 | 1674 | output := fl.String()
|
1684 | 1675 |
|
1685 |
| - expectedSuffix := suffixForEnv("APP_SMURF") |
| 1676 | + expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "") |
1686 | 1677 | if !strings.HasSuffix(output, expectedSuffix) {
|
1687 | 1678 | t.Errorf("%q does not end with"+expectedSuffix, output)
|
1688 | 1679 | }
|
@@ -1802,7 +1793,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
1802 | 1793 | fl := &GenericFlag{Name: test.name, EnvVars: []string{"APP_ZAP"}}
|
1803 | 1794 | output := fl.String()
|
1804 | 1795 |
|
1805 |
| - expectedSuffix := suffixForEnv("APP_ZAP") |
| 1796 | + expectedSuffix := withEnvHint([]string{"APP_ZAP"}, "") |
1806 | 1797 | if !strings.HasSuffix(output, expectedSuffix) {
|
1807 | 1798 | t.Errorf("%s does not end with"+expectedSuffix, output)
|
1808 | 1799 | }
|
|
0 commit comments