Skip to content

Commit

Permalink
testscript: support stdout/stderr args in stdin (#94)
Browse files Browse the repository at this point in the history
This is particularly useful to "pipe" output like "stdin stdout". A
simple test is added.
  • Loading branch information
mvdan committed May 5, 2020
1 parent f1b9519 commit b01f880
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 1 addition & 3 deletions testscript/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ func (ts *TestScript) cmdStdin(neg bool, args []string) {
if len(args) != 1 {
ts.Fatalf("usage: stdin filename")
}
data, err := ioutil.ReadFile(ts.MkAbs(args[0]))
ts.Check(err)
ts.stdin = string(data)
ts.stdin = ts.ReadFile(args[0])
}

// stdout checks that the last go command standard output matches a regexp.
Expand Down
2 changes: 2 additions & 0 deletions testscript/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ The predefined commands are:
- stdin file
Set the standard input for the next exec command to the contents of the given file.
File can be "stdout" or "stderr" to use the standard output or standard error
from the most recent exec or wait command.
- [!] stderr [-count=N] pattern
Apply the grep command (see above) to the standard error
Expand Down
9 changes: 9 additions & 0 deletions testscript/testdata/stdin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ stdout hello
[exec:cat] exec cat
! stdout hello


[!exec:cat] stop

# Check that 'stdin stdout' works.
exec cat hello.txt
stdin stdout
exec cat
stdout hello

-- hello.txt --
hello

0 comments on commit b01f880

Please sign in to comment.