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

Function TestGlobalNormFuncPropagation

command_test.go:1789–1806  ·  view source on GitHub ↗

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

(t *testing.T)

Source from the content-addressed store, hash-verified

1787
1788// Related to https://github.com/spf13/cobra/issues/521.
1789func TestGlobalNormFuncPropagation(t *testing.T) {
1790 normFunc := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
1791 return pflag.NormalizedName(name)
1792 }
1793
1794 rootCmd := &Command{Use: "root", Run: emptyRun}
1795 childCmd := &Command{Use: "child", Run: emptyRun}
1796 rootCmd.AddCommand(childCmd)
1797
1798 rootCmd.SetGlobalNormalizationFunc(normFunc)
1799 if reflect.ValueOf(normFunc).Pointer() != reflect.ValueOf(rootCmd.GlobalNormalizationFunc()).Pointer() {
1800 t.Error("rootCmd seems to have a wrong normalization function")
1801 }
1802
1803 if reflect.ValueOf(normFunc).Pointer() != reflect.ValueOf(childCmd.GlobalNormalizationFunc()).Pointer() {
1804 t.Error("childCmd should have had the normalization function of rootCmd")
1805 }
1806}
1807
1808// Related to https://github.com/spf13/cobra/issues/521.
1809func TestNormPassedOnLocal(t *testing.T) {

Callers

nothing calls this directly

Calls 4

AddCommandMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected