Skip to content

Commit 5972a4e

Browse files
committed
Add multiplexed writer to constructor method NewCommand
1 parent a7c478f commit 5972a4e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func NewCommand(cmd string, options ...func(*Command)) *Command {
5959
Env: []string{},
6060
}
6161

62-
c.StdoutWriter = &c.stdout
63-
c.StderrWriter = &c.stderr
62+
c.StdoutWriter = NewMultiplexedWriter(&c.stdout, &c.combined)
63+
c.StderrWriter = NewMultiplexedWriter(&c.stderr, &c.combined)
6464

6565
for _, o := range options {
6666
o(c)

command_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111
)
1212

1313
func TestCommand_NewCommand(t *testing.T) {
14-
cmd := NewCommand("")
15-
assert.False(t, cmd.Executed())
14+
cmd := NewCommand("echo hello")
15+
cmd.Execute()
16+
17+
assertEqualWithLineBreak(t, "hello", cmd.Combined())
18+
assertEqualWithLineBreak(t, "hello", cmd.Stdout())
1619
}
1720

1821
func TestCommand_Execute(t *testing.T) {

0 commit comments

Comments
 (0)