< Summary - Neospec Coverage

Information
Line coverage
100%
Covered lines: 43
Uncovered lines: 0
Coverable lines: 43
Total lines: 99
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Write0%00100%
fprintColor0%00100%
statusSymbol0%00100%

File(s)

/home/runner/work/neospec/neospec/internal/adapters/reporter/console.go

#LineLine coverage
 1// Package reporter contains implementations of ports.Reporter for each
 2// supported output format.
 3package reporter
 4
 5import (
 6  "context"
 7  "fmt"
 8  "io"
 9
 10  "github.com/jedi-knights/neospec/internal/domain"
 11)
 12
 13// Console writes a human-readable test and coverage summary to the writer.
 14// It uses ANSI color codes when the writer is likely a TTY; callers that need
 15// plain text can wrap the writer with a color-stripping adapter.
 16type Console struct {
 17  // Color controls whether ANSI escape codes are emitted.
 18  Color bool
 19}
 20
 21// NewConsole creates a Console reporter. Pass color=true for terminal output.
 22func NewConsole(color bool) *Console {
 23  return &Console{Color: color}
 24}
 25
 926func (c *Console) Write(_ context.Context, w io.Writer, suite *domain.SuiteResult, cov *domain.CoverageData) error {
 927  pass, fail, skip, errors := suite.Counts()
 928
 929  for _, t := range suite.Tests {
 1330    symbol, color := c.statusSymbol(t.Status)
 1331    c.fprintColor(w, color, fmt.Sprintf("  %s %s\n", symbol, t.Name))
 332    if t.Error != "" {
 333      c.fprintColor(w, colorRed, fmt.Sprintf("    %s\n", t.Error))
 334    }
 35  }
 36
 937  fmt.Fprintln(w)
 938  summary := fmt.Sprintf(
 939    "Tests: %d passed, %d failed, %d skipped, %d errors  (%.2fs)\n",
 940    pass, fail, skip, errors,
 941    suite.Duration.Seconds(),
 942  )
 243  if fail > 0 || errors > 0 {
 244    c.fprintColor(w, colorRed, summary)
 245  } else {
 746    c.fprintColor(w, colorGreen, summary)
 747  }
 48
 749  if cov != nil && cov.TotalLines() > 0 {
 750    pct := cov.Percentage()
 751    covLine := fmt.Sprintf("Coverage: %s (%d/%d lines)\n",
 752      domain.BadgeLabel(pct), cov.HitLines(), cov.TotalLines())
 753    c.fprintColor(w, colorForPct(pct), covLine)
 754  }
 55
 956  return nil
 57}
 58
 59const (
 60  colorReset  = "\033[0m"
 61  colorRed    = "\033[31m"
 62  colorGreen  = "\033[32m"
 63  colorYellow = "\033[33m"
 64  colorOrange = "\033[38;5;208m"
 65)
 66
 67func colorForPct(pct float64) string {
 68  switch domain.BadgeColor(pct) {
 69  case "brightgreen", "green":
 70    return colorGreen
 71  case "yellow":
 72    return colorYellow
 73  case "orange":
 74    return colorOrange
 75  default:
 76    return colorRed
 77  }
 78}
 79
 3280func (c *Console) fprintColor(w io.Writer, color, s string) {
 381  if c.Color {
 382    fmt.Fprintf(w, "%s%s%s", color, s, colorReset)
 383  } else {
 2984    fmt.Fprint(w, s)
 2985  }
 86}
 87
 1388func (c *Console) statusSymbol(s domain.TestStatus) (string, string) {
 1389  switch s {
 990  case domain.StatusPass:
 991    return "✓", colorGreen
 292  case domain.StatusFail:
 293    return "✗", colorRed
 194  case domain.StatusSkip:
 195    return "○", colorYellow
 196  default:
 197    return "!", colorOrange
 98  }
 99}

Methods/Properties

Write
fprintColor
statusSymbol