test(ananke): reject numbered split filenames
This commit is contained in:
parent
30558d676e
commit
a80acfc343
@ -17,6 +17,12 @@ import (
|
|||||||
const maxGoFileLOC = 500
|
const maxGoFileLOC = 500
|
||||||
|
|
||||||
var goFileNamePattern = regexp.MustCompile(`^[a-z0-9]+(_[a-z0-9]+)*(_test)?\.go$`)
|
var goFileNamePattern = regexp.MustCompile(`^[a-z0-9]+(_[a-z0-9]+)*(_test)?\.go$`)
|
||||||
|
var genericFileNameTokens = map[string]struct{}{
|
||||||
|
"chunk": {},
|
||||||
|
"part": {},
|
||||||
|
"piece": {},
|
||||||
|
"split": {},
|
||||||
|
}
|
||||||
|
|
||||||
func repoRoot(tb testing.TB) string {
|
func repoRoot(tb testing.TB) string {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
@ -61,13 +67,16 @@ func collectGoFiles(tb testing.TB, roots ...string) []string {
|
|||||||
func TestHygieneContracts(t *testing.T) {
|
func TestHygieneContracts(t *testing.T) {
|
||||||
root := repoRoot(t)
|
root := repoRoot(t)
|
||||||
files := collectGoFiles(t, filepath.Join(root, "cmd"), filepath.Join(root, "internal"))
|
files := collectGoFiles(t, filepath.Join(root, "cmd"), filepath.Join(root, "internal"))
|
||||||
|
namingFiles := append([]string{}, files...)
|
||||||
|
namingFiles = append(namingFiles, collectGoFiles(t, filepath.Join(root, "testing"))...)
|
||||||
sort.Strings(files)
|
sort.Strings(files)
|
||||||
|
sort.Strings(namingFiles)
|
||||||
|
|
||||||
t.Run("doc_contract", func(t *testing.T) {
|
t.Run("doc_contract", func(t *testing.T) {
|
||||||
checkDocContracts(t, files)
|
checkDocContracts(t, files)
|
||||||
})
|
})
|
||||||
t.Run("naming_contract", func(t *testing.T) {
|
t.Run("naming_contract", func(t *testing.T) {
|
||||||
checkNamingContracts(t, files)
|
checkNamingContracts(t, namingFiles)
|
||||||
})
|
})
|
||||||
t.Run("loc_limit", func(t *testing.T) {
|
t.Run("loc_limit", func(t *testing.T) {
|
||||||
checkFileLOCLimits(t, files)
|
checkFileLOCLimits(t, files)
|
||||||
@ -121,9 +130,19 @@ func checkNamingContracts(t *testing.T, files []string) {
|
|||||||
if !goFileNamePattern.MatchString(base) {
|
if !goFileNamePattern.MatchString(base) {
|
||||||
t.Errorf("%s: filename %q violates naming contract %s", file, base, goFileNamePattern.String())
|
t.Errorf("%s: filename %q violates naming contract %s", file, base, goFileNamePattern.String())
|
||||||
}
|
}
|
||||||
|
for _, token := range filenameTokens(base) {
|
||||||
|
if _, ok := genericFileNameTokens[token]; ok {
|
||||||
|
t.Errorf("%s: filename %q uses generic split-file token %q", file, base, token)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filenameTokens(name string) []string {
|
||||||
|
trimmed := strings.TrimSuffix(strings.TrimSuffix(name, ".go"), "_test")
|
||||||
|
return strings.Split(trimmed, "_")
|
||||||
|
}
|
||||||
|
|
||||||
// checkFileLOCLimits runs one orchestration or CLI step.
|
// checkFileLOCLimits runs one orchestration or CLI step.
|
||||||
// Signature: checkFileLOCLimits(t *testing.T, files []string).
|
// Signature: checkFileLOCLimits(t *testing.T, files []string).
|
||||||
// Why: A strict LOC cap forces focused files and keeps refactors manageable.
|
// Why: A strict LOC cap forces focused files and keeps refactors manageable.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user