Source file src/os/exec/lp_unix_test.go

     1  // Copyright 2013 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 unix
     6  
     7  package exec_test
     8  
     9  import (
    10  	"os"
    11  	"os/exec"
    12  	"testing"
    13  )
    14  
    15  func TestLookPathUnixEmptyPath(t *testing.T) {
    16  	// Not parallel: uses Chdir and Setenv.
    17  
    18  	tmp := t.TempDir()
    19  	t.Chdir(tmp)
    20  
    21  	f, err := os.OpenFile("exec_me", os.O_CREATE|os.O_EXCL, 0700)
    22  	if err != nil {
    23  		t.Fatal("OpenFile failed: ", err)
    24  	}
    25  	err = f.Close()
    26  	if err != nil {
    27  		t.Fatal("Close failed: ", err)
    28  	}
    29  
    30  	t.Setenv("PATH", "")
    31  
    32  	path, err := exec.LookPath("exec_me")
    33  	if err == nil {
    34  		t.Fatal("LookPath found exec_me in empty $PATH")
    35  	}
    36  	if path != "" {
    37  		t.Fatalf("LookPath path == %q when err != nil", path)
    38  	}
    39  }
    40  

View as plain text