storj/internal/testcontext/compile.go

32 lines
611 B
Go
Raw Normal View History

2019-02-27 08:25:28 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package testcontext
import (
"os/exec"
"path"
)
// Compile compiles the specified package and returns the executable name.
func (ctx *Context) Compile(pkg string) string {
ctx.test.Helper()
exe := ctx.File("build", path.Base(pkg)+".exe")
var cmd *exec.Cmd
if raceEnabled {
cmd = exec.Command("go", "build", "-race", "-o", exe, pkg)
} else {
cmd = exec.Command("go", "build", "-o", exe, pkg)
}
out, err := cmd.CombinedOutput()
if err != nil {
ctx.test.Error(string(out))
ctx.test.Fatal(err)
}
return exe
}