Skip to content

Commit e88da3a

Browse files
committed
Fix StandardStreamTest and ignore exmaples in test suite
1 parent 8d9ce65 commit e88da3a

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ stages:
99
- test
1010

1111
go:
12-
- 1.12.x
1312
- 1.13.x
1413

1514
sudo: required
@@ -28,11 +27,6 @@ jobs:
2827
script:
2928
- make test
3029

31-
- name: macOS integration
32-
os: osx
33-
script:
34-
- make integration
35-
3630
- name: windows Unit
3731
os: windows
3832
before_install:

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ lint:
2424

2525
test:
2626
$(info INFO: Starting build $@)
27-
go test ./...
27+
go test `go list ./... | grep -v examples`
28+
29+
test-windows:
30+
$(info INFO: Starting build $@)
31+
go test .
2832

2933
test-coverage:
3034
$(info INFO: Starting build $@)
31-
go test -coverprofile c.out ./...
35+
go test -coverprofile c.out `go list ./... | grep -v examples`

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# cmd package
88

9-
A simple package to execute shell commands on windows, darwin and windows.
9+
A simple package to execute shell commands on linux, darwin and windows.
1010

1111
## Usage
1212

@@ -58,6 +58,4 @@ make test
5858
- Coverage reports
5959
- Go report
6060
- Codeclimate
61-
- Travis-Pipeline
62-
- Documentation
6361
- os.Stdout and os.Stderr output access after execution

command.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ type Command struct {
2222
StdoutWriter io.Writer
2323
WorkingDir string
2424
executed bool
25+
exitCode int
26+
// stderr and stdout retrieve the output after the command was executed
2527
stderr bytes.Buffer
2628
stdout bytes.Buffer
27-
exitCode int
2829
}
2930

30-
//NewCommand creates a new command
31+
// NewCommand creates a new command
32+
// You can add option with variadic option argument
33+
//
34+
// Example:
35+
// c := cmd.NewCommand("echo hello", function (c *Command) {
36+
// c.WorkingDir = "/tmp"
37+
// })
38+
// c.Execute()
39+
//
40+
// or you can use existing options functions
41+
//
42+
// c := cmd.NewCommand("echo hello", cmd.WithStandardStreams)
43+
// c.Execute()
44+
//
3145
func NewCommand(cmd string, options ...func(*Command)) *Command {
3246
c := &Command{
3347
Command: cmd,

command_linux_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cmd
22

33
import (
44
"github.com/stretchr/testify/assert"
5+
"io/ioutil"
6+
"os"
57
"strings"
68
"testing"
79
)
@@ -48,8 +50,19 @@ func TestCommand_WithWorkingDir(t *testing.T) {
4850
}
4951

5052
func TestCommand_WithStandardStreams(t *testing.T) {
53+
tmpFile, _ := ioutil.TempFile("/tmp", "stdout_")
54+
originalStdout := os.Stdout
55+
os.Stdout = tmpFile
56+
57+
// Reset os.Stdout to its original value
58+
defer func() {
59+
os.Stdout = originalStdout
60+
}()
61+
5162
cmd := NewCommand("echo hey", WithStandardStreams)
5263
cmd.Execute()
5364

54-
assert.Equal(t, "/tmp\n", cmd.Stdout())
65+
r, err := ioutil.ReadFile(tmpFile.Name())
66+
assert.Nil(t, err)
67+
assert.Equal(t, "hey\n", string(r))
5568
}

0 commit comments

Comments
 (0)