From ec9288116c4d4f5a3feb35f13987bb7f98f3fec7 Mon Sep 17 00:00:00 2001 From: Larry Clapp Date: Wed, 20 Mar 2024 16:22:41 -0400 Subject: [PATCH] Refactor TestCancelreader - Move interp.New & StdIO out of the "if", as requested. - Change the stdin read/write filehandle variable names to be a bit clearer. --- interp/interp_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/interp/interp_test.go b/interp/interp_test.go index 75735571..30eeb6ee 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -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() {