trunkLike takes TrunkBranch where it named the string again, so the first watched branch changes in one place. Builds: design 47 G §7, A-93 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package index
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A-93, design 47 G §7: the trunk `main` is named once in the indexer, as TrunkBranch; no other non-test source of the module holds the
|
|
// string, so the first watched branch changes in one place.
|
|
func TestTheTrunkIsNamedOnceInTheIndexer(t *testing.T) {
|
|
var named []string
|
|
for _, dir := range []string{".", "../../cmd/mesh-delivery-indexer", "../judge"} {
|
|
files, err := filepath.Glob(filepath.Join(dir, "*.go"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, f := range files {
|
|
if strings.HasSuffix(f, "_test.go") {
|
|
continue
|
|
}
|
|
src, err := os.ReadFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, line := range strings.Split(string(src), "\n") {
|
|
if t := strings.TrimSpace(line); strings.Contains(line, `"main"`) && !strings.HasPrefix(t, "//") {
|
|
named = append(named, filepath.Base(f))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(named) != 1 {
|
|
t.Errorf(`"main" is named %d times in code (%v), want once: TrunkBranch`, len(named), named)
|
|
}
|
|
}
|