File tree 3 files changed +56
-1
lines changed
3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -166,9 +166,13 @@ func newAssertions(
166
166
outPipe * bytes.Buffer ,
167
167
errPipe * bytes.Buffer ,
168
168
) api.Assertions {
169
+ expExitCode := 0
170
+ if e != nil {
171
+ expExitCode = e .ExitCode
172
+ }
169
173
a := & assertions {
170
174
failures : []error {},
171
- expExitCode : exitCode ,
175
+ expExitCode : expExitCode ,
172
176
exitCode : exitCode ,
173
177
}
174
178
if e != nil {
Original file line number Diff line number Diff line change 9
9
"bytes"
10
10
"context"
11
11
"flag"
12
+ "fmt"
12
13
"os"
13
14
"os/exec"
14
15
"path/filepath"
@@ -71,6 +72,52 @@ func TestExitCode(t *testing.T) {
71
72
require .Nil (err )
72
73
}
73
74
75
+ func TestFailExecExitCodeNotSpecified (t * testing.T ) {
76
+ if ! * failFlag {
77
+ t .Skip ("skipping without -fail flag" )
78
+ }
79
+ require := require .New (t )
80
+
81
+ fp := filepath .Join ("testdata" , "ls-fail-no-exit-code.yaml" )
82
+ f , err := os .Open (fp )
83
+ require .Nil (err )
84
+
85
+ s , err := scenario .FromReader (
86
+ f ,
87
+ scenario .WithPath (fp ),
88
+ )
89
+ require .Nil (err )
90
+ require .NotNil (s )
91
+
92
+ ctx := gdtcontext .New (gdtcontext .WithDebug ())
93
+ err = s .Run (ctx , t )
94
+ require .Nil (err )
95
+ }
96
+
97
+ func TestExecFailExitCodeNotSpecified (t * testing.T ) {
98
+ require := require .New (t )
99
+ target := os .Args [0 ]
100
+ failArgs := []string {
101
+ "-test.v" ,
102
+ "-test.run=FailExecExitCodeNotSpecified" ,
103
+ "-fail" ,
104
+ }
105
+ outerr , err := exec .Command (target , failArgs ... ).CombinedOutput ()
106
+
107
+ // The test should have failed...
108
+ require .NotNil (err )
109
+ debugout := string (outerr )
110
+ ec := 2
111
+ // Yay, different exit codes for the same not found error...
112
+ if runtime .GOOS == "darwin" {
113
+ ec = 1
114
+ }
115
+ msg := fmt .Sprintf (
116
+ "assertion failed: not equal: expected 0 but got %d" , ec ,
117
+ )
118
+ require .Contains (debugout , msg )
119
+ }
120
+
74
121
func TestShellList (t * testing.T ) {
75
122
require := require .New (t )
76
123
Original file line number Diff line number Diff line change
1
+ name : ls-fail-no-exit-code
2
+ description : a scenario that runs the `ls` command with a non-0 exit code and no assertion on exit code
3
+ tests :
4
+ - exec : ls /this/dir/does/not/exist
You can’t perform that action at this time.
0 commit comments