本文整理汇总了Golang中github.com/constabulary/gb.Package.Run方法的典型用法代码示例。如果您正苦于以下问题:Golang Package.Run方法的具体用法?Golang Package.Run怎么用?Golang Package.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/constabulary/gb.Package
的用法示例。
在下文中一共展示了Package.Run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testPackage
func testPackage(targets map[string]gb.PkgTarget, pkg *gb.Package, flags []string) gb.Target {
var gofiles []string
gofiles = append(gofiles, pkg.GoFiles...)
gofiles = append(gofiles, pkg.TestGoFiles...)
var cgofiles []string
cgofiles = append(cgofiles, pkg.CgoFiles...)
var imports []string
imports = append(imports, pkg.Package.Imports...)
imports = append(imports, pkg.Package.TestImports...)
name := pkg.Name
if name == "main" {
// rename the main package to its package name for testing.
name = filepath.Base(filepath.FromSlash(pkg.ImportPath))
}
// internal tests
testpkg := gb.NewPackage(pkg.Context, &build.Package{
Name: name,
ImportPath: pkg.ImportPath,
Dir: pkg.Dir,
SrcRoot: pkg.SrcRoot,
GoFiles: gofiles,
CFiles: pkg.CFiles,
CgoFiles: cgofiles,
TestGoFiles: pkg.TestGoFiles, // passed directly to buildTestMain
XTestGoFiles: pkg.XTestGoFiles, // passed directly to buildTestMain
CgoCFLAGS: pkg.CgoCFLAGS,
CgoCPPFLAGS: pkg.CgoCPPFLAGS,
CgoCXXFLAGS: pkg.CgoCXXFLAGS,
CgoLDFLAGS: pkg.CgoLDFLAGS,
CgoPkgConfig: pkg.CgoPkgConfig,
Imports: imports,
})
// build dependencies
deps := gb.BuildDependencies(targets, testpkg)
testpkg.Scope = "test"
testpkg.Stale = true
testobj := gb.Compile(testpkg, deps...)
// external tests
if len(pkg.XTestGoFiles) > 0 {
xtestpkg := gb.NewPackage(pkg.Context, &build.Package{
Name: name,
ImportPath: pkg.ImportPath + "_test",
Dir: pkg.Dir,
GoFiles: pkg.XTestGoFiles,
Imports: pkg.XTestImports,
})
// build external test dependencies
deps := gb.BuildDependencies(targets, xtestpkg)
xtestpkg.Scope = "test"
xtestpkg.Stale = true
xtestpkg.ExtraIncludes = filepath.Join(pkg.Workdir(), filepath.FromSlash(pkg.ImportPath), "_test")
testobj = gb.Compile(xtestpkg, append(deps, testobj)...)
}
testmain, err := buildTestMain(testpkg)
if err != nil {
return gb.ErrTarget{err}
}
buildmain := gb.Ld(testmain, gb.Compile(testmain, testobj))
cmd := exec.Command(testmain.Binfile()+".test", flags...)
cmd.Dir = pkg.Dir // tests run in the original source directory
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
gb.Debugf("scheduling run of %v", cmd.Args)
return pkg.Run(cmd, buildmain)
}