| 11 | ) |
| 12 | |
| 13 | func TestLookPath(t *testing.T) { |
| 14 | root, wderr := os.Getwd() |
| 15 | if wderr != nil { |
| 16 | t.Fatal(wderr) |
| 17 | } |
| 18 | |
| 19 | if err := os.Chdir(filepath.Join(root, "_fixtures", "cwd")); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | |
| 23 | testCases := []struct { |
| 24 | desc string |
| 25 | path []string |
| 26 | pathext string |
| 27 | arg string |
| 28 | wants string |
| 29 | wantErr bool |
| 30 | }{ |
| 31 | { |
| 32 | desc: "no extension", |
| 33 | path: []string{ |
| 34 | filepath.Join(root, "_fixtures", "nonexist"), |
| 35 | filepath.Join(root, "_fixtures", "system"), |
| 36 | }, |
| 37 | pathext: "", |
| 38 | arg: "ls", |
| 39 | wants: filepath.Join(root, "_fixtures", "system", "ls"+winonly(".exe")), |
| 40 | wantErr: false, |
| 41 | }, |
| 42 | { |
| 43 | desc: "with extension", |
| 44 | path: []string{filepath.Join(root, "_fixtures", "system")}, |
| 45 | pathext: "", |
| 46 | arg: "ls.exe", |
| 47 | wants: filepath.Join(root, "_fixtures", "system", "ls.exe"), |
| 48 | wantErr: false, |
| 49 | }, |
| 50 | { |
| 51 | desc: "with path", |
| 52 | path: []string{filepath.Join(root, "_fixtures", "system")}, |
| 53 | pathext: "", |
| 54 | arg: filepath.Join("..", "system", "ls"), |
| 55 | wants: filepath.Join("..", "system", "ls"+winonly(".exe")), |
| 56 | wantErr: false, |
| 57 | }, |
| 58 | { |
| 59 | desc: "with path+extension", |
| 60 | path: []string{filepath.Join(root, "_fixtures", "system")}, |
| 61 | pathext: "", |
| 62 | arg: filepath.Join("..", "system", "ls.bat"), |
| 63 | wants: filepath.Join("..", "system", "ls.bat"), |
| 64 | wantErr: false, |
| 65 | }, |
| 66 | { |
| 67 | desc: "no extension, PATHEXT", |
| 68 | path: []string{filepath.Join(root, "_fixtures", "system")}, |
| 69 | pathext: ".com;.bat", |
| 70 | arg: "ls", |