1- use std:: collections:: HashSet ;
1+ use std:: collections:: BTreeSet ;
22use std:: fs:: { self , File } ;
33use std:: io:: { BufRead , BufReader , ErrorKind } ;
44use std:: path:: { Path , PathBuf } ;
@@ -17,8 +17,16 @@ impl RecordFailedTests {
1717 }
1818}
1919
20- impl RecordFailedTests { }
21-
20+ /// This step is run as a dependency of most testing steps.
21+ /// Upon running, a file is created for failed tests to be recorded in if `--record` is passed on
22+ /// the command line.
23+ ///
24+ /// This step is the only way to get access to a token type called [`RecordFailedTests`].
25+ /// Having this token type signifies the fact that a file was created to store failed tests in,
26+ /// and is required to create a `Renderer`, the type that renders the outputs of tests.
27+ ///
28+ /// If `--rerun` isn't passed, or we're in dry-run mode, running this step is a no-op,
29+ /// and the `RecordFailedTest` type doesn't (need to) signify anything.
2230#[ derive( Clone , Copy , Eq , PartialEq , Hash , Debug ) ]
2331pub struct SetupFailedTestsFile ;
2432impl Step for SetupFailedTestsFile {
@@ -46,7 +54,9 @@ impl Step for SetupFailedTestsFile {
4654 }
4755}
4856
49- pub fn collect_previously_failed_tests ( failed_tests_file_path : & PathBuf , paths : & mut Vec < PathBuf > ) {
57+ pub fn collect_previously_failed_tests ( failed_tests_file_path : & PathBuf ) -> Vec < PathBuf > {
58+ let mut paths = BTreeSet :: new ( ) ;
59+
5060 println ! (
5161 "`--rerun` passed so looking for failed tests in {}" ,
5262 failed_tests_file_path. display( )
@@ -58,45 +68,43 @@ pub fn collect_previously_failed_tests(failed_tests_file_path: &PathBuf, paths:
5868 println ! (
5969 "WARNING: failed tests file doesn't exist: `--rerun` only makes sense after a previous test run with `--record`"
6070 ) ;
61- return ;
71+ return Vec :: new ( ) ;
6272 }
6373 Err ( e) => t ! ( Err ( e) ) ,
6474 } ;
6575
66- let mut set_tracking_duplicates = HashSet :: new ( ) ;
67- let mut num_printed = 0 ;
6876 const MAX_RERUN_PRINTS : usize = 10 ;
6977
7078 for line in lines {
7179 let trimmed = line. as_str ( ) . trim ( ) ;
7280 let without_revision =
73- trimmed. rsplit_once ( "#" ) . map ( |( before, _) | before) . unwrap_or ( & trimmed) ;
81+ trimmed. rsplit_once ( "#" ) . map ( |( before, _) | before) . unwrap_or ( trimmed) ;
7482 let without_suite_prefix = without_revision
7583 . strip_prefix ( "[" )
7684 . and_then ( |rest| rest. split_once ( "]" ) )
7785 . map ( |( _, after) | after. trim ( ) )
7886 . unwrap_or ( without_revision) ;
7987
8088 let failed_test_path = PathBuf :: from ( without_suite_prefix. to_string ( ) ) ;
81- if set_tracking_duplicates . insert ( failed_test_path. clone ( ) ) {
82- if num_printed == 0 {
83- println ! ( "rerunning previousy failed tests:" ) ;
89+ if paths . insert ( failed_test_path. clone ( ) ) {
90+ if paths . len ( ) == 1 {
91+ println ! ( "rerunning previously failed tests:" ) ;
8492 }
85- if num_printed < MAX_RERUN_PRINTS {
93+ if paths . len ( ) <= MAX_RERUN_PRINTS {
8694 println ! ( " {}" , failed_test_path. display( ) ) ;
87- num_printed += 1 ;
8895 }
89- paths. push ( failed_test_path) ;
9096 }
9197 }
9298
93- if num_printed == MAX_RERUN_PRINTS && set_tracking_duplicates . len ( ) > MAX_RERUN_PRINTS {
94- println ! ( " and {} more..." , set_tracking_duplicates . len( ) - MAX_RERUN_PRINTS )
99+ if paths . len ( ) > MAX_RERUN_PRINTS {
100+ println ! ( " and {} more..." , paths . len( ) - MAX_RERUN_PRINTS )
95101 }
96102
97- if set_tracking_duplicates . is_empty ( ) {
103+ if paths . is_empty ( ) {
98104 println ! (
99105 "WARNING: failed tests file doesn't contain any failed tests: `--rerun` only makes sense after a previous test run with `--record`"
100106 ) ;
101107 }
108+
109+ paths. into_iter ( ) . collect ( )
102110}
0 commit comments