@@ -798,13 +798,17 @@ impl Execs {
798798 match res {
799799 Ok ( out) => self . match_output ( & out) ,
800800 Err ( e) => {
801- let err = e. downcast_ref :: < ProcessError > ( ) ;
802- if let Some ( & ProcessError {
803- output : Some ( ref out) ,
801+ if let Some ( ProcessError {
802+ stdout : Some ( stdout) ,
803+ stderr : Some ( stderr) ,
804+ code,
804805 ..
805- } ) = err
806+ } ) = e . downcast_ref :: < ProcessError > ( )
806807 {
807- return self . match_output ( out) ;
808+ return self
809+ . match_status ( * code, stdout, stderr)
810+ . and ( self . match_stdout ( stdout, stderr) )
811+ . and ( self . match_stderr ( stdout, stderr) ) ;
808812 }
809813 Err ( format ! ( "could not exec process {}: {:?}" , process, e) )
810814 }
@@ -813,119 +817,91 @@ impl Execs {
813817
814818 fn match_output ( & self , actual : & Output ) -> MatchResult {
815819 self . verify_checks_output ( actual) ;
816- self . match_status ( actual)
817- . and ( self . match_stdout ( actual) )
818- . and ( self . match_stderr ( actual) )
820+ self . match_status ( actual. status . code ( ) , & actual . stdout , & actual . stderr )
821+ . and ( self . match_stdout ( & actual. stdout , & actual . stderr ) )
822+ . and ( self . match_stderr ( & actual. stdout , & actual . stderr ) )
819823 }
820824
821- fn match_status ( & self , actual : & Output ) -> MatchResult {
825+ fn match_status ( & self , code : Option < i32 > , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
822826 match self . expect_exit_code {
823827 None => Ok ( ( ) ) ,
824- Some ( code ) if actual . status . code ( ) == Some ( code ) => Ok ( ( ) ) ,
828+ Some ( expected ) if code == Some ( expected ) => Ok ( ( ) ) ,
825829 Some ( _) => Err ( format ! (
826- "exited with {}\n --- stdout\n {}\n --- stderr\n {}" ,
827- actual . status ,
828- String :: from_utf8_lossy( & actual . stdout) ,
829- String :: from_utf8_lossy( & actual . stderr)
830+ "exited with {:? }\n --- stdout\n {}\n --- stderr\n {}" ,
831+ code ,
832+ String :: from_utf8_lossy( & stdout) ,
833+ String :: from_utf8_lossy( & stderr)
830834 ) ) ,
831835 }
832836 }
833837
834- fn match_stdout ( & self , actual : & Output ) -> MatchResult {
838+ fn match_stdout ( & self , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
835839 self . match_std (
836840 self . expect_stdout . as_ref ( ) ,
837- & actual . stdout ,
841+ stdout,
838842 "stdout" ,
839- & actual . stderr ,
843+ stderr,
840844 MatchKind :: Exact ,
841845 ) ?;
842846 for expect in self . expect_stdout_contains . iter ( ) {
843- self . match_std (
844- Some ( expect) ,
845- & actual. stdout ,
846- "stdout" ,
847- & actual. stderr ,
848- MatchKind :: Partial ,
849- ) ?;
847+ self . match_std ( Some ( expect) , stdout, "stdout" , stderr, MatchKind :: Partial ) ?;
850848 }
851849 for expect in self . expect_stderr_contains . iter ( ) {
852- self . match_std (
853- Some ( expect) ,
854- & actual. stderr ,
855- "stderr" ,
856- & actual. stdout ,
857- MatchKind :: Partial ,
858- ) ?;
850+ self . match_std ( Some ( expect) , stderr, "stderr" , stdout, MatchKind :: Partial ) ?;
859851 }
860852 for & ( ref expect, number) in self . expect_stdout_contains_n . iter ( ) {
861853 self . match_std (
862854 Some ( expect) ,
863- & actual . stdout ,
855+ stdout,
864856 "stdout" ,
865- & actual . stderr ,
857+ stderr,
866858 MatchKind :: PartialN ( number) ,
867859 ) ?;
868860 }
869861 for expect in self . expect_stdout_not_contains . iter ( ) {
870862 self . match_std (
871863 Some ( expect) ,
872- & actual . stdout ,
864+ stdout,
873865 "stdout" ,
874- & actual . stderr ,
866+ stderr,
875867 MatchKind :: NotPresent ,
876868 ) ?;
877869 }
878870 for expect in self . expect_stderr_not_contains . iter ( ) {
879871 self . match_std (
880872 Some ( expect) ,
881- & actual . stderr ,
873+ stderr,
882874 "stderr" ,
883- & actual . stdout ,
875+ stdout,
884876 MatchKind :: NotPresent ,
885877 ) ?;
886878 }
887879 for expect in self . expect_stderr_unordered . iter ( ) {
888- self . match_std (
889- Some ( expect) ,
890- & actual. stderr ,
891- "stderr" ,
892- & actual. stdout ,
893- MatchKind :: Unordered ,
894- ) ?;
880+ self . match_std ( Some ( expect) , stderr, "stderr" , stdout, MatchKind :: Unordered ) ?;
895881 }
896882 for expect in self . expect_neither_contains . iter ( ) {
897883 self . match_std (
898884 Some ( expect) ,
899- & actual . stdout ,
885+ stdout,
900886 "stdout" ,
901- & actual . stdout ,
887+ stdout,
902888 MatchKind :: NotPresent ,
903889 ) ?;
904890
905891 self . match_std (
906892 Some ( expect) ,
907- & actual . stderr ,
893+ stderr,
908894 "stderr" ,
909- & actual . stderr ,
895+ stderr,
910896 MatchKind :: NotPresent ,
911897 ) ?;
912898 }
913899
914900 for expect in self . expect_either_contains . iter ( ) {
915- let match_std = self . match_std (
916- Some ( expect) ,
917- & actual. stdout ,
918- "stdout" ,
919- & actual. stdout ,
920- MatchKind :: Partial ,
921- ) ;
922- let match_err = self . match_std (
923- Some ( expect) ,
924- & actual. stderr ,
925- "stderr" ,
926- & actual. stderr ,
927- MatchKind :: Partial ,
928- ) ;
901+ let match_std =
902+ self . match_std ( Some ( expect) , stdout, "stdout" , stdout, MatchKind :: Partial ) ;
903+ let match_err =
904+ self . match_std ( Some ( expect) , stderr, "stderr" , stderr, MatchKind :: Partial ) ;
929905
930906 if let ( Err ( _) , Err ( _) ) = ( match_std, match_err) {
931907 return Err ( format ! (
@@ -938,12 +914,12 @@ impl Execs {
938914 }
939915
940916 for ( with, without) in self . expect_stderr_with_without . iter ( ) {
941- self . match_with_without ( & actual . stderr , with, without) ?;
917+ self . match_with_without ( stderr, with, without) ?;
942918 }
943919
944920 if let Some ( ref objects) = self . expect_json {
945- let stdout = str :: from_utf8 ( & actual . stdout )
946- . map_err ( |_| "stdout was not utf8 encoded" . to_owned ( ) ) ?;
921+ let stdout =
922+ str :: from_utf8 ( stdout ) . map_err ( |_| "stdout was not utf8 encoded" . to_owned ( ) ) ?;
947923 let lines = stdout
948924 . lines ( )
949925 . filter ( |line| line. starts_with ( '{' ) )
@@ -962,8 +938,8 @@ impl Execs {
962938 }
963939
964940 if !self . expect_json_contains_unordered . is_empty ( ) {
965- let stdout = str :: from_utf8 ( & actual . stdout )
966- . map_err ( |_| "stdout was not utf8 encoded" . to_owned ( ) ) ?;
941+ let stdout =
942+ str :: from_utf8 ( stdout ) . map_err ( |_| "stdout was not utf8 encoded" . to_owned ( ) ) ?;
967943 let mut lines = stdout
968944 . lines ( )
969945 . filter ( |line| line. starts_with ( '{' ) )
@@ -990,12 +966,12 @@ impl Execs {
990966 Ok ( ( ) )
991967 }
992968
993- fn match_stderr ( & self , actual : & Output ) -> MatchResult {
969+ fn match_stderr ( & self , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
994970 self . match_std (
995971 self . expect_stderr . as_ref ( ) ,
996- & actual . stderr ,
972+ stderr,
997973 "stderr" ,
998- & actual . stdout ,
974+ stdout,
999975 MatchKind :: Exact ,
1000976 )
1001977 }
0 commit comments