cli/cmd/test/test.go
Snider cdf74d9f30 refactor(cmd): split command packages into smaller files
Split all cmd/* packages for maintainability, following the pattern
established in cmd/php. Each package now has:
- Main file with styles (using cmd/shared) and Add*Commands function
- Separate files for logical command groupings

Packages refactored:
- cmd/dev: 13 files (was 2779 lines in one file)
- cmd/build: 5 files (was 913 lines)
- cmd/setup: 6 files (was 961 lines)
- cmd/go: 5 files (was 655 lines)
- cmd/pkg: 5 files (was 634 lines)
- cmd/vm: 4 files (was 717 lines)
- cmd/ai: 5 files (was 800 lines)
- cmd/docs: 5 files (was 379 lines)
- cmd/doctor: 5 files (was 301 lines)
- cmd/test: 3 files (was 429 lines)
- cmd/ci: 5 files (was 272 lines)

All packages now import shared styles from cmd/shared instead of
redefining them locally.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 00:22:47 +00:00

67 lines
2.4 KiB
Go

// Package testcmd provides test running commands.
//
// Note: Package named testcmd to avoid conflict with Go's test package.
package testcmd
import (
"github.com/charmbracelet/lipgloss"
"github.com/host-uk/core/cmd/shared"
"github.com/leaanthony/clir"
)
// Style aliases from shared
var (
testHeaderStyle = shared.RepoNameStyle
testPassStyle = shared.SuccessStyle
testFailStyle = shared.ErrorStyle
testSkipStyle = shared.WarningStyle
testDimStyle = shared.DimStyle
)
// Coverage-specific styles
var (
testCovHighStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#22c55e")) // green-500
testCovMedStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#f59e0b")) // amber-500
testCovLowStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#ef4444")) // red-500
)
// AddTestCommand adds the 'test' command to the given parent command.
func AddTestCommand(parent *clir.Cli) {
var verbose bool
var coverage bool
var short bool
var pkg string
var run string
var race bool
var json bool
testCmd := parent.NewSubCommand("test", "Run tests with coverage")
testCmd.LongDescription("Runs Go tests with coverage reporting.\n\n" +
"Sets MACOSX_DEPLOYMENT_TARGET=26.0 to suppress linker warnings on macOS.\n\n" +
"Examples:\n" +
" core test # Run all tests with coverage summary\n" +
" core test --verbose # Show test output as it runs\n" +
" core test --coverage # Show detailed per-package coverage\n" +
" core test --pkg ./pkg/... # Test specific packages\n" +
" core test --run TestName # Run specific test by name\n" +
" core test --short # Skip long-running tests\n" +
" core test --race # Enable race detector\n" +
" core test --json # Output JSON for CI/agents")
testCmd.BoolFlag("verbose", "Show test output as it runs (-v)", &verbose)
testCmd.BoolFlag("coverage", "Show detailed per-package coverage", &coverage)
testCmd.BoolFlag("short", "Skip long-running tests (-short)", &short)
testCmd.StringFlag("pkg", "Package pattern to test (default: ./...)", &pkg)
testCmd.StringFlag("run", "Run only tests matching this regex (-run)", &run)
testCmd.BoolFlag("race", "Enable race detector (-race)", &race)
testCmd.BoolFlag("json", "Output JSON for CI/agents", &json)
testCmd.Action(func() error {
return runTest(verbose, coverage, short, pkg, run, race, json)
})
}