Skip to content
Myr

Reset root command lists in testing

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This fixes some issues that appear when testing prefix invocations. Since the root command lists weren't being cleared, the list would persist between tests, so there would be multiple instances of each command. Then, if you tried to match a prefix of one of those commands, you'd get two matches (one for each instance) and the command would fail. Resetting the root command lists prevents them from persisting between tests, resolving this issue.

authored by tummychow · committed by tummychow · parent f4c075f · Browse files · 1 file+2 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−0 removed

  • other:+2 added−0 removed

1 file+2 added−0 removed

modified:cobra_test.go+2 added
79 unmodified lines
80func commandInit() {81 cmdEcho.ResetCommands()82 cmdPrint.ResetCommands()83 cmdTimes.ResetCommands()84 cmdRootNoRun.ResetCommands()85 cmdRootWithRun.ResetCommands()86}8788func initialize() *Command {89 tt, tp, te = nil, nil, nil
274 unmodified lines