mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Add test showing startCmdWithPipe returns a nil reader on pipe failure
NewCmdTask feeds the reader returned by its start func straight into a bufio.Scanner, whose Scan panics on a nil reader with a nil pointer dereference. startCmdWithPipe returns exactly that when the pipe cannot be created. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
5209294a56
commit
400faea60c
27
pkg/gui/tasks_adapter_test.go
Normal file
27
pkg/gui/tasks_adapter_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStartCmdWithPipeWhenPipeCannotBeCreated(t *testing.T) {
|
||||
cmd := exec.Command("non-existent-command")
|
||||
// Assigning stdout up front makes cmd.StdoutPipe fail. This happens in
|
||||
// practice on the Unix pty fallback path: a failed pty start can leave
|
||||
// the tty assigned to the command's stdout.
|
||||
cmd.Stdout = &bytes.Buffer{}
|
||||
|
||||
_, r := startCmdWithPipe(cmd, utils.NewDummyLog())
|
||||
|
||||
// NewCmdTask's scanner panics on a nil reader, so startCmdWithPipe must
|
||||
// not return one even when it can't create the pipe.
|
||||
/* EXPECTED:
|
||||
assert.NotNil(t, r)
|
||||
ACTUAL: */
|
||||
assert.Nil(t, r)
|
||||
}
|
||||
Loading…
Reference in a new issue