@@ -5,6 +5,7 @@ use std::str;
55use predicates;
66use predicates:: str:: PredicateStrExt ;
77
8+ use cmd:: dump_buffer;
89use errors:: output_fmt;
910
1011/// Assert the state of an `Output`.
@@ -127,7 +128,19 @@ impl Assert {
127128 /// ```
128129 pub fn success ( self ) -> Self {
129130 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+ ) ;
131144 }
132145 self
133146 }
@@ -149,15 +162,23 @@ impl Assert {
149162 /// ```
150163 pub fn failure ( self ) -> Self {
151164 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+ ) ;
153170 }
154171 self
155172 }
156173
157174 /// Ensure the command aborted before returning a code.
158175 pub fn interrupted ( self ) -> Self {
159176 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+ ) ;
161182 }
162183 self
163184 }
@@ -186,12 +207,20 @@ impl Assert {
186207 }
187208
188209 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+ } ) ;
193217 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+ ) ;
195224 }
196225 self
197226 }
0 commit comments