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

Function TestConsistentNormalizedName

command_test.go:1851–1867  ·  view source on GitHub ↗

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

(t *testing.T)

Source from the content-addressed store, hash-verified

1849
1850// Related to https://github.com/spf13/cobra/issues/521.
1851func TestConsistentNormalizedName(t *testing.T) {
1852 toUpper := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
1853 return pflag.NormalizedName(strings.ToUpper(name))
1854 }
1855 n := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
1856 return pflag.NormalizedName(name)
1857 }
1858
1859 c := &Command{}
1860 c.Flags().Bool("flagname", true, "")
1861 c.SetGlobalNormalizationFunc(toUpper)
1862 c.SetGlobalNormalizationFunc(n)
1863
1864 if c.LocalFlags().Lookup("flagname") == c.LocalFlags().Lookup("FLAGNAME") {
1865 t.Error("Normalizing flag names should not result in duplicate flags")
1866 }
1867}
1868
1869func TestFlagOnPflagCommandLine(t *testing.T) {
1870 flagName := "flagOnCommandLine"

Callers

nothing calls this directly

Calls 4

FlagsMethod · 0.95
LocalFlagsMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected