Skip to content

Commit b01f880

Browse files
authored
testscript: support stdout/stderr args in stdin (#94)
This is particularly useful to "pipe" output like "stdin stdout". A simple test is added.
1 parent f1b9519 commit b01f880

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

testscript/cmd.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ func (ts *TestScript) cmdStdin(neg bool, args []string) {
363363
if len(args) != 1 {
364364
ts.Fatalf("usage: stdin filename")
365365
}
366-
data, err := ioutil.ReadFile(ts.MkAbs(args[0]))
367-
ts.Check(err)
368-
ts.stdin = string(data)
366+
ts.stdin = ts.ReadFile(args[0])
369367
}
370368

371369
// stdout checks that the last go command standard output matches a regexp.

testscript/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ The predefined commands are:
180180
181181
- stdin file
182182
Set the standard input for the next exec command to the contents of the given file.
183+
File can be "stdout" or "stderr" to use the standard output or standard error
184+
from the most recent exec or wait command.
183185
184186
- [!] stderr [-count=N] pattern
185187
Apply the grep command (see above) to the standard error

testscript/testdata/stdin.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ stdout hello
44
[exec:cat] exec cat
55
! stdout hello
66

7+
8+
[!exec:cat] stop
9+
10+
# Check that 'stdin stdout' works.
11+
exec cat hello.txt
12+
stdin stdout
13+
exec cat
14+
stdout hello
15+
716
-- hello.txt --
817
hello
918

0 commit comments

Comments
 (0)