(t *testing.T)
| 1601 | } |
| 1602 | |
| 1603 | func TestWrappedCommandHelp(t *testing.T) { |
| 1604 | // Reset HelpPrinter after this test. |
| 1605 | defer func(old HelpPrinterFunc) { |
| 1606 | HelpPrinter = old |
| 1607 | }(HelpPrinter) |
| 1608 | |
| 1609 | output := &bytes.Buffer{} |
| 1610 | cmd := &Command{ |
| 1611 | Writer: output, |
| 1612 | ErrWriter: output, |
| 1613 | Commands: []*Command{ |
| 1614 | { |
| 1615 | Name: "add", |
| 1616 | Aliases: []string{"a"}, |
| 1617 | Usage: "add a task to the list", |
| 1618 | UsageText: "this is an even longer way of describing adding a task to the list", |
| 1619 | Description: "and a description long enough to wrap in this test case", |
| 1620 | Action: func(context.Context, *Command) error { |
| 1621 | return nil |
| 1622 | }, |
| 1623 | }, |
| 1624 | }, |
| 1625 | } |
| 1626 | cmd.setupDefaults([]string{"cli.test"}) |
| 1627 | cmd.setupCommandGraph() |
| 1628 | |
| 1629 | HelpPrinter = func(w io.Writer, templ string, data any) { |
| 1630 | funcMap := map[string]any{ |
| 1631 | "wrapAt": func() int { |
| 1632 | return 30 |
| 1633 | }, |
| 1634 | } |
| 1635 | |
| 1636 | HelpPrinterCustom(w, templ, data, funcMap) |
| 1637 | } |
| 1638 | |
| 1639 | r := require.New(t) |
| 1640 | |
| 1641 | r.NoError(ShowCommandHelp(context.Background(), cmd, "add")) |
| 1642 | r.Equal(`NAME: |
| 1643 | cli.test add - add a task |
| 1644 | to the list |
| 1645 | |
| 1646 | USAGE: |
| 1647 | this is an even longer way |
| 1648 | of describing adding a task |
| 1649 | to the list |
| 1650 | |
| 1651 | DESCRIPTION: |
| 1652 | and a description long |
| 1653 | enough to wrap in this test |
| 1654 | case |
| 1655 | |
| 1656 | OPTIONS: |
| 1657 | --help, -h show help |
| 1658 | `, |
| 1659 | output.String(), |
| 1660 | ) |
nothing calls this directly
no test coverage detected