Skip to content

Commit

Permalink
-P not available in old versions of env
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Jun 5, 2024
1 parent 5b81264 commit 32f4d8a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ func (p *program) unpathEntry(dir string, entries []fs.DirEntry, unpathN int) (s
}

func (p *program) run(cmd []string, path string) int {
arg := append([]string{"-P", path}, cmd...)
subcmd := exec.Command("env", arg...)
subcmd := exec.Command(cmd[0], cmd[1:]...)
subcmd.Env = append(subcmd.Environ(), fmt.Sprintf("PATH=%s", path))
subcmd.Stdout = p.stdout
subcmd.Stderr = p.stderr
Expand Down
20 changes: 0 additions & 20 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ import (
"testing"
)

func TestUnpathsNonExistingCommand(t *testing.T) {
var stdout, stderr bytes.Buffer
status := newProgram([]string{"unpath", "not-cat", "cat", "main_test.go"}, &stdout, &stderr).main()
if status != 0 {
t.Fatal(stderr)
}
}

func TestUnpathsCommand(t *testing.T) {
var stdout, stderr bytes.Buffer
status := newProgram([]string{"unpath", "cat", "cat", "main_test.go"}, &stdout, &stderr).main()
if status == 0 {
t.Errorf("got: %d; want: %d", status, 0)
}
message := "env: cat: No such file or directory"
if !strings.Contains(stderr.String(), message) {
t.Errorf("got: %s; want: %s", stderr.String(), message)
}
}

func TestUnpathsNonExistingCommandThroughScript(t *testing.T) {
script := createScript("#!/usr/bin/env bash\ncat $1", t.Fatal)
var stdout, stderr bytes.Buffer
Expand Down

0 comments on commit 32f4d8a

Please sign in to comment.