25 lines
530 B
Go
25 lines
530 B
Go
package main
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"testing"
|
|
)
|
|
|
|
func TestMainContainsOnlyProcessEntryPoints(t *testing.T) {
|
|
file, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, declaration := range file.Decls {
|
|
function, ok := declaration.(*ast.FuncDecl)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if function.Name.Name != "main" && function.Name.Name != "newRootCommand" {
|
|
t.Errorf("obsolete process entry or helper remains in main.go: %s", function.Name.Name)
|
|
}
|
|
}
|
|
}
|