storj/internal/testcontext/compile.go
2019-02-27 09:25:28 +01:00

32 lines
611 B
Go

// 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
}