Repository navigation
test: add table-driven CLI command tests with shared executor helper - #4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22d41d5623
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| out := &bytes.Buffer{} | ||
| errOut := &bytes.Buffer{} | ||
| RootCmd.SetOut(out) | ||
| RootCmd.SetErr(errOut) |
There was a problem hiding this comment.
Capture process stdout/stderr in command test helper
runCommandTest only captures RootCmd's writers, but several tested code paths write directly to process stdio (e.g. coloredHelpFunc uses fmt.Println and UI logging uses color printers). As a result, wantContains checks run against an empty buffer even when commands produce output, which makes help/success cases fail consistently and turns these table tests into false negatives.
Useful? React with 👍 / 👎.
| RootCmd.SilenceUsage = true | ||
| RootCmd.SilenceErrors = true |
There was a problem hiding this comment.
Stop silencing Cobra errors when asserting error output
The helper sets RootCmd.SilenceUsage and RootCmd.SilenceErrors to true but error-path test cases assert for Cobra-generated error text like "requires at least 1 arg". With both silence flags enabled, that text is intentionally suppressed from output, so those assertions fail regardless of command behavior.
Useful? React with 👍 / 👎.
Motivation
Description
cmd/command_exec_test.gowhich providesrunCommandTesthelper to setRootCmdargs, capture stdout/stderr, and assert error/exit semantics.completion(cmd/completion_cmd_test.go),add(cmd/add_cmd_test.go) andremove(cmd/remove_cmd_test.go) that cover missing required args, invalid input formats, flag combinations,--helpoutput, and success paths.setupTempConfigincmd/add_cmd_test.goto inject a temporarydeca.tomlby overridingconfigPathand restore it after the test.wantContainsfield to avoid brittle exact-string matches.Testing
go test ./cmd -run 'Test(AddCommand|RemoveCommand|CompletionCommand)'andgo test ./cmd -run TestCompletionCommand -vin the execution environment but the test runs did not complete within the session (hung/timeouts).Codex Task