Merge pull request #2 from dmarkham/fix-non-windows

Fix non windows
This commit is contained in:
Dan Markham 2019-04-04 15:47:42 -07:00 committed by GitHub
commit 2c68820d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -16,10 +16,24 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
var (
// GOEXE defines the executable file name suffix (".exe" on Windows, "" on other systems).
// Must be defined here, cannot be read from ENVIRONMENT variables
GOEXE = ""
)
func init() {
// Set GOEXE for Windows platform
if runtime.GOOS == "windows" {
GOEXE = ".exe"
}
}
// This file contains a test that compiles and runs each program in testdata
// after generating the string method for its type. The rule is that for testdata/x.go
// we run stringer -type X and then compile and run the program. The resulting
@ -31,8 +45,9 @@ func TestEndToEnd(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(dir)
// Create stringer in temporary directory.
stringer := filepath.Join(dir, "stringer.exe")
stringer := filepath.Join(dir, fmt.Sprintf("stringer%s", GOEXE))
err = run("go", "build", "-o", stringer)
if err != nil {
t.Fatalf("building stringer: %s", err)