File tree Expand file tree Collapse file tree 5 files changed +37
-14
lines changed
Expand file tree Collapse file tree 5 files changed +37
-14
lines changed Original file line number Diff line number Diff line change 99 - test
1010
1111go :
12- - 1.12.x
1312 - 1.13.x
1413
1514sudo : required
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 :
Original file line number Diff line number Diff line change 2424
2525test :
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
2933test-coverage :
3034 $(info INFO: Starting build $@ )
31- go test -coverprofile c.out ./...
35+ go test -coverprofile c.out ` go list ./... | grep -v examples `
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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+ //
3145func NewCommand (cmd string , options ... func (* Command )) * Command {
3246 c := & Command {
3347 Command : cmd ,
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package cmd
22
33import (
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
5052func 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}
You can’t perform that action at this time.
0 commit comments