Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 2, 2025

This PR adds comprehensive function coverage support to go-covercheck, enabling users to track and enforce coverage thresholds at the function level alongside existing statement and block coverage.

Features Added

Function Coverage Tracking

  • Function counting: Uses Go AST parsing to accurately count function declarations in source files
  • Coverage calculation: Matches functions with coverage profile data to determine covered vs uncovered functions
  • Aggregation: Shows function coverage per file, per package, and total across the entire project

CLI Integration

New command-line flags for function coverage:

  • --function-threshold (-n): Set global function coverage threshold (default: 60%)
  • --total-function-threshold (-F): Override total function coverage threshold
  • --sort-by functions: Sort results by function hit count
  • --sort-by function-percent: Sort results by function coverage percentage

Configuration File Support

Function thresholds can be configured in .go-covercheck.yml:

functionThreshold: 60.0
total:
  functions: 80.0
perFile:
  functions:
    main.go: 0
perPackage:
  functions:
    pkg/config: 90

Enhanced Output

All output formats now include function coverage:

  • Table format: New "Functions" column showing coverage like 8/12 (66.7%)
  • JSON/YAML: Include functionCoverage, functionPercentage, and functionThreshold fields
  • Export formats: CSV, TSV, Markdown, and HTML all include function data
  • Failure reporting: Function coverage failures shown with [F] prefix in summary

History and Compare Support

  • History display: Function coverage shown in history table with [F] indicator
  • History comparison: Function coverage deltas displayed when comparing against previous commits
  • Complete integration: All history operations now include function coverage data

Example Output

┌─────────────────┬─────────────┬───────────┬─────────────┬─────────────┬───────────┬─────────────┐
│                 │ STATEMENTS  │  BLOCKS   │ FUNCTIONS   │ STATEMENT % │  BLOCK %  │ FUNCTION %  │
├─────────────────┼─────────────┼───────────┼─────────────┼─────────────┼───────────┼─────────────┤
│ pkg/config.go   │     47/55   │   32/40   │     5/6     │      85.5   │     80.0  │      83.3   │
│ pkg/compute.go  │    102/104  │   53/55   │     5/7     │      98.1   │     96.4  │      71.4   │
├─────────────────┼─────────────┼───────────┼─────────────┼─────────────┼───────────┼─────────────┤
│ BY TOTAL        │   629/731   │  378/462  │    64/73    │      86.0   │     81.8  │      87.7   │
└─────────────────┴─────────────┴───────────┴─────────────┴─────────────┴───────────┴─────────────┘

Technical Implementation

  • AST parsing: Uses go/ast package to parse Go source files and count function declarations
  • Coverage matching: Correlates function line ranges with coverage profile blocks to determine coverage status
  • Method support: Handles both regular functions and methods (functions with receivers)
  • Error handling: Gracefully handles missing source files and parsing errors
  • Minimal changes: Follows existing code patterns to maintain consistency

Testing

  • All existing tests continue to pass
  • Added comprehensive tests for function counting and coverage matching logic
  • Updated model tests to include new function-related fields
  • Updated history tests to include function coverage expectations
  • Verified functionality with real coverage data

This implementation provides complete function coverage analysis with full feature parity to the existing statement and block coverage functionality.

Fixes #40.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] [Feature] add support for func coverage Add function coverage support to go-covercheck Aug 2, 2025
Copilot AI requested a review from mach6 August 2, 2025 06:08
@mach6
Copy link
Owner

mach6 commented Aug 2, 2025

History and compare history should also work for func coverage

Copy link
Contributor Author

Copilot AI commented Aug 2, 2025

History and compare history should also work for func coverage

Function coverage support has been added to history and compare history functionality. This includes:

  • History display now shows function coverage with [F] indicator alongside statements [S] and blocks [B]
  • History comparison shows function coverage deltas when comparing against previous commits
  • All existing history operations now include function coverage data

The changes are implemented in commit a36f473 with updated tests to verify the functionality works correctly.

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.

[Feature] add support for func coverage

2 participants