@@ -5,6 +5,7 @@ use std::str;
5
5
use predicates;
6
6
use predicates:: str:: PredicateStrExt ;
7
7
8
+ use cmd:: dump_buffer;
8
9
use errors:: output_fmt;
9
10
10
11
/// Assert the state of an `Output`.
@@ -127,7 +128,19 @@ impl Assert {
127
128
/// ```
128
129
pub fn success ( self ) -> Self {
129
130
if !self . output . status . success ( ) {
130
- panic ! ( "Unexpected failure\n {}" , self ) ;
131
+ let actual_code = self . output . status . code ( ) . unwrap_or_else ( || {
132
+ panic ! (
133
+ "Unexpected failure.\n code=<interrupted>\n stderr=```{}```\n {}" ,
134
+ dump_buffer( & self . output. stderr) ,
135
+ self
136
+ )
137
+ } ) ;
138
+ panic ! (
139
+ "Unexpected failure.\n code-{}\n stderr=```{}```\n {}" ,
140
+ actual_code,
141
+ dump_buffer( & self . output. stderr) ,
142
+ self
143
+ ) ;
131
144
}
132
145
self
133
146
}
@@ -149,15 +162,23 @@ impl Assert {
149
162
/// ```
150
163
pub fn failure ( self ) -> Self {
151
164
if self . output . status . success ( ) {
152
- panic ! ( "Unexpected success\n {}" , self ) ;
165
+ panic ! (
166
+ "Unexpected success\n stdout=```{}```\n {}" ,
167
+ dump_buffer( & self . output. stdout) ,
168
+ self
169
+ ) ;
153
170
}
154
171
self
155
172
}
156
173
157
174
/// Ensure the command aborted before returning a code.
158
175
pub fn interrupted ( self ) -> Self {
159
176
if self . output . status . code ( ) . is_some ( ) {
160
- panic ! ( "Unexpected completion\n {}" , self ) ;
177
+ panic ! (
178
+ "Unexpected completion\n stdout=```{}```\n {}" ,
179
+ dump_buffer( & self . output. stdout) ,
180
+ self
181
+ ) ;
161
182
}
162
183
self
163
184
}
@@ -186,12 +207,20 @@ impl Assert {
186
207
}
187
208
188
209
fn code_impl ( self , pred : & predicates:: Predicate < i32 > ) -> Self {
189
- let actual_code = self . output
190
- . status
191
- . code ( )
192
- . unwrap_or_else ( || panic ! ( "Command interrupted\n {}" , self ) ) ;
210
+ let actual_code = self . output . status . code ( ) . unwrap_or_else ( || {
211
+ panic ! (
212
+ "Command interrupted\n stderr=```{}```\n {}" ,
213
+ dump_buffer( & self . output. stderr) ,
214
+ self
215
+ )
216
+ } ) ;
193
217
if !pred. eval ( & actual_code) {
194
- panic ! ( "Unexpected return code\n {}" , self ) ;
218
+ panic ! (
219
+ "Unexpected return code\n stdout=```{}```\n stderr=```{}```\n {}" ,
220
+ dump_buffer( & self . output. stdout) ,
221
+ dump_buffer( & self . output. stderr) ,
222
+ self
223
+ ) ;
195
224
}
196
225
self
197
226
}
0 commit comments