2026-01-30 00:22:47 +00:00
|
|
|
package testcmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
|
|
|
|
|
"github.com/host-uk/core/pkg/i18n"
|
2026-01-30 00:22:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func runTest(verbose, coverage, short bool, pkg, run string, race, jsonOutput bool) error {
|
|
|
|
|
// Detect if we're in a Go project
|
|
|
|
|
if _, err := os.Stat("go.mod"); os.IsNotExist(err) {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
return fmt.Errorf(i18n.T("cmd.test.error.no_go_mod"))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build command arguments
|
|
|
|
|
args := []string{"test"}
|
|
|
|
|
|
|
|
|
|
// Default to ./... if no package specified
|
|
|
|
|
if pkg == "" {
|
|
|
|
|
pkg = "./..."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add flags
|
|
|
|
|
if verbose {
|
|
|
|
|
args = append(args, "-v")
|
|
|
|
|
}
|
|
|
|
|
if short {
|
|
|
|
|
args = append(args, "-short")
|
|
|
|
|
}
|
|
|
|
|
if run != "" {
|
|
|
|
|
args = append(args, "-run", run)
|
|
|
|
|
}
|
|
|
|
|
if race {
|
|
|
|
|
args = append(args, "-race")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Always add coverage
|
|
|
|
|
args = append(args, "-cover")
|
|
|
|
|
|
|
|
|
|
// Add package pattern
|
|
|
|
|
args = append(args, pkg)
|
|
|
|
|
|
|
|
|
|
// Create command
|
|
|
|
|
cmd := exec.Command("go", args...)
|
|
|
|
|
cmd.Dir, _ = os.Getwd()
|
|
|
|
|
|
|
|
|
|
// Set environment to suppress macOS linker warnings
|
|
|
|
|
cmd.Env = append(os.Environ(), getMacOSDeploymentTarget())
|
|
|
|
|
|
|
|
|
|
if !jsonOutput {
|
2026-01-30 11:44:45 +00:00
|
|
|
fmt.Printf("%s %s\n", testHeaderStyle.Render(i18n.T("common.label.test")), i18n.T("common.progress.running", map[string]any{"Task": "tests"}))
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" %s %s\n", i18n.T("common.label.package"), testDimStyle.Render(pkg))
|
2026-01-30 00:22:47 +00:00
|
|
|
if run != "" {
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" %s %s\n", i18n.T("common.label.filter"), testDimStyle.Render(run))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Capture output for parsing
|
|
|
|
|
var stdout, stderr strings.Builder
|
|
|
|
|
|
|
|
|
|
if verbose && !jsonOutput {
|
|
|
|
|
// Stream output in verbose mode, but also capture for parsing
|
|
|
|
|
cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
|
|
|
|
|
cmd.Stderr = io.MultiWriter(os.Stderr, &stderr)
|
|
|
|
|
} else {
|
|
|
|
|
// Capture output for parsing
|
|
|
|
|
cmd.Stdout = &stdout
|
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := cmd.Run()
|
|
|
|
|
exitCode := 0
|
|
|
|
|
if err != nil {
|
|
|
|
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
|
|
|
|
exitCode = exitErr.ExitCode()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Combine stdout and stderr for parsing, filtering linker warnings
|
|
|
|
|
combined := filterLinkerWarnings(stdout.String() + "\n" + stderr.String())
|
|
|
|
|
|
|
|
|
|
// Parse results
|
|
|
|
|
results := parseTestOutput(combined)
|
|
|
|
|
|
|
|
|
|
if jsonOutput {
|
|
|
|
|
// JSON output for CI/agents
|
|
|
|
|
printJSONResults(results, exitCode)
|
|
|
|
|
if exitCode != 0 {
|
2026-01-30 11:35:38 +00:00
|
|
|
return fmt.Errorf(i18n.T("common.error.failed", map[string]any{"Action": "run tests"}))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print summary
|
|
|
|
|
if !verbose {
|
|
|
|
|
printTestSummary(results, coverage)
|
|
|
|
|
} else if coverage {
|
|
|
|
|
// In verbose mode, still show coverage summary at end
|
|
|
|
|
fmt.Println()
|
|
|
|
|
printCoverageSummary(results)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if exitCode != 0 {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("\n%s %s\n", testFailStyle.Render(i18n.T("cli.fail")), i18n.T("cmd.test.tests_failed"))
|
2026-01-30 11:35:38 +00:00
|
|
|
return fmt.Errorf(i18n.T("common.error.failed", map[string]any{"Action": "run tests"}))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf("\n%s %s\n", testPassStyle.Render(i18n.T("cli.pass")), i18n.T("common.result.all_passed"))
|
2026-01-30 00:22:47 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getMacOSDeploymentTarget() string {
|
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
|
// Use deployment target matching current macOS to suppress linker warnings
|
|
|
|
|
return "MACOSX_DEPLOYMENT_TARGET=26.0"
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func filterLinkerWarnings(output string) string {
|
|
|
|
|
// Filter out ld: warning lines that pollute the output
|
|
|
|
|
var filtered []string
|
|
|
|
|
scanner := bufio.NewScanner(strings.NewReader(output))
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
line := scanner.Text()
|
|
|
|
|
// Skip linker warnings
|
|
|
|
|
if strings.HasPrefix(line, "ld: warning:") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// Skip test binary build comments
|
|
|
|
|
if strings.HasPrefix(line, "# ") && strings.HasSuffix(line, ".test") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
filtered = append(filtered, line)
|
|
|
|
|
}
|
|
|
|
|
return strings.Join(filtered, "\n")
|
|
|
|
|
}
|