Skip to content

Commit

Permalink
interp: trace should write to stderr by default
Browse files Browse the repository at this point in the history
Fixes #926.
  • Loading branch information
graf0 authored Oct 16, 2022
1 parent 13def01 commit c780bb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,14 @@ single quote
// for trace
{
`set -x
exec >/dev/null
echo "trace should go to stderr"`,
`+ exec
+ echo 'trace should go to stderr'
`,
},
{
`set -x
animals=(dog, cat, otter)
for i in ${animals[@]}
do
Expand Down
6 changes: 3 additions & 3 deletions interp/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type tracer struct {
buf bytes.Buffer
printer *syntax.Printer
stdout io.Writer
output io.Writer
needsPlus bool
}

Expand All @@ -25,7 +25,7 @@ func (r *Runner) tracer() *tracer {

return &tracer{
printer: syntax.NewPrinter(),
stdout: r.stdout,
output: r.stderr,
needsPlus: true,
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (t *tracer) flush() {
return
}

t.stdout.Write(t.buf.Bytes())
t.output.Write(t.buf.Bytes())
t.buf.Reset()
}

Expand Down

0 comments on commit c780bb4

Please sign in to comment.