@@ -176,10 +176,8 @@ impl<'test> TestCx<'test> {
176176 if proc_res. status . success ( ) {
177177 self . fatal_proc_rec ( "test failed: expected check failure, got success" , & proc_res) ;
178178 }
179- } else {
180- if !proc_res. status . success ( ) {
181- self . fatal_proc_rec ( "test failed: expected check success, got failure" , & proc_res) ;
182- }
179+ } else if !proc_res. status . success ( ) {
180+ self . fatal_proc_rec ( "test failed: expected check success, got failure" , & proc_res) ;
183181 }
184182 }
185183
@@ -202,13 +200,8 @@ impl<'test> TestCx<'test> {
202200 & proc_res,
203201 ) ;
204202 }
205- } else {
206- if !proc_res. status . success ( ) {
207- self . fatal_proc_rec (
208- "test failed: expected codegen success, got failure" ,
209- & proc_res,
210- ) ;
211- }
203+ } else if !proc_res. status . success ( ) {
204+ self . fatal_proc_rec ( "test failed: expected codegen success, got failure" , & proc_res) ;
212205 }
213206 }
214207
@@ -247,13 +240,11 @@ impl<'test> TestCx<'test> {
247240 & proc_res,
248241 ) ;
249242 }
250- } else {
251- if !proc_res. status . success ( ) {
252- self . fatal_proc_rec (
253- "test failed: expected verification success, got failure" ,
254- & proc_res,
255- ) ;
256- }
243+ } else if !proc_res. status . success ( ) {
244+ self . fatal_proc_rec (
245+ "test failed: expected verification success, got failure" ,
246+ & proc_res,
247+ ) ;
257248 }
258249 }
259250 }
@@ -278,12 +269,10 @@ impl<'test> TestCx<'test> {
278269 /// If the test file contains expected failures in some locations, ensure
279270 /// that verification does not succeed in those locations.
280271 fn verify_expect_fail ( str : & str ) -> Vec < usize > {
281- let re = Regex :: new ( r"line [0-9]+ EXPECTED FAIL: SUCCESS" ) . unwrap ( ) ;
272+ let re = Regex :: new ( r"line ( [0-9]+) EXPECTED FAIL: SUCCESS" ) . unwrap ( ) ;
282273 let mut lines = vec ! [ ] ;
283- for m in re. find_iter ( str) {
284- let splits = m. as_str ( ) . split_ascii_whitespace ( ) ;
285- let num_str = splits. skip ( 1 ) . next ( ) . unwrap ( ) ;
286- let num = num_str. parse ( ) . unwrap ( ) ;
274+ for m in re. captures_iter ( str) {
275+ let num = m. get ( 1 ) . unwrap ( ) . as_str ( ) . parse ( ) . unwrap ( ) ;
287276 lines. push ( num) ;
288277 }
289278 lines
@@ -365,35 +354,36 @@ impl<'test> TestCx<'test> {
365354 fn verify_output ( & self , proc_res : & ProcRes , expected : & str ) {
366355 // Include the output from stderr here for cases where there are exceptions
367356 let output = proc_res. stdout . to_string ( ) + & proc_res. stderr ;
368- if let Some ( lines) =
369- TestCx :: contains_lines ( & output. split ( '\n' ) . collect ( ) , expected. split ( '\n' ) . collect ( ) )
370- {
357+ if let Some ( lines) = TestCx :: contains_lines (
358+ & output. split ( '\n' ) . collect :: < Vec < _ > > ( ) ,
359+ expected. split ( '\n' ) . collect ( ) ,
360+ ) {
371361 self . fatal_proc_rec (
372362 & format ! (
373363 "test failed: expected output to contain the line(s):\n {}" ,
374364 lines. join( "\n " )
375365 ) ,
376- & proc_res,
366+ proc_res,
377367 ) ;
378368 }
379369 }
380370
381371 /// Looks for each line or set of lines in `str`. Returns `None` if all
382372 /// lines are in `str`. Otherwise, it returns the first line not found in
383373 /// `str`.
384- fn contains_lines < ' a > ( str : & Vec < & str > , lines : Vec < & ' a str > ) -> Option < Vec < & ' a str > > {
374+ fn contains_lines < ' a > ( str : & [ & str ] , lines : Vec < & ' a str > ) -> Option < Vec < & ' a str > > {
385375 let mut consecutive_lines: Vec < & str > = Vec :: new ( ) ;
386376 for line in lines {
387377 // A line that ends in "\" indicates that the next line in the
388378 // expected file should appear on the consecutive line in the
389379 // output. This is a temporary mechanism until we have more robust
390380 // json-based checking of verification results
391- if let Some ( prefix) = line. strip_suffix ( " \\ " ) {
381+ if let Some ( prefix) = line. strip_suffix ( '\\' ) {
392382 // accumulate the lines
393383 consecutive_lines. push ( prefix) ;
394384 } else {
395385 consecutive_lines. push ( line) ;
396- if !TestCx :: contains ( & str, & consecutive_lines) {
386+ if !TestCx :: contains ( str, & consecutive_lines) {
397387 return Some ( consecutive_lines) ;
398388 }
399389 consecutive_lines. clear ( ) ;
@@ -404,7 +394,7 @@ impl<'test> TestCx<'test> {
404394
405395 /// Check if there is a set of consecutive lines in `str` where each line
406396 /// contains a line from `lines`
407- fn contains ( str : & Vec < & str > , lines : & Vec < & str > ) -> bool {
397+ fn contains ( str : & [ & str ] , lines : & [ & str ] ) -> bool {
408398 let mut i = str. iter ( ) ;
409399 while let Some ( output_line) = i. next ( ) {
410400 if output_line. contains ( & lines[ 0 ] ) {
@@ -413,9 +403,9 @@ impl<'test> TestCx<'test> {
413403 let mut matches = true ;
414404 // Clone the iterator so that we keep i unchanged
415405 let mut j = i. clone ( ) ;
416- for i in 1 .. lines. len ( ) {
406+ for line in lines. iter ( ) . skip ( 1 ) {
417407 if let Some ( output_line) = j. next ( ) {
418- if output_line. contains ( lines [ i ] ) {
408+ if output_line. contains ( line ) {
419409 continue ;
420410 }
421411 }
@@ -431,7 +421,7 @@ impl<'test> TestCx<'test> {
431421 }
432422
433423 fn create_stamp ( & self ) {
434- let stamp = crate :: stamp ( & self . config , self . testpaths , self . revision ) ;
424+ let stamp = crate :: stamp ( self . config , self . testpaths , self . revision ) ;
435425 fs:: write ( & stamp, "we only support one configuration" ) . unwrap ( ) ;
436426 }
437427}
0 commit comments