@@ -45,6 +45,15 @@ use std::path::Path;
45
45
use std:: str;
46
46
use url:: Url ;
47
47
48
+ /// This makes it easier to write regex replacements that are guaranteed to only
49
+ /// get compiled once
50
+ macro_rules! regex {
51
+ ( $re: literal $( , ) ?) => { {
52
+ static RE : std:: sync:: OnceLock <regex:: Regex > = std:: sync:: OnceLock :: new( ) ;
53
+ RE . get_or_init( || regex:: Regex :: new( $re) . unwrap( ) )
54
+ } } ;
55
+ }
56
+
48
57
/// Assertion policy for UI tests
49
58
///
50
59
/// This emphasizes showing as much content as possible at the cost of more brittleness
@@ -139,29 +148,29 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
139
148
// For e2e tests
140
149
subs. insert (
141
150
"[ELAPSED]" ,
142
- regex:: Regex :: new ( "[FINISHED].*in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) . unwrap ( ) ,
151
+ regex ! ( "[FINISHED].*in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) ,
143
152
)
144
153
. unwrap ( ) ;
145
154
// for UI tests
146
155
subs. insert (
147
156
"[ELAPSED]" ,
148
- regex:: Regex :: new ( "Finished.*in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) . unwrap ( ) ,
157
+ regex ! ( "Finished.*in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) ,
149
158
)
150
159
. unwrap ( ) ;
151
160
// output from libtest
152
161
subs. insert (
153
162
"[ELAPSED]" ,
154
- regex:: Regex :: new ( "; finished in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) . unwrap ( ) ,
163
+ regex ! ( "; finished in (?<redacted>[0-9]+(\\ .[0-9]+))s" ) ,
155
164
)
156
165
. unwrap ( ) ;
157
166
subs. insert (
158
167
"[FILE_SIZE]" ,
159
- regex:: Regex :: new ( "(?<redacted>[0-9]+(\\ .[0-9]+)([a-zA-Z]i)?)B" ) . unwrap ( ) ,
168
+ regex ! ( "(?<redacted>[0-9]+(\\ .[0-9]+)([a-zA-Z]i)?)B" ) ,
160
169
)
161
170
. unwrap ( ) ;
162
171
subs. insert (
163
172
"[HASH]" ,
164
- regex:: Regex :: new ( "home/\\ .cargo/registry/src/-(?<redacted>[a-z0-9]+)" ) . unwrap ( ) ,
173
+ regex ! ( "home/\\ .cargo/registry/src/-(?<redacted>[a-z0-9]+)" ) ,
165
174
)
166
175
. unwrap ( ) ;
167
176
}
0 commit comments