internal/processtest: bug fix: timeout didn't work for go-run

Apparently timing-out for a go-run process didn't work well. Instead,
use CommandContext for the actual test binary which is already built.
This commit is contained in:
Hajime Hoshi 2023-04-01 03:56:47 +09:00
parent 09d2459f1c
commit 4e7db88829

View File

@ -59,6 +59,11 @@ func TestPrograms(t *testing.T) {
// Run sub-tests one by one, not in parallel (#2571). // Run sub-tests one by one, not in parallel (#2571).
var m sync.Mutex var m sync.Mutex
tmpdir, err := os.MkdirTemp("", "ebitengine-processtest-*")
if err != nil {
t.Fatal(err)
}
for _, e := range ents { for _, e := range ents {
if e.IsDir() { if e.IsDir() {
continue continue
@ -72,10 +77,15 @@ func TestPrograms(t *testing.T) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
bin := filepath.Join(tmpdir, n)
if err := exec.Command("go", "build", "-o", bin, filepath.Join(dir, n)).Run(); err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel() defer cancel()
cmd := exec.CommandContext(ctx, "go", "run", filepath.Join(dir, n)) cmd := exec.CommandContext(ctx, bin)
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
cmd.Stderr = stderr cmd.Stderr = stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {