From 8674bc27d36a1ed7bd34dea9380fd9c395089758 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Tue, 16 Jan 2024 21:44:52 +0100 Subject: [PATCH] Disable command tests on Windows --- internal/command/command_native.go | 5 ++--- internal/command/command_native_test.go | 2 ++ internal/command/command_test.go | 2 ++ internal/command/command_unix.go | 12 ++++++++++-- internal/command/command_virtual_test.go | 2 ++ internal/command/command_windows.go | 8 ++++++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/command/command_native.go b/internal/command/command_native.go index 14850918a..086237fa2 100644 --- a/internal/command/command_native.go +++ b/internal/command/command_native.go @@ -4,7 +4,6 @@ import ( "context" "os" "os/exec" - "syscall" "github.com/pkg/errors" "go.uber.org/zap" @@ -69,11 +68,11 @@ func (c *NativeCommand) Start(ctx context.Context) (err error) { if f, ok := stdin.(*os.File); ok && f != nil { // Duplicate /dev/stdin. - newStdinFd, err := dup(int(f.Fd())) + newStdinFd, err := dup(f.Fd()) if err != nil { return errors.Wrap(err, "failed to dup stdin") } - syscall.CloseOnExec(newStdinFd) + closeOnExec(newStdinFd) // Setting stdin to the non-block mode fails on the simple "read" command. // On the other hand, it allows to use SetReadDeadline(). diff --git a/internal/command/command_native_test.go b/internal/command/command_native_test.go index e03a42306..fbd832409 100644 --- a/internal/command/command_native_test.go +++ b/internal/command/command_native_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package command import ( diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 9261a5b1d..07cf4782f 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package command import ( diff --git a/internal/command/command_unix.go b/internal/command/command_unix.go index 4da20d0b0..b8be2ded9 100644 --- a/internal/command/command_unix.go +++ b/internal/command/command_unix.go @@ -30,8 +30,16 @@ func disableEcho(fd uintptr) error { return errors.Wrap(err, "failed to set tty attr") } -func dup(fd int) (int, error) { - return syscall.Dup(fd) +func dup(fd uintptr) (uintptr, error) { + dupFd, err := syscall.Dup(int(fd)) + if err != nil { + return 0, err + } + return uintptr(dupFd), nil +} + +func closeOnExec(fd uintptr) { + syscall.CloseOnExec(int(fd)) } // func setSysProcAttrPgid(cmd *exec.Cmd) { diff --git a/internal/command/command_virtual_test.go b/internal/command/command_virtual_test.go index 4217e0ee6..aba60b458 100644 --- a/internal/command/command_virtual_test.go +++ b/internal/command/command_virtual_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package command import ( diff --git a/internal/command/command_windows.go b/internal/command/command_windows.go index 8dd6be163..1fb1ebcd7 100644 --- a/internal/command/command_windows.go +++ b/internal/command/command_windows.go @@ -1,6 +1,6 @@ //go:build windows -package runner +package command import ( "os" @@ -13,10 +13,14 @@ func setSysProcAttrCtty(cmd *exec.Cmd) {} func setSysProcAttrPgid(cmd *exec.Cmd) {} -func dup(fd int) (int, error) { +func dup(fd uintptr) (uintptr, error) { return fd, nil } +func closeOnExec(uintptr) { + // noop +} + func disableEcho(fd uintptr) error { return errors.New("Error: Environment not supported! " + "Runme currently doesn't support PowerShell. " +