Skip to content

Commit

Permalink
Merge pull request #225 from motemen/fix-win-helper
Browse files Browse the repository at this point in the history
refactor test helpers
  • Loading branch information
Songmu authored Dec 18, 2019
2 parents 49090e8 + 7be651a commit ad6895c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 5 additions & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ func newTempDir(t *testing.T) string {
t.Fatalf("os.Getwd(): %s", err)
}

return toFullPath(tmpdir)
s, err := toFullPath(tmpdir)
if err != nil {
t.Fatalf("toFullPath(%q): %s", tmpdir, err)
}
return s
}

func tmpEnv(key, val string) func() {
Expand Down
4 changes: 2 additions & 2 deletions helpers_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

package main

func toFullPath(s string) string {
return s
func toFullPath(s string) (string, error) {
return s, nil
}
10 changes: 4 additions & 6 deletions helpers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ package main

import "syscall"

func toFullPath(s string) string {
func toFullPath(s string) (string, error) {
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
return s, err
}
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
return s, err
}
}
b = b[:n]
return syscall.UTF16ToString(b)
return syscall.UTF16ToString(b), nil
}

0 comments on commit ad6895c

Please sign in to comment.