@@ -3,6 +3,7 @@ package cmd
33import (
44 "os"
55 "path/filepath"
6+ "runtime"
67 "testing"
78
89 "github.com/github/gh-stack/internal/config"
@@ -34,10 +35,20 @@ func TestAliasCmd_ValidatesName(t *testing.T) {
3435 }
3536}
3637
37- // withTmpBinDir overrides localBinDirFunc to use a temp directory and restores
38- // it when the test completes.
38+ // skipWindows skips the current test on Windows since the alias command
39+ // creates Unix shell scripts.
40+ func skipWindows (t * testing.T ) {
41+ t .Helper ()
42+ if runtime .GOOS == "windows" {
43+ t .Skip ("alias command uses shell scripts; not supported on Windows" )
44+ }
45+ }
46+
47+ // withTmpBinDir skips on Windows, overrides localBinDirFunc to use a temp
48+ // directory, and restores it when the test completes.
3949func withTmpBinDir (t * testing.T ) string {
4050 t .Helper ()
51+ skipWindows (t )
4152 tmpDir := t .TempDir ()
4253 orig := localBinDirFunc
4354 localBinDirFunc = func () (string , error ) { return tmpDir , nil }
@@ -133,7 +144,15 @@ func TestIsOurWrapper(t *testing.T) {
133144}
134145
135146func TestDirInPath (t * testing.T ) {
136- assert .True (t , dirInPath ("/usr/bin" ) || dirInPath ("/bin" ), "expected at least /usr/bin or /bin in PATH" )
147+ // Use a directory we know is in PATH on any platform.
148+ found := false
149+ for _ , dir := range filepath .SplitList (os .Getenv ("PATH" )) {
150+ if dirInPath (dir ) {
151+ found = true
152+ break
153+ }
154+ }
155+ assert .True (t , found , "expected at least one PATH entry to be found by dirInPath" )
137156 assert .False (t , dirInPath ("/nonexistent/path/that/should/not/exist" ))
138157}
139158
@@ -153,6 +172,18 @@ func TestAliasCmd_RemoveFlagWiring(t *testing.T) {
153172 assert .NoFileExists (t , filepath .Join (tmpDir , testAliasName ))
154173}
155174
175+ func TestAliasCmd_WindowsReturnsError (t * testing.T ) {
176+ if runtime .GOOS != "windows" {
177+ t .Skip ("Windows-only test" )
178+ }
179+
180+ cfg , _ , _ := config .NewTestConfig ()
181+
182+ cmd := AliasCmd (cfg )
183+ cmd .SetArgs ([]string {testAliasName })
184+ assert .Error (t , cmd .Execute ())
185+ }
186+
156187func TestValidateAliasName (t * testing.T ) {
157188 cfg , _ , _ := config .NewTestConfig ()
158189
0 commit comments