Skip to content

Improve test quality: scripts/lint_error_messages_test.go#23706

Merged
pelikhan merged 3 commits intomainfrom
copilot/improve-test-quality-lint-error-messages
Mar 31, 2026
Merged

Improve test quality: scripts/lint_error_messages_test.go#23706
pelikhan merged 3 commits intomainfrom
copilot/improve-test-quality-lint-error-messages

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

scripts/lint_error_messages_test.go had zero testify usage and incomplete coverage — bare t.Errorf patterns, an unused wantContain field, only 3 of 7 regex patterns tested, and no tests for analyzeFile.

Changes

  • Testify adoption: Replace all if x != y { t.Errorf(...) } patterns with assert.Equal, assert.Nil/assert.NotNil, assert.NotEmpty, assert.Contains; use require.NoError for setup steps in TestAnalyzeFile
  • TestCheckErrorQuality: Simplified pass/fail branches to single assert.Nil/assert.NotNil with descriptive messages
  • TestSuggestImprovement: wantContain is now actually asserted via assert.Contains instead of being ignored
  • TestPatternMatching: Expanded from 4 cases (3 patterns) to 22 cases covering all 7 compiled regex patterns — hasExample, hasExpected, isValidationError, isFormatError, isTypeError, isEnumError, isWrappedError, hasDocLink — each with both a match and a non-match case
  • TestAnalyzeFile (new): 5 subtests exercising the core AST-walking function across compliant, non-compliant, mixed, empty, and unparseable files

Copilot AI and others added 2 commits March 31, 2026 13:10
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d351260f-2bbe-4728-ba3a-d5166fa126bd

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add testify imports (assert, require) replacing bare t.Errorf patterns
- Replace complex conditional in TestCheckErrorQuality with assert.Nil/NotNil
- Replace t.Errorf in TestShouldSkipQualityCheck with assert.Equal
- Update TestSuggestImprovement to use assert.NotEmpty and assert.Contains
  to verify wantContain field
- Expand TestPatternMatching from 4 cases (3 patterns) to 22 cases covering
  all 7 regex patterns with both matching and non-matching cases
- Add TestAnalyzeFile with 5 subtests covering compliant, non-compliant,
  mixed, empty, and invalid file scenarios
- Add helpful messages to all assertions

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d351260f-2bbe-4728-ba3a-d5166fa126bd

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve test quality for lint_error_messages_test.go Improve test quality: scripts/lint_error_messages_test.go Mar 31, 2026
Copilot AI requested a review from pelikhan March 31, 2026 13:17
@pelikhan pelikhan marked this pull request as ready for review March 31, 2026 13:18
Copilot AI review requested due to automatic review settings March 31, 2026 13:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the quality and coverage of scripts/lint_error_messages_test.go by adopting testify assertions and adding missing tests for regex pattern matching and analyzeFile.

Changes:

  • Replaced manual t.Errorf checks with testify/assert + testify/require for clearer, more consistent test failures.
  • Expanded TestPatternMatching to cover all compiled regexes with both match and non-match cases.
  • Added TestAnalyzeFile to exercise AST-walking behavior across compliant, non-compliant, mixed, empty, and unparseable files; removed now-unused indirect deps via tidy.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
scripts/lint_error_messages_test.go Switch to testify, expand regex coverage, and add new analyzeFile tests using temp Go files.
go.mod Removes an unused indirect dependency (github.com/sahilm/fuzzy).
go.sum Drops stale checksums consistent with dependency cleanup/tidy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

case "isWrappedError":
result = isWrappedError.MatchString(tt.message)
case "hasDocLink":
result = hasDocLink.MatchString(tt.message)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TestPatternMatching, the switch tt.pattern has no default case. If a new/typo pattern string is added with want: false, the test will silently pass because result stays at the zero value (false). Consider adding a default branch that fails the test (e.g., via t.Fatalf) when an unknown pattern key is encountered, so incorrect test cases don’t get masked.

Suggested change
result = hasDocLink.MatchString(tt.message)
result = hasDocLink.MatchString(tt.message)
default:
t.Fatalf("unknown pattern %q in test %q", tt.pattern, tt.name)

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit b7151ea into main Mar 31, 2026
65 of 67 checks passed
@pelikhan pelikhan deleted the copilot/improve-test-quality-lint-error-messages branch March 31, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[testify-expert] Improve Test Quality: scripts/lint_error_messages_test.go

3 participants