(t *testing.T)
| 1595 | } |
| 1596 | |
| 1597 | func TestReplaceCommandWithRemove(t *testing.T) { |
| 1598 | childUsed := 0 |
| 1599 | rootCmd := &Command{Use: "root", Run: emptyRun} |
| 1600 | child1Cmd := &Command{ |
| 1601 | Use: "child", |
| 1602 | Run: func(*Command, []string) { childUsed = 1 }, |
| 1603 | } |
| 1604 | child2Cmd := &Command{ |
| 1605 | Use: "child", |
| 1606 | Run: func(*Command, []string) { childUsed = 2 }, |
| 1607 | } |
| 1608 | rootCmd.AddCommand(child1Cmd) |
| 1609 | rootCmd.RemoveCommand(child1Cmd) |
| 1610 | rootCmd.AddCommand(child2Cmd) |
| 1611 | |
| 1612 | output, err := executeCommand(rootCmd, "child") |
| 1613 | if output != "" { |
| 1614 | t.Errorf("Unexpected output: %v", output) |
| 1615 | } |
| 1616 | if err != nil { |
| 1617 | t.Errorf("Unexpected error: %v", err) |
| 1618 | } |
| 1619 | |
| 1620 | if childUsed == 1 { |
| 1621 | t.Error("Removed command shouldn't be called") |
| 1622 | } |
| 1623 | if childUsed != 2 { |
| 1624 | t.Error("Replacing command should have been called but didn't") |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | func TestDeprecatedCommand(t *testing.T) { |
| 1629 | rootCmd := &Command{Use: "root", Run: emptyRun} |
nothing calls this directly
no test coverage detected