@@ -25,6 +25,7 @@ use std::time::{self, Duration};
25
25
26
26
use anyhow:: { bail, Result } ;
27
27
use cargo_util:: { is_ci, ProcessBuilder , ProcessError } ;
28
+ use snapbox:: IntoData as _;
28
29
use url:: Url ;
29
30
30
31
use self :: paths:: CargoPathExt ;
@@ -534,6 +535,8 @@ pub struct Execs {
534
535
expect_stdin : Option < String > ,
535
536
expect_stderr : Option < String > ,
536
537
expect_exit_code : Option < i32 > ,
538
+ expect_stdout_data : Option < snapbox:: Data > ,
539
+ expect_stderr_data : Option < snapbox:: Data > ,
537
540
expect_stdout_contains : Vec < String > ,
538
541
expect_stderr_contains : Vec < String > ,
539
542
expect_stdout_contains_n : Vec < ( String , usize ) > ,
@@ -545,6 +548,7 @@ pub struct Execs {
545
548
expect_json : Option < String > ,
546
549
expect_json_contains_unordered : Option < String > ,
547
550
stream_output : bool ,
551
+ assert : snapbox:: Assert ,
548
552
}
549
553
550
554
impl Execs {
@@ -567,6 +571,22 @@ impl Execs {
567
571
self
568
572
}
569
573
574
+ /// Verifies that stdout is equal to the given lines.
575
+ ///
576
+ /// See [`compare::assert_e2e`] for assertion details.
577
+ pub fn with_stdout_data ( & mut self , expected : impl snapbox:: IntoData ) -> & mut Self {
578
+ self . expect_stdout_data = Some ( expected. into_data ( ) ) ;
579
+ self
580
+ }
581
+
582
+ /// Verifies that stderr is equal to the given lines.
583
+ ///
584
+ /// See [`compare::assert_e2e`] for assertion details.
585
+ pub fn with_stderr_data ( & mut self , expected : impl snapbox:: IntoData ) -> & mut Self {
586
+ self . expect_stderr_data = Some ( expected. into_data ( ) ) ;
587
+ self
588
+ }
589
+
570
590
/// Writes the given lines to stdin.
571
591
pub fn with_stdin < S : ToString > ( & mut self , expected : S ) -> & mut Self {
572
592
self . expect_stdin = Some ( expected. to_string ( ) ) ;
@@ -914,6 +934,8 @@ impl Execs {
914
934
&& self . expect_stdout . is_none ( )
915
935
&& self . expect_stdin . is_none ( )
916
936
&& self . expect_stderr . is_none ( )
937
+ && self . expect_stdout_data . is_none ( )
938
+ && self . expect_stderr_data . is_none ( )
917
939
&& self . expect_stdout_contains . is_empty ( )
918
940
&& self . expect_stderr_contains . is_empty ( )
919
941
&& self . expect_stdout_contains_n . is_empty ( )
@@ -1011,6 +1033,24 @@ impl Execs {
1011
1033
if let Some ( expect_stderr) = & self . expect_stderr {
1012
1034
compare:: match_exact ( expect_stderr, stderr, "stderr" , stdout, cwd) ?;
1013
1035
}
1036
+ if let Some ( expect_stdout_data) = & self . expect_stdout_data {
1037
+ if let Err ( err) = self . assert . try_eq (
1038
+ Some ( & "stdout" ) ,
1039
+ stdout. into_data ( ) ,
1040
+ expect_stdout_data. clone ( ) ,
1041
+ ) {
1042
+ panic ! ( "{err}" )
1043
+ }
1044
+ }
1045
+ if let Some ( expect_stderr_data) = & self . expect_stderr_data {
1046
+ if let Err ( err) = self . assert . try_eq (
1047
+ Some ( & "stderr" ) ,
1048
+ stderr. into_data ( ) ,
1049
+ expect_stderr_data. clone ( ) ,
1050
+ ) {
1051
+ panic ! ( "{err}" )
1052
+ }
1053
+ }
1014
1054
for expect in self . expect_stdout_contains . iter ( ) {
1015
1055
compare:: match_contains ( expect, stdout, cwd) ?;
1016
1056
}
@@ -1063,6 +1103,8 @@ pub fn execs() -> Execs {
1063
1103
expect_stderr : None ,
1064
1104
expect_stdin : None ,
1065
1105
expect_exit_code : Some ( 0 ) ,
1106
+ expect_stdout_data : None ,
1107
+ expect_stderr_data : None ,
1066
1108
expect_stdout_contains : Vec :: new ( ) ,
1067
1109
expect_stderr_contains : Vec :: new ( ) ,
1068
1110
expect_stdout_contains_n : Vec :: new ( ) ,
@@ -1074,6 +1116,7 @@ pub fn execs() -> Execs {
1074
1116
expect_json : None ,
1075
1117
expect_json_contains_unordered : None ,
1076
1118
stream_output : false ,
1119
+ assert : compare:: assert_e2e ( ) ,
1077
1120
}
1078
1121
}
1079
1122
0 commit comments