search_unix_test.go 790 B

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build !windows && !plan9 && !js
  2. package fsutil
  3. import (
  4. "reflect"
  5. "sort"
  6. "testing"
  7. "src.elv.sh/pkg/testutil"
  8. )
  9. func TestEachExternal(t *testing.T) {
  10. binPath := testutil.InTempDir(t)
  11. testutil.Setenv(t, "PATH", "/foo:"+binPath+":/bar")
  12. testutil.ApplyDir(testutil.Dir{
  13. "dir": testutil.Dir{},
  14. "file": "",
  15. "cmdx": "#!/bin/sh",
  16. "cmd1": testutil.File{Perm: 0755, Content: "#!/bin/sh"},
  17. "cmd2": testutil.File{Perm: 0755, Content: "#!/bin/sh"},
  18. "cmd3": testutil.File{Perm: 0755, Content: ""},
  19. })
  20. wantCmds := []string{"cmd1", "cmd2", "cmd3"}
  21. gotCmds := []string{}
  22. EachExternal(func(cmd string) { gotCmds = append(gotCmds, cmd) })
  23. sort.Strings(gotCmds)
  24. if !reflect.DeepEqual(wantCmds, gotCmds) {
  25. t.Errorf("EachExternal want %q got %q", wantCmds, gotCmds)
  26. }
  27. }