Conversation
…act helper, merge tests Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
pkg/cli/actionlint_test.go
Outdated
| ) | ||
|
|
||
| // captureStderr runs fn and returns what was written to stderr. | ||
| func captureStderr(t *testing.T, fn func()) string { |
There was a problem hiding this comment.
@copilot find a helper for this or refactor into a test helper.
There was a problem hiding this comment.
Moved into testutil.CaptureStderr in pkg/testutil/tempdir.go so it's reusable across the codebase. The local captureStderr helper is removed and all call sites in actionlint_test.go now use testutil.CaptureStderr(...). (95a4b85)
…packages Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves test quality in pkg/cli/actionlint_test.go by adopting testify assertions, reducing code duplication, and improving test maintainability. The changes align with codebase testing conventions seen throughout the repository where testify is used extensively.
Changes:
- Adopted testify/assert and testify/require for all test assertions
- Extracted stderr capture logic into a reusable
testutil.CaptureStderrhelper - Consolidated test cases by merging multi-file tests into the main test function
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/testutil/tempdir.go | Added CaptureStderr helper function for reusable stderr capture across tests |
| pkg/cli/actionlint_test.go | Converted all manual assertions to testify, merged duplicate test functions, simplified test logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
testify/assertandtestify/requireimportscaptureStderrhelper to reduce code duplicationcaptureStderrtotestutil.CaptureStderrfor codebase-wide reuseTestParseAndDisplayActionlintOutputMultiFileintoTestParseAndDisplayActionlintOutputt.Errorf/t.Error/t.Fatalto testify assertions with descriptive messagesTestGetActionlintVersionto only test the cached version case properlyTestInitActionlintStatsto use testify assertionsTestGetActionlintDocsURLto use testify assertionsOriginal prompt
This section details on the original issue you should resolve
<issue_title>[testify-expert] Improve Test Quality: pkg/cli/actionlint_test.go</issue_title>
<issue_description>The test file
pkg/cli/actionlint_test.gohas been selected for quality improvement by the Testify Uber Super Expert. This issue provides specific, actionable recommendations to enhance test quality using testify best practices.Current State
pkg/cli/actionlint_test.gopkg/cli/actionlint.goTestParseAndDisplayActionlintOutput,TestGetActionlintVersion,TestParseAndDisplayActionlintOutputMultiFile,TestDisplayActionlintSummary,TestInitActionlintStats,TestGetActionlintDocsURL)testifybeing available and used throughout the codebaseTest Quality Analysis
Strengths ✅
t.Run()subtests throughoutAreas for Improvement 🎯
1. No Testify Assertions — Zero testify usage
The file does not import testify at all, relying entirely on manual Go testing patterns (
t.Errorf,t.Error,t.Fatal). This is inconsistent with the rest of the codebase.Current Issues:
Recommended Changes:
Why this matters: Testify provides clearer error messages, better test output, and is the standard used throughout this codebase (see
scratchpad/testing.md).2. Duplicated Test Body in
TestParseAndDisplayActionlintOutputMultiFileTestParseAndDisplayActionlintOutputMultiFileis a separate test function that duplicates the exact same assertion logic asTestParseAndDisplayActionlintOutput. They test the same function with different data but have identical assertion boilerplate.Recommended Change: Merge into a single
TestParseAndDisplayActionlintOutputwith additional table-driven test cases:3. Duplicated Stderr Capture Setup
The stderr capture setup is copy-pasted verbatim in
TestParseAndDisplayActionlintOutput,TestParseAndDisplayActionlintOutputMultiFile, andTestDisplayActionlintSummary. This is brittle and hard to maintain.Recommended Change: Extract a helper:
Usage:
4.
TestInitActionlintStats— No Testify, Verbose Manual ChecksThis function uses 5 separate ...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.