add testcontext.Compile (#1356)
This commit is contained in:
parent
fde0020c68
commit
307cc640b6
31
internal/testcontext/compile.go
Normal file
31
internal/testcontext/compile.go
Normal file
@ -0,0 +1,31 @@
|
||||
// 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
|
||||
}
|
8
internal/testcontext/compile_norace.go
Normal file
8
internal/testcontext/compile_norace.go
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
// +build !race
|
||||
|
||||
package testcontext
|
||||
|
||||
const raceEnabled = false
|
8
internal/testcontext/compile_race.go
Normal file
8
internal/testcontext/compile_race.go
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
// +build race
|
||||
|
||||
package testcontext
|
||||
|
||||
const raceEnabled = true
|
20
internal/testcontext/compile_test.go
Normal file
20
internal/testcontext/compile_test.go
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package testcontext_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
)
|
||||
|
||||
func TestCompile(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
|
||||
exe := ctx.Compile("storj.io/storj/examples/pointerdb-client")
|
||||
assert.NotEmpty(t, exe)
|
||||
}
|
Loading…
Reference in New Issue
Block a user