Skip to content

Commit

Permalink
Refactor TestCancelreader
Browse files Browse the repository at this point in the history
- Move interp.New & StdIO out of the "if", as requested.
- Change the stdin read/write filehandle variable names to be a bit
  clearer.
  • Loading branch information
theclapp committed Mar 20, 2024
1 parent 72db5a6 commit ec92881
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3974,21 +3974,23 @@ func TestCancelreader(t *testing.T) {
// timeout.
defer cancel()

var r *interp.Runner
var stdinRead *os.File
if runtime.GOOS == "windows" {
// On Windows, the cancelreader only works on stdin
r, _ = interp.New(interp.StdIO(os.Stdin, nil, nil))
stdinRead = os.Stdin
} else {
siR, siW, err := os.Pipe()
var stdinWrite *os.File
var err error
stdinRead, stdinWrite, err = os.Pipe()
if err != nil {
t.Fatalf("Error calling os.Pipe: %v", err)
}
defer func() {
siW.Close()
siR.Close()
stdinWrite.Close()
stdinRead.Close()
}()
r, _ = interp.New(interp.StdIO(siR, nil, nil))
}
r, _ := interp.New(interp.StdIO(stdinRead, nil, nil))
now := time.Now()
errChan := make(chan error)
go func() {
Expand Down

0 comments on commit ec92881

Please sign in to comment.