@@ -88,7 +88,11 @@ macro_rules! regex {
88
88
/// - Carriage returns are removed, which can help when running on Windows.
89
89
pub fn assert_ui ( ) -> snapbox:: Assert {
90
90
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
+
92
96
snapbox:: Assert :: new ( )
93
97
. action_env ( snapbox:: assert:: DEFAULT_ACTION_ENV )
94
98
. redact_with ( subs)
@@ -127,41 +131,49 @@ pub fn assert_ui() -> snapbox::Assert {
127
131
/// - Carriage returns are removed, which can help when running on Windows.
128
132
pub fn assert_e2e ( ) -> snapbox:: Assert {
129
133
let mut subs = snapbox:: Redactions :: new ( ) ;
130
- add_common_redactions ( & mut subs) ;
134
+ subs. extend ( MIN_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
135
+ . unwrap ( ) ;
131
136
subs. extend ( E2E_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
132
137
. unwrap ( ) ;
138
+ add_test_support_redactions ( & mut subs) ;
139
+ add_regex_redactions ( & mut subs) ;
133
140
134
141
snapbox:: Assert :: new ( )
135
142
. action_env ( snapbox:: assert:: DEFAULT_ACTION_ENV )
136
143
. redact_with ( subs)
137
144
}
138
145
139
- fn add_common_redactions ( subs : & mut snapbox:: Redactions ) {
146
+ fn add_test_support_redactions ( subs : & mut snapbox:: Redactions ) {
140
147
let root = paths:: root ( ) ;
141
148
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
142
149
// put in the users output, rather than hidden in the variable
143
150
let root_url = url:: Url :: from_file_path ( & root) . unwrap ( ) . to_string ( ) ;
144
151
145
- subs. extend ( MIN_LITERAL_REDACTIONS . into_iter ( ) . cloned ( ) )
146
- . unwrap ( ) ;
147
152
subs. insert ( "[ROOT]" , root) . unwrap ( ) ;
148
153
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 ) {
149
161
// For e2e tests
150
162
subs. insert (
151
163
"[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" ) ,
153
165
)
154
166
. unwrap ( ) ;
155
167
// for UI tests
156
168
subs. insert (
157
169
"[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" ) ,
159
171
)
160
172
. unwrap ( ) ;
161
173
// output from libtest
162
174
subs. insert (
163
175
"[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" ) ,
165
177
)
166
178
. unwrap ( ) ;
167
179
subs. insert (
@@ -186,10 +198,6 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
186
198
. unwrap ( ) ;
187
199
subs. insert ( "[HASH]" , regex ! ( r"/[a-z0-9\-_]+-(?<redacted>[0-9a-f]{16})" ) )
188
200
. 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
- }
193
201
subs. insert (
194
202
"[AVG_ELAPSED]" ,
195
203
regex ! ( r"(?<redacted>[0-9]+(\.[0-9]+)?) ns/iter" ) ,
@@ -822,129 +830,153 @@ impl fmt::Debug for WildStr<'_> {
822
830
}
823
831
}
824
832
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
+ }
838
855
}
839
- }
840
856
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
+ } ;
846
862
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 ) ;
850
866
851
- // with replacements
852
- case (
853
- "\
867
+ // with replacements
868
+ case (
869
+ "\
854
870
[DIRTY] a",
855
- "\
871
+ "\
856
872
[DIRTY-MSVC] a",
857
- true ,
858
- ) ;
859
- case (
860
- "" ,
861
- "\
873
+ true ,
874
+ ) ;
875
+ case (
876
+ "" ,
877
+ "\
862
878
[DIRTY-MSVC] a",
863
- false ,
864
- ) ;
865
- case (
866
- "\
879
+ false ,
880
+ ) ;
881
+ case (
882
+ "\
867
883
[DIRTY] a
868
884
[COMPILING] a" ,
869
- "\
885
+ "\
870
886
[DIRTY-MSVC] a
871
887
[COMPILING] a" ,
872
- true ,
873
- ) ;
874
- case (
875
- "\
888
+ true ,
889
+ ) ;
890
+ case (
891
+ "\
876
892
[COMPILING] a",
877
- "\
893
+ "\
878
894
[DIRTY-MSVC] a
879
895
[COMPILING] a" ,
880
- false ,
881
- ) ;
896
+ false ,
897
+ ) ;
882
898
883
- // test trailing newline behavior
884
- case (
885
- "\
899
+ // test trailing newline behavior
900
+ case (
901
+ "\
886
902
A
887
903
B
888
904
" , "\
889
905
A
890
906
B
891
907
" , true ,
892
- ) ;
908
+ ) ;
893
909
894
- case (
895
- "\
910
+ case (
911
+ "\
896
912
A
897
913
B
898
914
" , "\
899
915
A
900
916
B
901
917
" , false ,
902
- ) ;
918
+ ) ;
903
919
904
- case (
905
- "\
920
+ case (
921
+ "\
906
922
A
907
923
B" , "\
908
924
A
909
925
B" , true ,
910
- ) ;
926
+ ) ;
911
927
912
- case (
913
- "\
928
+ case (
929
+ "\
914
930
A
915
931
B" , "\
916
932
A
917
933
B" , false ,
918
- ) ;
934
+ ) ;
919
935
920
- case (
921
- "\
936
+ case (
937
+ "\
922
938
[DIRTY] a
923
939
" ,
924
- "\
940
+ "\
925
941
[DIRTY-MSVC] a
926
942
" ,
927
- true ,
928
- ) ;
929
- case (
930
- "\n " ,
931
- "\
943
+ true ,
944
+ ) ;
945
+ case (
946
+ "\n " ,
947
+ "\
932
948
[DIRTY-MSVC] a
933
949
" ,
934
- false ,
935
- ) ;
950
+ false ,
951
+ ) ;
936
952
937
- case (
938
- "\
953
+ case (
954
+ "\
939
955
[DIRTY] a",
940
- "\
956
+ "\
941
957
[DIRTY-MSVC] a",
942
- true ,
943
- ) ;
944
- case (
945
- "" ,
946
- "\
958
+ true ,
959
+ ) ;
960
+ case (
961
+ "" ,
962
+ "\
947
963
[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
+ }
950
982
}
0 commit comments