@@ -798,13 +798,17 @@ impl Execs {
798
798
match res {
799
799
Ok ( out) => self . match_output ( & out) ,
800
800
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,
804
805
..
805
- } ) = err
806
+ } ) = e . downcast_ref :: < ProcessError > ( )
806
807
{
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) ) ;
808
812
}
809
813
Err ( format ! ( "could not exec process {}: {:?}" , process, e) )
810
814
}
@@ -813,119 +817,91 @@ impl Execs {
813
817
814
818
fn match_output ( & self , actual : & Output ) -> MatchResult {
815
819
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 ) )
819
823
}
820
824
821
- fn match_status ( & self , actual : & Output ) -> MatchResult {
825
+ fn match_status ( & self , code : Option < i32 > , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
822
826
match self . expect_exit_code {
823
827
None => Ok ( ( ) ) ,
824
- Some ( code ) if actual . status . code ( ) == Some ( code ) => Ok ( ( ) ) ,
828
+ Some ( expected ) if code == Some ( expected ) => Ok ( ( ) ) ,
825
829
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)
830
834
) ) ,
831
835
}
832
836
}
833
837
834
- fn match_stdout ( & self , actual : & Output ) -> MatchResult {
838
+ fn match_stdout ( & self , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
835
839
self . match_std (
836
840
self . expect_stdout . as_ref ( ) ,
837
- & actual . stdout ,
841
+ stdout,
838
842
"stdout" ,
839
- & actual . stderr ,
843
+ stderr,
840
844
MatchKind :: Exact ,
841
845
) ?;
842
846
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 ) ?;
850
848
}
851
849
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 ) ?;
859
851
}
860
852
for & ( ref expect, number) in self . expect_stdout_contains_n . iter ( ) {
861
853
self . match_std (
862
854
Some ( expect) ,
863
- & actual . stdout ,
855
+ stdout,
864
856
"stdout" ,
865
- & actual . stderr ,
857
+ stderr,
866
858
MatchKind :: PartialN ( number) ,
867
859
) ?;
868
860
}
869
861
for expect in self . expect_stdout_not_contains . iter ( ) {
870
862
self . match_std (
871
863
Some ( expect) ,
872
- & actual . stdout ,
864
+ stdout,
873
865
"stdout" ,
874
- & actual . stderr ,
866
+ stderr,
875
867
MatchKind :: NotPresent ,
876
868
) ?;
877
869
}
878
870
for expect in self . expect_stderr_not_contains . iter ( ) {
879
871
self . match_std (
880
872
Some ( expect) ,
881
- & actual . stderr ,
873
+ stderr,
882
874
"stderr" ,
883
- & actual . stdout ,
875
+ stdout,
884
876
MatchKind :: NotPresent ,
885
877
) ?;
886
878
}
887
879
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 ) ?;
895
881
}
896
882
for expect in self . expect_neither_contains . iter ( ) {
897
883
self . match_std (
898
884
Some ( expect) ,
899
- & actual . stdout ,
885
+ stdout,
900
886
"stdout" ,
901
- & actual . stdout ,
887
+ stdout,
902
888
MatchKind :: NotPresent ,
903
889
) ?;
904
890
905
891
self . match_std (
906
892
Some ( expect) ,
907
- & actual . stderr ,
893
+ stderr,
908
894
"stderr" ,
909
- & actual . stderr ,
895
+ stderr,
910
896
MatchKind :: NotPresent ,
911
897
) ?;
912
898
}
913
899
914
900
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 ) ;
929
905
930
906
if let ( Err ( _) , Err ( _) ) = ( match_std, match_err) {
931
907
return Err ( format ! (
@@ -938,12 +914,12 @@ impl Execs {
938
914
}
939
915
940
916
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) ?;
942
918
}
943
919
944
920
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 ( ) ) ?;
947
923
let lines = stdout
948
924
. lines ( )
949
925
. filter ( |line| line. starts_with ( '{' ) )
@@ -962,8 +938,8 @@ impl Execs {
962
938
}
963
939
964
940
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 ( ) ) ?;
967
943
let mut lines = stdout
968
944
. lines ( )
969
945
. filter ( |line| line. starts_with ( '{' ) )
@@ -990,12 +966,12 @@ impl Execs {
990
966
Ok ( ( ) )
991
967
}
992
968
993
- fn match_stderr ( & self , actual : & Output ) -> MatchResult {
969
+ fn match_stderr ( & self , stdout : & [ u8 ] , stderr : & [ u8 ] ) -> MatchResult {
994
970
self . match_std (
995
971
self . expect_stderr . as_ref ( ) ,
996
- & actual . stderr ,
972
+ stderr,
997
973
"stderr" ,
998
- & actual . stdout ,
974
+ stdout,
999
975
MatchKind :: Exact ,
1000
976
)
1001
977
}
0 commit comments