Make really full-path

This commit is contained in:
Yasuhiro Matsumoto 2019-12-04 22:51:41 +09:00
parent 6513e998de
commit fd3cfb30c9
No known key found for this signature in database
GPG key ID: 622DE34DC490584B
5 changed files with 43 additions and 8 deletions

View file

@ -112,7 +112,7 @@ func newTempDir(t *testing.T) string {
t.Fatalf("os.Getwd(): %s", err)
}
return tmpdir
return toFullPath(tmpdir)
}
func tmpEnv(key, val string) func() {

7
helpers_unix.go Normal file
View file

@ -0,0 +1,7 @@
// +build !windows
package main
func toFullPath(s string) string {
return s
}

25
helpers_windows.go Normal file
View file

@ -0,0 +1,25 @@
// +build windows
package main
import "syscall"
func toFullPath(s string) string {
p := syscall.StringToUTF16(s)
b := p
n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
if err != nil {
println("error", err.Error())
return s
}
if n > uint32(len(b)) {
b = make([]uint16, n)
n, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
if err != nil {
println("error", err.Error())
return s
}
}
b = b[:n]
return syscall.UTF16ToString(b)
}

View file

@ -57,11 +57,15 @@ func TestCommandListUnknown(t *testing.T) {
}
func sortLines(s string) string {
ss := strings.Split(s, "\n")
ss := strings.Split(strings.TrimSpace(s), "\n")
sort.Strings(ss)
return strings.Join(ss, "\n")
}
func equalPathLines(lhs, rhs string) bool {
return sortLines(lhs) == sortLines(rhs)
}
func TestDoList_query(t *testing.T) {
gitRepos := []string{
"github.com/motemen/ghq",
@ -133,7 +137,7 @@ func TestDoList_query(t *testing.T) {
out, _, _ := capture(func() {
newApp().Run(args)
})
if sortLines(out) != sortLines(tc.expect) {
if !equalPathLines(out, tc.expect) {
t.Errorf("got:\n%s\nexpect:\n%s", out, tc.expect)
}
if strings.Contains(tc.name, "unique") {
@ -152,7 +156,7 @@ func TestDoList_query(t *testing.T) {
out, _, _ = capture(func() {
newApp().Run(argsFull)
})
if sortLines(out) != sortLines(fullExpect) {
if !equalPathLines(out, fullExpect) {
t.Errorf("got:\n%s\nexpect:\n%s", out, fullExpect)
}
})

View file

@ -33,6 +33,7 @@ func TestLocalRepositoryFromFullPath(t *testing.T) {
r, err := LocalRepositoryFromFullPath(tc.fpath, nil)
if err != nil {
t.Errorf("error should be nil but: %s", err)
return
}
if r.NonHostPath() != tc.expect {
t.Errorf("NonHostPath: got: %s, expect: %s", r.NonHostPath(), tc.expect)
@ -294,10 +295,7 @@ func TestLocalRepository_VCS(t *testing.T) {
t.Run("reporoot", func(t *testing.T) {
repo, err := LocalRepositoryFromFullPath(pkg, nil)
if err != nil {
t.Errorf("error should be nil, but: %s", err)
}
if repo == nil {
t.Errorf("repo should not be nil, but: %v", repo)
t.Errorf("error should be nil, but: %s (%s)", err, pkg)
return
}
vcs, repoPath := repo.VCS()
@ -314,6 +312,7 @@ func TestLocalRepository_VCS(t *testing.T) {
repo, err := LocalRepositoryFromFullPath(subpkg, nil)
if err != nil {
t.Errorf("error should be nil, but: %s", err)
return
}
vcs, repoPath := repo.VCS()
if vcs != GitBackend {