Skip to content

Commit

Permalink
interp: don't test cancelling a read via os.Stdin
Browse files Browse the repository at this point in the history
Now that we use file deadlines directly, the test correctly reads
(0, io.EOF) from stdin because it is empty.
Use an open pipe, which should correctly wait for input forever.

Note that this fails on GOOS=windows for me on Wine
because it seems like os.Pipe files do not support deadlines there,
even though the docs say that OS pipes should generally work:

    On most systems ordinary files do not support deadlines, but pipes do.

Let's see what CI with real Windows thinks.
We can then adjust GOOS=windows on Wine accordingly.
  • Loading branch information
mvdan committed Dec 17, 2024
1 parent aecfbc3 commit a51b0f6
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4039,22 +4039,14 @@ func TestCancelreader(t *testing.T) {
// timeout.
defer cancel()

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

0 comments on commit a51b0f6

Please sign in to comment.