зеркало из https://github.com/golang/tools.git
go/ssa: add list-of-tests constant to generated testmain package
And log its value in godoc -analysis. Related to issue 8968 Change-Id: I96a96922a3fa5c434c69e0faff1cc8ec4686b6f2 Reviewed-on: https://go-review.googlesource.com/3154 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Родитель
f011631cea
Коммит
96af1504f6
|
@ -12,8 +12,10 @@ import (
|
|||
"go/ast"
|
||||
"go/token"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/exact"
|
||||
"golang.org/x/tools/go/types"
|
||||
)
|
||||
|
||||
|
@ -118,25 +120,33 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
|||
}
|
||||
|
||||
// Initialize packages to test.
|
||||
var pkgpaths []string
|
||||
for _, pkg := range pkgs {
|
||||
var v Call
|
||||
v.Call.Value = pkg.init
|
||||
v.setType(types.NewTuple())
|
||||
init.emit(&v)
|
||||
|
||||
pkgpaths = append(pkgpaths, pkg.Object.Path())
|
||||
}
|
||||
sort.Strings(pkgpaths)
|
||||
init.emit(new(Return))
|
||||
init.finishBody()
|
||||
testmain.init = init
|
||||
testmain.Object.MarkComplete()
|
||||
testmain.Members[init.name] = init
|
||||
|
||||
main := &Function{
|
||||
name: "main",
|
||||
Signature: new(types.Signature),
|
||||
Synthetic: "test main function",
|
||||
Prog: prog,
|
||||
Pkg: testmain,
|
||||
}
|
||||
// For debugging convenience, define an unexported const
|
||||
// that enumerates the packages.
|
||||
packagesConst := types.NewConst(token.NoPos, testmain.Object, "packages", tString,
|
||||
exact.MakeString(strings.Join(pkgpaths, " ")))
|
||||
memberFromObject(testmain, packagesConst, nil)
|
||||
|
||||
// Create main *types.Func and *ssa.Function
|
||||
mainFunc := types.NewFunc(token.NoPos, testmain.Object, "main", new(types.Signature))
|
||||
memberFromObject(testmain, mainFunc, nil)
|
||||
main := testmain.Func("main")
|
||||
main.Synthetic = "test main function"
|
||||
|
||||
main.startBody()
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/tools/go/exact"
|
||||
"golang.org/x/tools/go/loader"
|
||||
"golang.org/x/tools/go/pointer"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
|
@ -400,6 +401,9 @@ func Run(pta bool, result *Result) {
|
|||
var mainPkgs []*ssa.Package
|
||||
if testmain := prog.CreateTestMainPackage(allPackages...); testmain != nil {
|
||||
mainPkgs = append(mainPkgs, testmain)
|
||||
if p := testmain.Const("packages"); p != nil {
|
||||
log.Printf("Tested packages: %v", exact.StringVal(p.Value.Value))
|
||||
}
|
||||
}
|
||||
for _, pkg := range allPackages {
|
||||
if pkg.Object.Name() == "main" && pkg.Func("main") != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче