Debian Codegraph @

libgo/go/os/exec/lp_unix_test.go

raw
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 aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
6
7 package exec
8
9 import (
10 "os"
11 "testing"
12 )
13
14 func TestLookPathUnixEmptyPath(t *testing.T) {
15 tmp, err := os.MkdirTemp("", "TestLookPathUnixEmptyPath")
16 if err != nil {
17 t.Fatal("TempDir failed: ", err)
18 }
19 defer os.RemoveAll(tmp)
20 wd, err := os.Getwd()
21 if err != nil {
22 t.Fatal("Getwd failed: ", err)
23 }
24 err = os.Chdir(tmp)
25 if err != nil {
26 t.Fatal("Chdir failed: ", err)
27 }
28 defer os.Chdir(wd)
29
30 f, err := os.OpenFile("exec_me", os.O_CREATE|os.O_EXCL, 0700)
31 if err != nil {
32 t.Fatal("OpenFile failed: ", err)
33 }
34 err = f.Close()
35 if err != nil {
36 t.Fatal("Close failed: ", err)
37 }
38
39 t.Setenv("PATH", "")
40
41 path, err := LookPath("exec_me")
42 if err == nil {
43 t.Fatal("LookPath found exec_me in empty $PATH")
44 }
45 if path != "" {
46 t.Fatalf("LookPath path == %q when err != nil", path)
47 }
48 }