Source file src/os/exec_nohandle_test.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !linux && !windows
     6  
     7  package os_test
     8  
     9  import (
    10  	"internal/testenv"
    11  	. "os"
    12  	"testing"
    13  	"time"
    14  )
    15  
    16  func TestProcessWithHandleUnsupported(t *testing.T) {
    17  	const envVar = "OSTEST_PROCESS_WITH_HANDLE"
    18  	if Getenv(envVar) != "" {
    19  		time.Sleep(1 * time.Minute)
    20  		return
    21  	}
    22  
    23  	cmd := testenv.CommandContext(t, t.Context(), testenv.Executable(t), "-test.run=^"+t.Name()+"$")
    24  	cmd = testenv.CleanCmdEnv(cmd)
    25  	cmd.Env = append(cmd.Env, envVar+"=1")
    26  	if err := cmd.Start(); err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	defer func() {
    30  		cmd.Process.Kill()
    31  		cmd.Wait()
    32  	}()
    33  
    34  	err := cmd.Process.WithHandle(func(handle uintptr) {
    35  		t.Errorf("WithHandle: callback called unexpectedly with handle=%v", handle)
    36  	})
    37  	if err != ErrNoHandle {
    38  		t.Fatalf("WithHandle: got error %v, want %v", err, ErrNoHandle)
    39  	}
    40  }
    41  

View as plain text