@@ -88,7 +88,11 @@ macro_rules! regex {
8888/// - Carriage returns are removed, which can help when running on Windows.
8989pub fn assert_ui ( ) -> snapbox:: Assert {
9090 let mut subs = snapbox:: Redactions :: new ( ) ;
91- add_common_redactions ( & mut subs) ;
91+ subs. extend ( MIN_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
92+ . unwrap ( ) ;
93+ add_test_support_redactions ( & mut subs) ;
94+ add_regex_redactions ( & mut subs) ;
95+
9296 snapbox:: Assert :: new ( )
9397 . action_env ( snapbox:: assert:: DEFAULT_ACTION_ENV )
9498 . redact_with ( subs)
@@ -127,41 +131,49 @@ pub fn assert_ui() -> snapbox::Assert {
127131/// - Carriage returns are removed, which can help when running on Windows.
128132pub fn assert_e2e ( ) -> snapbox:: Assert {
129133 let mut subs = snapbox:: Redactions :: new ( ) ;
130- add_common_redactions ( & mut subs) ;
134+ subs. extend ( MIN_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
135+ . unwrap ( ) ;
131136 subs. extend ( E2E_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
132137 . unwrap ( ) ;
138+ add_test_support_redactions ( & mut subs) ;
139+ add_regex_redactions ( & mut subs) ;
133140
134141 snapbox:: Assert :: new ( )
135142 . action_env ( snapbox:: assert:: DEFAULT_ACTION_ENV )
136143 . redact_with ( subs)
137144}
138145
139- fn add_common_redactions ( subs : & mut snapbox:: Redactions ) {
146+ fn add_test_support_redactions ( subs : & mut snapbox:: Redactions ) {
140147 let root = paths:: root ( ) ;
141148 // Use `from_file_path` instead of `from_dir_path` so the trailing slash is
142149 // put in the users output, rather than hidden in the variable
143150 let root_url = url:: Url :: from_file_path ( & root) . unwrap ( ) . to_string ( ) ;
144151
145- subs. extend ( MIN_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
146- . unwrap ( ) ;
147152 subs. insert ( "[ROOT]" , root) . unwrap ( ) ;
148153 subs. insert ( "[ROOTURL]" , root_url) . unwrap ( ) ;
154+ subs. insert ( "[HOST_TARGET]" , rustc_host ( ) ) . unwrap ( ) ;
155+ if let Some ( alt_target) = try_alternate ( ) {
156+ subs. insert ( "[ALT_TARGET]" , alt_target) . unwrap ( ) ;
157+ }
158+ }
159+
160+ fn add_regex_redactions ( subs : & mut snapbox:: Redactions ) {
149161 // For e2e tests
150162 subs. insert (
151163 "[ELAPSED]" ,
152- regex ! ( r"\[FINISHED\].*in (?<redacted>[0-9]+(\.[0-9]+))s" ) ,
164+ regex ! ( r"\[FINISHED\].*in (?<redacted>[0-9]+(\.[0-9]+)?(m [0-9]+)? )s" ) ,
153165 )
154166 . unwrap ( ) ;
155167 // for UI tests
156168 subs. insert (
157169 "[ELAPSED]" ,
158- regex ! ( r"Finished.*in (?<redacted>[0-9]+(\.[0-9]+))s" ) ,
170+ regex ! ( r"Finished.*in (?<redacted>[0-9]+(\.[0-9]+)?(m [0-9]+)? )s" ) ,
159171 )
160172 . unwrap ( ) ;
161173 // output from libtest
162174 subs. insert (
163175 "[ELAPSED]" ,
164- regex ! ( r"; finished in (?<redacted>[0-9]+(\.[0-9]+))s" ) ,
176+ regex ! ( r"; finished in (?<redacted>[0-9]+(\.[0-9]+)?(m [0-9]+)? )s" ) ,
165177 )
166178 . unwrap ( ) ;
167179 subs. insert (
@@ -186,10 +198,6 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
186198 . unwrap ( ) ;
187199 subs. insert ( "[HASH]" , regex ! ( r"/[a-z0-9\-_]+-(?<redacted>[0-9a-f]{16})" ) )
188200 . unwrap ( ) ;
189- subs. insert ( "[HOST_TARGET]" , rustc_host ( ) ) . unwrap ( ) ;
190- if let Some ( alt_target) = try_alternate ( ) {
191- subs. insert ( "[ALT_TARGET]" , alt_target) . unwrap ( ) ;
192- }
193201 subs. insert (
194202 "[AVG_ELAPSED]" ,
195203 regex ! ( r"(?<redacted>[0-9]+(\.[0-9]+)?) ns/iter" ) ,
@@ -822,129 +830,153 @@ impl fmt::Debug for WildStr<'_> {
822830 }
823831}
824832
825- #[ test]
826- fn wild_str_cmp ( ) {
827- for ( a, b) in & [
828- ( "a b" , "a b" ) ,
829- ( "a[..]b" , "a b" ) ,
830- ( "a[..]" , "a b" ) ,
831- ( "[..]" , "a b" ) ,
832- ( "[..]b" , "a b" ) ,
833- ] {
834- assert_eq ! ( WildStr :: new( a) , WildStr :: new( b) ) ;
835- }
836- for ( a, b) in & [ ( "[..]b" , "c" ) , ( "b" , "c" ) , ( "b" , "cb" ) ] {
837- assert_ne ! ( WildStr :: new( a) , WildStr :: new( b) ) ;
833+ #[ cfg( test) ]
834+ mod test {
835+ use snapbox:: assert_data_eq;
836+ use snapbox:: prelude:: * ;
837+ use snapbox:: str;
838+
839+ use super :: * ;
840+
841+ #[ test]
842+ fn wild_str_cmp ( ) {
843+ for ( a, b) in & [
844+ ( "a b" , "a b" ) ,
845+ ( "a[..]b" , "a b" ) ,
846+ ( "a[..]" , "a b" ) ,
847+ ( "[..]" , "a b" ) ,
848+ ( "[..]b" , "a b" ) ,
849+ ] {
850+ assert_eq ! ( WildStr :: new( a) , WildStr :: new( b) ) ;
851+ }
852+ for ( a, b) in & [ ( "[..]b" , "c" ) , ( "b" , "c" ) , ( "b" , "cb" ) ] {
853+ assert_ne ! ( WildStr :: new( a) , WildStr :: new( b) ) ;
854+ }
838855 }
839- }
840856
841- #[ test]
842- fn dirty_msvc ( ) {
843- let case = |expected : & str , wild : & str , msvc : bool | {
844- assert_eq ! ( expected, & replace_dirty_msvc_impl( wild, msvc) ) ;
845- } ;
857+ #[ test]
858+ fn dirty_msvc ( ) {
859+ let case = |expected : & str , wild : & str , msvc : bool | {
860+ assert_eq ! ( expected, & replace_dirty_msvc_impl( wild, msvc) ) ;
861+ } ;
846862
847- // no replacements
848- case ( "aa" , "aa" , false ) ;
849- case ( "aa" , "aa" , true ) ;
863+ // no replacements
864+ case ( "aa" , "aa" , false ) ;
865+ case ( "aa" , "aa" , true ) ;
850866
851- // with replacements
852- case (
853- "\
867+ // with replacements
868+ case (
869+ "\
854870 [DIRTY] a",
855- "\
871+ "\
856872 [DIRTY-MSVC] a",
857- true ,
858- ) ;
859- case (
860- "" ,
861- "\
873+ true ,
874+ ) ;
875+ case (
876+ "" ,
877+ "\
862878 [DIRTY-MSVC] a",
863- false ,
864- ) ;
865- case (
866- "\
879+ false ,
880+ ) ;
881+ case (
882+ "\
867883 [DIRTY] a
868884[COMPILING] a" ,
869- "\
885+ "\
870886 [DIRTY-MSVC] a
871887[COMPILING] a" ,
872- true ,
873- ) ;
874- case (
875- "\
888+ true ,
889+ ) ;
890+ case (
891+ "\
876892 [COMPILING] a",
877- "\
893+ "\
878894 [DIRTY-MSVC] a
879895[COMPILING] a" ,
880- false ,
881- ) ;
896+ false ,
897+ ) ;
882898
883- // test trailing newline behavior
884- case (
885- "\
899+ // test trailing newline behavior
900+ case (
901+ "\
886902 A
887903B
888904" , "\
889905 A
890906B
891907" , true ,
892- ) ;
908+ ) ;
893909
894- case (
895- "\
910+ case (
911+ "\
896912 A
897913B
898914" , "\
899915 A
900916B
901917" , false ,
902- ) ;
918+ ) ;
903919
904- case (
905- "\
920+ case (
921+ "\
906922 A
907923B" , "\
908924 A
909925B" , true ,
910- ) ;
926+ ) ;
911927
912- case (
913- "\
928+ case (
929+ "\
914930 A
915931B" , "\
916932 A
917933B" , false ,
918- ) ;
934+ ) ;
919935
920- case (
921- "\
936+ case (
937+ "\
922938 [DIRTY] a
923939" ,
924- "\
940+ "\
925941 [DIRTY-MSVC] a
926942" ,
927- true ,
928- ) ;
929- case (
930- "\n " ,
931- "\
943+ true ,
944+ ) ;
945+ case (
946+ "\n " ,
947+ "\
932948 [DIRTY-MSVC] a
933949" ,
934- false ,
935- ) ;
950+ false ,
951+ ) ;
936952
937- case (
938- "\
953+ case (
954+ "\
939955 [DIRTY] a",
940- "\
956+ "\
941957 [DIRTY-MSVC] a",
942- true ,
943- ) ;
944- case (
945- "" ,
946- "\
958+ true ,
959+ ) ;
960+ case (
961+ "" ,
962+ "\
947963 [DIRTY-MSVC] a",
948- false ,
949- ) ;
964+ false ,
965+ ) ;
966+ }
967+
968+ #[ test]
969+ fn redact_elapsed_time ( ) {
970+ let mut subs = snapbox:: Redactions :: new ( ) ;
971+ add_regex_redactions ( & mut subs) ;
972+
973+ assert_data_eq ! (
974+ subs. redact( "[FINISHED] `release` profile [optimized] target(s) in 5.5s" ) ,
975+ str ![ "[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s" ] . raw( )
976+ ) ;
977+ assert_data_eq ! (
978+ subs. redact( "[FINISHED] `release` profile [optimized] target(s) in 1m 05s" ) ,
979+ str ![ "[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s" ] . raw( )
980+ ) ;
981+ }
950982}
0 commit comments