Delete functions that no product code calls, and fold "simple plus WithOptions" pairs into the one signature callers actually use. Rename the live macOS lifecycle functions that were labelled Legacy. The architecture tests now share one source loader and reject functions without a product caller and catalog messages nobody reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
2.2 KiB
Go
99 lines
2.2 KiB
Go
package archtest
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
const modulePath = "github.com/Nwflower/reims-go"
|
|
|
|
// source is one Go file of the repository. All build constraints are covered:
|
|
// the checks read every file, not one platform's selection.
|
|
type source struct {
|
|
rel string // slash-separated path from the repository root
|
|
raw string
|
|
file *ast.File
|
|
}
|
|
|
|
func (s source) dir() string { return path.Dir(s.rel) }
|
|
func (s source) isTest() bool { return strings.HasSuffix(s.rel, "_test.go") }
|
|
|
|
// imports maps the local name of every module-internal import to its
|
|
// repository directory.
|
|
func (s source) imports() map[string]string {
|
|
out := map[string]string{}
|
|
for _, imp := range s.file.Imports {
|
|
p, err := strconv.Unquote(imp.Path.Value)
|
|
if err != nil || !strings.HasPrefix(p, modulePath+"/") {
|
|
continue
|
|
}
|
|
name := path.Base(p)
|
|
if imp.Name != nil {
|
|
name = imp.Name.Name
|
|
}
|
|
out[name] = strings.TrimPrefix(p, modulePath+"/")
|
|
}
|
|
return out
|
|
}
|
|
|
|
var fileSet = token.NewFileSet()
|
|
|
|
var loadSources = sync.OnceValues(func() ([]source, error) {
|
|
root, err := filepath.Abs(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
skip := map[string]bool{".git": true, ".debug": true, ".local": true, "build": true, "frontend": true, "node_modules": true, "archtest": true}
|
|
var out []source
|
|
err = filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() {
|
|
if skip[d.Name()] {
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
}
|
|
if !strings.HasSuffix(p, ".go") {
|
|
return nil
|
|
}
|
|
raw, err := os.ReadFile(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
f, err := parser.ParseFile(fileSet, p, raw, parser.SkipObjectResolution)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rel, err := filepath.Rel(root, p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out = append(out, source{rel: filepath.ToSlash(rel), raw: string(raw), file: f})
|
|
return nil
|
|
})
|
|
return out, err
|
|
})
|
|
|
|
func sources(t *testing.T) []source {
|
|
t.Helper()
|
|
all, err := loadSources()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(all) < 300 {
|
|
t.Fatalf("found only %d Go files: the walk no longer sees the repository", len(all))
|
|
}
|
|
return all
|
|
}
|