Related to https://github.com/spf13/cobra/issues/521.
(t *testing.T)
| 1821 | |
| 1822 | // Related to https://github.com/spf13/cobra/issues/521. |
| 1823 | func TestNormPassedOnInherited(t *testing.T) { |
| 1824 | toUpper := func(f *pflag.FlagSet, name string) pflag.NormalizedName { |
| 1825 | return pflag.NormalizedName(strings.ToUpper(name)) |
| 1826 | } |
| 1827 | |
| 1828 | c := &Command{} |
| 1829 | c.SetGlobalNormalizationFunc(toUpper) |
| 1830 | |
| 1831 | child1 := &Command{} |
| 1832 | c.AddCommand(child1) |
| 1833 | |
| 1834 | c.PersistentFlags().Bool("flagname", true, "") |
| 1835 | |
| 1836 | child2 := &Command{} |
| 1837 | c.AddCommand(child2) |
| 1838 | |
| 1839 | inherited := child1.InheritedFlags() |
| 1840 | if inherited.Lookup("flagname") == nil || inherited.Lookup("flagname") != inherited.Lookup("FLAGNAME") { |
| 1841 | t.Error("Normalization function should be passed on to inherited flag set in command added before flag") |
| 1842 | } |
| 1843 | |
| 1844 | inherited = child2.InheritedFlags() |
| 1845 | if inherited.Lookup("flagname") == nil || inherited.Lookup("flagname") != inherited.Lookup("FLAGNAME") { |
| 1846 | t.Error("Normalization function should be passed on to inherited flag set in command added after flag") |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | // Related to https://github.com/spf13/cobra/issues/521. |
| 1851 | func TestConsistentNormalizedName(t *testing.T) { |
nothing calls this directly
no test coverage detected