elvish/pkg/fsutil/search_unix_test.go
Qi Xiao d0be34c227 Run gofmt with Go 1.17.
This has created a lot of //go:build lines.
2021-08-23 00:19:49 +01:00

40 lines
1019 B
Go

//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js
package fsutil
import (
"reflect"
"sort"
"testing"
"src.elv.sh/pkg/testutil"
)
// TODO: When EachExternal is modified to work on Windows either fold this
// test into external_cmd_test.go or create an external_cmd_windows_test.go
// that performs an equivalent test on Windows.
func TestEachExternal(t *testing.T) {
binPath := testutil.InTempDir(t)
testutil.Setenv(t, "PATH", "/foo:"+binPath+":/bar")
testutil.ApplyDir(testutil.Dir{
"dir": testutil.Dir{},
"file": "",
"cmdx": "#!/bin/sh",
"cmd1": testutil.File{Perm: 0755, Content: "#!/bin/sh"},
"cmd2": testutil.File{Perm: 0755, Content: "#!/bin/sh"},
"cmd3": testutil.File{Perm: 0755, Content: ""},
})
wantCmds := []string{"cmd1", "cmd2", "cmd3"}
gotCmds := []string{}
EachExternal(func(cmd string) { gotCmds = append(gotCmds, cmd) })
sort.Strings(gotCmds)
if !reflect.DeepEqual(wantCmds, gotCmds) {
t.Errorf("EachExternal want %q got %q", wantCmds, gotCmds)
}
}