Skip to content

Commit

Permalink
Uncomment more read tests.
Browse files Browse the repository at this point in the history
- Uncomment the tests that already worked. (And move them to below the
  other "read" tests.) They failed under Linux bash (though they worked
  under macOS bash). Fixed that.
- TestCancelreader failing intermittently under Linux, even though the
  read context is definitely cancelled.

  Committing what I've got, for posterity.
  • Loading branch information
theclapp committed Mar 20, 2024
1 parent ec92881 commit 24a510d
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2903,6 +2903,22 @@ done <<< 2`,
"read -r -p 'Prompt and raw flag together: ' a <<< '\\a\\b\\c'; echo $a",
"Prompt and raw flag together: \\a\\b\\c\n #IGNORE bash requires a terminal",
},
{
`a=a; echo | (read a; echo -n "$a")`,
"",
},
{
`a=b; read a < /dev/null; echo -n "$a"`,
"",
},
{
"a=c; echo x | (read a; echo -n $a)",
"x",
},
{
"a=d; echo -n y | (read a; echo -n $a)",
"y",
},

// getopts
{
Expand Down Expand Up @@ -2982,27 +2998,6 @@ done <<< 2`,
"mapfile -t butter <<EOF\na\nb\nc\nEOF\n" + `for x in "${butter[@]}"; do echo "$x"; done`,
"a\nb\nc\n",
},
// read & EOF
// // newline
// {
// `a=a; echo | read a; echo -n "$a"`,
// "",
// },
// empty input
{
`a=b; read a < /dev/null; echo -n "$a"`,
"",
},
// // some string and newline
// {
// "a=c; echo x | read a; echo -n $a",
// "x",
// },
// // some string and EOF
// {
// "a=d; echo -n y | read a; echo -n $a",
// "y",
// },
}

var runTestsUnix = []runTest{
Expand Down Expand Up @@ -3997,7 +3992,13 @@ func TestCancelreader(t *testing.T) {
errChan <- r.Run(ctx, file)
}()

go func() {
<-ctx.Done()
t.Logf("context cancelled after %v", time.Since(now))
}()

timeout := 500 * time.Millisecond
timeout = 5 * time.Second
select {
case err := <-errChan:
if err == nil || err.Error() != "exit status 1" || ctx.Err() != context.DeadlineExceeded {
Expand Down

0 comments on commit 24a510d

Please sign in to comment.