mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
go.tools/go/ssa: add hook to testmain.go for proprietary (non-'go test') build systems.
Users need only add an extra file to the package to specify additional imports and initialization steps in testmain, to match their build system. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/120090043
This commit is contained in:
parent
129869a1a6
commit
9ffbf29971
@ -17,6 +17,12 @@ import (
|
|||||||
"code.google.com/p/go.tools/go/types"
|
"code.google.com/p/go.tools/go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// If non-nil, testMainStartBodyHook is called immediately after
|
||||||
|
// startBody for main.init and main.main, making it easy for users to
|
||||||
|
// add custom imports and initialization steps for proprietary build
|
||||||
|
// systems that don't exactly follow 'go test' conventions.
|
||||||
|
var testMainStartBodyHook func(*Function)
|
||||||
|
|
||||||
// CreateTestMainPackage creates and returns a synthetic "main"
|
// CreateTestMainPackage creates and returns a synthetic "main"
|
||||||
// package that runs all the tests of the supplied packages, similar
|
// package that runs all the tests of the supplied packages, similar
|
||||||
// to the one that would be created by the 'go test' tool.
|
// to the one that would be created by the 'go test' tool.
|
||||||
@ -43,6 +49,11 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
|||||||
Prog: prog,
|
Prog: prog,
|
||||||
}
|
}
|
||||||
init.startBody()
|
init.startBody()
|
||||||
|
|
||||||
|
if testMainStartBodyHook != nil {
|
||||||
|
testMainStartBodyHook(init)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(adonovan): use lexical order.
|
// TODO(adonovan): use lexical order.
|
||||||
var expfuncs []*Function // all exported functions of *_test.go in pkgs, unordered
|
var expfuncs []*Function // all exported functions of *_test.go in pkgs, unordered
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
@ -113,6 +124,11 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
|||||||
matcher.finishBody()
|
matcher.finishBody()
|
||||||
|
|
||||||
main.startBody()
|
main.startBody()
|
||||||
|
|
||||||
|
if testMainStartBodyHook != nil {
|
||||||
|
testMainStartBodyHook(main)
|
||||||
|
}
|
||||||
|
|
||||||
var c Call
|
var c Call
|
||||||
c.Call.Value = testingMain
|
c.Call.Value = testingMain
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user