From a51b0f69f4b94e0529bfa6c7e2ba43ce64bc8451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 17 Dec 2024 15:59:49 +0000 Subject: [PATCH] interp: don't test cancelling a read via os.Stdin 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. --- interp/interp_test.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/interp/interp_test.go b/interp/interp_test.go index d2e5e4c1..dd8a38b4 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -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)