1
0
mirror of https://github.com/golang/go synced 2024-11-27 00:41:31 -07:00
go/src/runtime/signal_windows_test.go
Tom Thorogood 9cce08d724 cmd/go/internal/renameio,runtime: avoid leaking temp directory in test
TestWriteFileModeAppliesUmask and TestVectoredHandlerDontCrashOnLibrary
could both leak /tmp/go-build-* directories which isn't very friendly.

Change-Id: Ibee9c33d49ad48958fae4df73853b82d92314bf0
GitHub-Last-Rev: 814e2fa4bb
GitHub-Pull-Request: golang/go#34253
Reviewed-on: https://go-review.googlesource.com/c/go/+/194880
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-12 15:52:35 +00:00

62 lines
1.6 KiB
Go

// +build windows
package runtime_test
import (
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestVectoredHandlerDontCrashOnLibrary(t *testing.T) {
if *flagQuick {
t.Skip("-quick")
}
if runtime.GOARCH != "amd64" {
t.Skip("this test can only run on windows/amd64")
}
testenv.MustHaveGoBuild(t)
testenv.MustHaveExecPath(t, "gcc")
testprog.Lock()
defer testprog.Unlock()
dir, err := ioutil.TempDir("", "go-build")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(dir)
// build go dll
dll := filepath.Join(dir, "testwinlib.dll")
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", dll, "--buildmode", "c-shared", "testdata/testwinlib/main.go")
out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("failed to build go library: %s\n%s", err, out)
}
// build c program
exe := filepath.Join(dir, "test.exe")
cmd = exec.Command("gcc", "-L"+dir, "-I"+dir, "-ltestwinlib", "-o", exe, "testdata/testwinlib/main.c")
out, err = testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("failed to build c exe: %s\n%s", err, out)
}
// run test program
cmd = exec.Command(exe)
out, err = testenv.CleanCmdEnv(cmd).CombinedOutput()
if err != nil {
t.Fatalf("failure while running executable: %s\n%s", err, out)
}
expectedOutput := "exceptionCount: 1\ncontinueCount: 1\n"
// cleaning output
cleanedOut := strings.ReplaceAll(string(out), "\r\n", "\n")
if cleanedOut != expectedOutput {
t.Errorf("expected output %q, got %q", expectedOutput, cleanedOut)
}
}