mirror of
https://github.com/github/gh-stack.git
synced 2026-09-14 20:26:28 +08:00
skip unix tests on windows
This commit is contained in:
@@ -102,6 +102,13 @@ func runAlias(cfg *config.Config, name string, binDir string) error {
|
||||
return ErrInvalidArgs
|
||||
}
|
||||
|
||||
// Guard against overwriting an existing file that isn't on PATH
|
||||
if _, err := os.Stat(scriptPath); err == nil {
|
||||
cfg.Errorf("a file already exists at %s", scriptPath)
|
||||
cfg.Printf("Choose a different alias name, for example: %s", cfg.ColorCyan("gh stack alias gst"))
|
||||
return ErrInvalidArgs
|
||||
}
|
||||
|
||||
// Ensure the bin directory exists.
|
||||
if err := os.MkdirAll(binDir, 0o755); err != nil {
|
||||
cfg.Errorf("failed to create directory %s: %s", binDir, err)
|
||||
|
||||
+34
-3
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/github/gh-stack/internal/config"
|
||||
@@ -34,10 +35,20 @@ func TestAliasCmd_ValidatesName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// withTmpBinDir overrides localBinDirFunc to use a temp directory and restores
|
||||
// it when the test completes.
|
||||
// skipWindows skips the current test on Windows since the alias command
|
||||
// creates Unix shell scripts.
|
||||
func skipWindows(t *testing.T) {
|
||||
t.Helper()
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("alias command uses shell scripts; not supported on Windows")
|
||||
}
|
||||
}
|
||||
|
||||
// withTmpBinDir skips on Windows, overrides localBinDirFunc to use a temp
|
||||
// directory, and restores it when the test completes.
|
||||
func withTmpBinDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
skipWindows(t)
|
||||
tmpDir := t.TempDir()
|
||||
orig := localBinDirFunc
|
||||
localBinDirFunc = func() (string, error) { return tmpDir, nil }
|
||||
@@ -133,7 +144,15 @@ func TestIsOurWrapper(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDirInPath(t *testing.T) {
|
||||
assert.True(t, dirInPath("/usr/bin") || dirInPath("/bin"), "expected at least /usr/bin or /bin in PATH")
|
||||
// Use a directory we know is in PATH on any platform.
|
||||
found := false
|
||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||
if dirInPath(dir) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "expected at least one PATH entry to be found by dirInPath")
|
||||
assert.False(t, dirInPath("/nonexistent/path/that/should/not/exist"))
|
||||
}
|
||||
|
||||
@@ -153,6 +172,18 @@ func TestAliasCmd_RemoveFlagWiring(t *testing.T) {
|
||||
assert.NoFileExists(t, filepath.Join(tmpDir, testAliasName))
|
||||
}
|
||||
|
||||
func TestAliasCmd_WindowsReturnsError(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("Windows-only test")
|
||||
}
|
||||
|
||||
cfg, _, _ := config.NewTestConfig()
|
||||
|
||||
cmd := AliasCmd(cfg)
|
||||
cmd.SetArgs([]string{testAliasName})
|
||||
assert.Error(t, cmd.Execute())
|
||||
}
|
||||
|
||||
func TestValidateAliasName(t *testing.T) {
|
||||
cfg, _, _ := config.NewTestConfig()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user