-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2206 from crazy-max/test-os
ci: test-unit job matrix for win/macos/ubuntu
- Loading branch information
Showing
10 changed files
with
156 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package build | ||
|
||
// getLongPathName is a no-op on non-Windows platforms. | ||
func getLongPathName(path string) (string, error) { | ||
return path, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package build | ||
|
||
import "golang.org/x/sys/windows" | ||
|
||
// getLongPathName converts Windows short pathnames to full pathnames. | ||
// For example C:\Users\ADMIN~1 --> C:\Users\Administrator. | ||
func getLongPathName(path string) (string, error) { | ||
// See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg | ||
p, err := windows.UTF16FromString(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
b := p // GetLongPathName says we can reuse buffer | ||
n, err := windows.GetLongPathName(&p[0], &b[0], uint32(len(b))) | ||
if err != nil { | ||
return "", err | ||
} | ||
if n > uint32(len(b)) { | ||
b = make([]uint16, n) | ||
_, err = windows.GetLongPathName(&p[0], &b[0], uint32(len(b))) | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
return windows.UTF16ToString(b), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
package gitutil | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSanitizePathWindows(t *testing.T) { | ||
assert.Equal(t, "C:\\Users\\foobar", sanitizePath("C:/Users/foobar")) | ||
expected := "C:\\Users\\foobar" | ||
if isGitBash() { | ||
expected = "C:/Users/foobar" | ||
} | ||
assert.Equal(t, expected, SanitizePath("C:/Users/foobar")) | ||
} | ||
|
||
func isGitBash() bool { | ||
// The MSYSTEM environment variable is used in MSYS2 environments, | ||
// including Git Bash, to select the active environment. This variable | ||
// dictates the environment in which the shell operates, influencing | ||
// factors like the path prefixes, default compilers, and system libraries | ||
// used: https://www.msys2.org/docs/environments/ | ||
if _, ok := os.LookupEnv("MSYSTEM"); ok { | ||
return true | ||
} | ||
return false | ||
} |