MCPcopy
hub / github.com/spf13/cobra / TestNormPassedOnInherited

Function TestNormPassedOnInherited

command_test.go:1823–1848  ·  view source on GitHub ↗

Related to https://github.com/spf13/cobra/issues/521.

(t *testing.T)

Source from the content-addressed store, hash-verified

1821
1822// Related to https://github.com/spf13/cobra/issues/521.
1823func 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.
1851func TestConsistentNormalizedName(t *testing.T) {

Callers

nothing calls this directly

Calls 5

AddCommandMethod · 0.95
PersistentFlagsMethod · 0.95
InheritedFlagsMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected