Skip to content

Commit

Permalink
interp: add a broken test for stdin draining with StdIO
Browse files Browse the repository at this point in the history
To show the bug that the recent TODO on Runner.stdin mentions.
  • Loading branch information
mvdan committed Aug 8, 2024
1 parent 7eeba77 commit 262cc0e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/go-quicktest/qt"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
Expand Down Expand Up @@ -4401,3 +4402,21 @@ func TestRunnerSubshell(t *testing.T) {
t.Fatalf("wrong output:\nwant: %q\ngot: %q", want, got)
}
}

func TestRunnerNonFileStdin(t *testing.T) {
t.Parallel()

var cb concBuffer
r, err := interp.New(interp.StdIO(strings.NewReader("a\nb\nc\n"), &cb, &cb))
if err != nil {
t.Fatal(err)
}
file := parse(t, nil, "while read a; do echo $a; GOSH_CMD=exec_ok $GOSH_PROG; done")
ctx, cancel := context.WithTimeout(context.Background(), runnerRunTimeout)
defer cancel()
if err := r.Run(ctx, file); err != nil {
cb.WriteString(err.Error())
}
// TODO: just like with heredocs, the first exec_ok call consumes all stdin.
qt.Assert(t, qt.Equals(cb.String(), "a\nexec ok\n"))
}

0 comments on commit 262cc0e

Please sign in to comment.