go-crypt/cmd/testcmd/output_test.go
Virgil 693964145e test: enforce AX exact test naming
Renames the remaining AX v0.8.0 test cases to the exact TestFile_Function_{Good,Bad,Ugly} pattern.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-27 04:46:56 +00:00

52 lines
1.7 KiB
Go

package testcmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOutput_ShortenPackageName_Good(t *testing.T) {
assert.Equal(t, "pkg/foo", shortenPackageName("dappco.re/go/core/pkg/foo"))
assert.Equal(t, "cli-php", shortenPackageName("example.com/org/cli-php"))
assert.Equal(t, "bar", shortenPackageName("github.com/other/bar"))
}
func TestOutput_FormatCoverage_Good(t *testing.T) {
assert.Contains(t, formatCoverage(85.0), "85.0%")
assert.Contains(t, formatCoverage(65.0), "65.0%")
assert.Contains(t, formatCoverage(25.0), "25.0%")
}
func TestOutput_ParseTestOutput_Good(t *testing.T) {
output := `ok dappco.re/go/core/pkg/foo 0.100s coverage: 50.0% of statements
FAIL dappco.re/go/core/pkg/bar
? dappco.re/go/core/pkg/baz [no test files]
`
results := parseTestOutput(output)
assert.Equal(t, 1, results.passed)
assert.Equal(t, 1, results.failed)
assert.Equal(t, 1, results.skipped)
assert.Equal(t, 1, len(results.failedPkgs))
assert.Equal(t, "dappco.re/go/core/pkg/bar", results.failedPkgs[0])
assert.Equal(t, 1, len(results.packages))
assert.Equal(t, 50.0, results.packages[0].coverage)
}
func TestOutput_PrintCoverageSummaryLongPackageNames_Good(t *testing.T) {
// This tests the bug fix for long package names causing negative Repeat count
results := testResults{
packages: []packageCoverage{
{name: "dappco.re/go/core/pkg/short", coverage: 100, hasCov: true},
{name: "dappco.re/go/core/pkg/a-very-very-very-very-very-long-package-name-that-might-cause-issues", coverage: 80, hasCov: true},
},
passed: 2,
totalCov: 180,
covCount: 2,
}
// Should not panic
assert.NotPanics(t, func() {
printCoverageSummary(results)
})
}