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

Function TestCommandsAreSorted

command_test.go:1913–1933  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1911}
1912
1913func TestCommandsAreSorted(t *testing.T) {
1914 EnableCommandSorting = true
1915
1916 originalNames := []string{"middle", "zlast", "afirst"}
1917 expectedNames := []string{"afirst", "middle", "zlast"}
1918
1919 var rootCmd = &Command{Use: "root"}
1920
1921 for _, name := range originalNames {
1922 rootCmd.AddCommand(&Command{Use: name})
1923 }
1924
1925 for i, c := range rootCmd.Commands() {
1926 got := c.Name()
1927 if expectedNames[i] != got {
1928 t.Errorf("Expected: %s, got: %s", expectedNames[i], got)
1929 }
1930 }
1931
1932 EnableCommandSorting = defaultCommandSorting
1933}
1934
1935func TestEnableCommandSortingIsDisabled(t *testing.T) {
1936 EnableCommandSorting = false

Callers

nothing calls this directly

Calls 3

AddCommandMethod · 0.80
CommandsMethod · 0.80
NameMethod · 0.80

Tested by

no test coverage detected