@@ -223,4 +223,67 @@ Going to do perf runs for a few of these:
223223 ]
224224 ) ;
225225 }
226+
227+ #[ test]
228+ fn captures_backends ( ) {
229+ // First, check that the `build` command captures the `backends` parameter correctly.
230+ // Note that the build command without parameters is the last one, so that parsing doesn't
231+ // miss commands. See the FIXME on BODY_TIMER_BUILD for more details.
232+ let comment_body = r#"
233+ @rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af995A backends=Llvm
234+ @rust-timer build 23936af287657fa4148aeab40cc2a780810fae5B backends=Cranelift
235+ @rust-timer build 23936af287657fa4148aeab40cc2a780810fae5C backends=Cranelift,Llvm
236+ @rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af995D include=hello backends=Llvm
237+ @rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af995E runs=10 backends=Llvm
238+ @rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af995F backends=Llvm
239+ @rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af995G
240+ "# ;
241+ let backends = build_captures ( comment_body)
242+ . map ( |( _, captures) | captures. get ( 5 ) . map ( |v| v. as_str ( ) ) )
243+ . collect :: < Vec < _ > > ( ) ;
244+ assert_eq ! (
245+ backends,
246+ & [
247+ Some ( "Llvm" ) ,
248+ Some ( "Cranelift" ) ,
249+ Some ( "Cranelift,Llvm" ) ,
250+ Some ( "Llvm" ) ,
251+ Some ( "Llvm" ) ,
252+ Some ( "Llvm" ) ,
253+ None ,
254+ ]
255+ ) ;
256+
257+ // Then, check that the `queue` command captures the `backends` parameter correctly
258+ let capture_backends = |comment_body| {
259+ BODY_TIMER_QUEUE
260+ . captures ( comment_body)
261+ . and_then ( |captures| captures. get ( 4 ) . map ( |v| v. as_str ( ) ) )
262+ } ;
263+
264+ assert_eq ! (
265+ capture_backends( "@rust-timer queue backends=Llvm" ) ,
266+ Some ( "Llvm" )
267+ ) ;
268+ assert_eq ! (
269+ capture_backends( "@rust-timer queue backends=Cranelift" ) ,
270+ Some ( "Cranelift" )
271+ ) ;
272+ assert_eq ! (
273+ capture_backends( "@rust-timer queue backends=Cranelift,Llvm" ) ,
274+ Some ( "Cranelift,Llvm" )
275+ ) ;
276+ assert_eq ! ( capture_backends( "@rust-timer queue backends=" ) , None ) ;
277+ assert_eq ! ( capture_backends( "@rust-timer queue" ) , None ) ;
278+ assert_eq ! (
279+ capture_backends( "@rust-timer queue include=hello backends=Llvm" ) ,
280+ Some ( "Llvm" )
281+ ) ;
282+ assert_eq ! (
283+ capture_backends(
284+ "@rust-timer queue include=hello exclude=ripgrep runs=3 backends=Llvm"
285+ ) ,
286+ Some ( "Llvm" )
287+ ) ;
288+ }
226289}
0 commit comments