Skip to content

chore: add unit tests for CRAP report formatting functions #202

Description

@yvonnedevlinrh

Context

Four report formatting functions in internal/crap/ were extracted during the q4-complexity-reduction work (decomposition of crap.WriteText from CC 18 to CC 2). The extracted helpers are small, focused functions with zero direct test coverage. Adding tests for these functions improves confidence in report output correctness and prevents regressions.

Related: codebase audit from #166 triage

Functions

Function File Lines Description
writeScoreTable internal/crap/report.go ~36 Renders the CRAP score table with columns for CRAP, complexity, coverage, function name, and location
writeWorstSection internal/crap/report.go ~32 Renders the "Worst Offenders" section with fix strategy labels
writeRemediationSection internal/crap/report.go ~13 Renders the "Remediation Breakdown" section with strategy counts
writeSSADiagnostics internal/crap/report.go ~11 Renders SSA degradation warnings listing affected packages

Approach

All four functions write to an io.Writer and accept structured data (slices of crap.Score, crap.Summary). Tests should:

  • Construct synthetic Score and Summary values
  • Call each function with a bytes.Buffer
  • Assert the output contains expected column headers, values, and formatting
  • Verify 80-column width compliance (per project convention)

Acceptance Criteria

  • Each function has at least one unit test verifying its primary output
  • Tests use synthetic data (no real CRAP analysis required)
  • Output width verified to fit within 80-column terminals
  • All tests run without testing.Short() guards
  • go test -race -count=1 -short ./internal/crap/... passes
  • golangci-lint run reports zero issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions