elvish/pkg/fsutil/search_windows_test.go
Qi Xiao e85afa2cbe Fixup for PR #1499.
- Use filepath.Ext instead of path.Ext

- Use cmp.Diff to generate test failure messages

- Misc stylistic changes
2022-03-12 23:22:34 +00:00

35 lines
953 B
Go

package fsutil
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"src.elv.sh/pkg/testutil"
)
func TestEachExternal(t *testing.T) {
binPath := testutil.InTempDir(t)
testutil.Setenv(t, "PATH", "Z:\\foo;"+binPath+";Z:\\bar")
testutil.ApplyDir(testutil.Dir{
"dir": testutil.Dir{},
"file.txt": "",
"prog.bat": testutil.File{Perm: 0o666, Content: ""},
"prog.cmd": testutil.File{Perm: 0o755, Content: ""},
"prog.txt": testutil.File{Perm: 0o755, Content: ""},
"PROG.EXE": "", // validate that explicit file perms don't matter
})
wantCmds := []string{"prog.bat", "prog.cmd", "PROG.EXE"}
gotCmds := []string{}
EachExternal(func(cmd string) { gotCmds = append(gotCmds, cmd) })
if diff := cmp.Diff(wantCmds, gotCmds, sortStringSlices); diff != "" {
t.Errorf("EachExternal (-want +got): \n%s", diff)
}
}
var sortStringSlices = cmpopts.SortSlices(func(a, b string) bool { return a < b })