From 32f4d8a7df5d5d4e2ef4793696d7aa73d6065a02 Mon Sep 17 00:00:00 2001 From: 3v0k4 Date: Wed, 5 Jun 2024 21:13:27 +0200 Subject: [PATCH] -P not available in old versions of env --- main.go | 3 +-- main_test.go | 20 -------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/main.go b/main.go index a025eb0..eebe1b6 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/main_test.go b/main_test.go index a761be0..be97af2 100644 --- a/main_test.go +++ b/main_test.go @@ -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