buildstep's generated.go and generated_test.go and claude-code's config_test.go reached the join unformatted: the second of a kind, which no check caught since each module's tests hold only themselves. All three are formatted, and checks/gofmt refuses a Go file of the catalogue gofmt would change. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package gofmt
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestUnformattedNamesWhatGofmtChanges(t *testing.T) {
|
|
root := t.TempDir()
|
|
for f, src := range map[string]string{
|
|
"modules/a/a.go": "package a\n",
|
|
"modules/b/b.go": "package b\nimport (\n\t\"os\"\n\t\"fmt\"\n)\nvar _, _ = fmt.Sprint, os.Exit\n",
|
|
"modules/c/testdata/c.go": "package c",
|
|
"modules/d/node_modules/d.go": "package d",
|
|
} {
|
|
p := filepath.Join(root, f)
|
|
_ = os.MkdirAll(filepath.Dir(p), 0o755)
|
|
if err := os.WriteFile(p, []byte(src), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
files, err := Files(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := Unformatted(root, files)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(files) != 2 || len(got) != 1 || got["modules/b/b.go"] == "" {
|
|
t.Errorf("files %v, unformatted %v; want a.go and b.go read, b.go named", files, got)
|
|
}
|
|
}
|
|
|
|
// The catalogue's own Go files are as gofmt writes them.
|
|
func TestTheCataloguesGoIsFormatted(t *testing.T) {
|
|
root := filepath.Join("..", "..")
|
|
files, err := Files(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(files) == 0 {
|
|
t.Fatal("no Go file found: the check reads nothing")
|
|
}
|
|
got, err := Unformatted(root, files)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for f, why := range got {
|
|
t.Errorf("%s: %s", f, why)
|
|
}
|
|
}
|