From 9ffbf2997150d3566659b50fb55387118cffaed9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 23 Jul 2014 15:37:37 -0400 Subject: [PATCH] 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 --- go/ssa/testmain.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/go/ssa/testmain.go b/go/ssa/testmain.go index 448338b084..0d915a2b98 100644 --- a/go/ssa/testmain.go +++ b/go/ssa/testmain.go @@ -17,6 +17,12 @@ import ( "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" // package that runs all the tests of the supplied packages, similar // 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, } init.startBody() + + if testMainStartBodyHook != nil { + testMainStartBodyHook(init) + } + // TODO(adonovan): use lexical order. var expfuncs []*Function // all exported functions of *_test.go in pkgs, unordered for _, pkg := range pkgs { @@ -113,6 +124,11 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package { matcher.finishBody() main.startBody() + + if testMainStartBodyHook != nil { + testMainStartBodyHook(main) + } + var c Call c.Call.Value = testingMain