11//! Proptest-driven fuzz test against real GitHub repos with a live watcher.
22//!
33//! Clones real repository, runs the simulated close to real user sereies of file system ewvents and
4- //! verifies that fff can still find the correct files. Test cases are randomzied and preserved
4+ //! verifies that fff can still find the correct files. Test cases are randomized and preserved
55//! using proptest
66//!
77//! Run:
@@ -104,7 +104,11 @@ fn copy_repo_to_workdir(cached: &Path, workdir: &Path) {
104104 . arg ( workdir)
105105 . output ( )
106106 . expect ( "cp -r failed" ) ;
107- assert ! ( out. status. success( ) , "cp -r failed: {}" , String :: from_utf8_lossy( & out. stderr) ) ;
107+ assert ! (
108+ out. status. success( ) ,
109+ "cp -r failed: {}" ,
110+ String :: from_utf8_lossy( & out. stderr)
111+ ) ;
108112}
109113
110114fn collect_text_files ( base : & Path ) -> Vec < PathBuf > {
@@ -156,7 +160,9 @@ fn collect_text_files(base: &Path) -> Vec<PathBuf> {
156160 if path. is_empty ( ) {
157161 continue ;
158162 }
159- let Ok ( s) = std:: str:: from_utf8 ( path) else { continue } ;
163+ let Ok ( s) = std:: str:: from_utf8 ( path) else {
164+ continue ;
165+ } ;
160166 if ignored_set. contains ( s) {
161167 continue ;
162168 }
@@ -199,7 +205,9 @@ fn inject_marker(path: &Path, marker: &str, seed: u32) -> Option<String> {
199205/// Revert a file by restoring the original line at the same position
200206/// where inject_marker placed the marker.
201207fn revert_marker ( path : & Path , marker : & str , original_line : & str ) {
202- let Ok ( content) = fs:: read_to_string ( path) else { return } ;
208+ let Ok ( content) = fs:: read_to_string ( path) else {
209+ return ;
210+ } ;
203211 let marker_line = format ! ( "// {marker}" ) ;
204212 let result: String = content
205213 . lines ( )
@@ -293,9 +301,8 @@ fn run_scenario(ops: &[Op]) {
293301 // Stream fff logs at info+ level by default. Override with RUST_LOG.
294302 let _ = tracing_subscriber:: fmt ( )
295303 . with_env_filter (
296- tracing_subscriber:: EnvFilter :: try_from_default_env ( ) . unwrap_or_else ( |_| {
297- tracing_subscriber:: EnvFilter :: new ( "warn,fff_search=info" )
298- } ) ,
304+ tracing_subscriber:: EnvFilter :: try_from_default_env ( )
305+ . unwrap_or_else ( |_| tracing_subscriber:: EnvFilter :: new ( "warn,fff_search=info" ) ) ,
299306 )
300307 . with_test_writer ( )
301308 . try_init ( ) ;
@@ -389,7 +396,13 @@ fn run_scenario(ops: &[Op]) {
389396 let content = fs:: read_to_string ( & path) . unwrap_or_default ( ) ;
390397 let new_content = content
391398 . lines ( )
392- . map ( |l| if l == old_marker_line { format ! ( "// {new_marker}" ) } else { l. to_string ( ) } )
399+ . map ( |l| {
400+ if l == old_marker_line {
401+ format ! ( "// {new_marker}" )
402+ } else {
403+ l. to_string ( )
404+ }
405+ } )
393406 . collect :: < Vec < _ > > ( )
394407 . join ( "\n " )
395408 + "\n " ;
@@ -426,7 +439,13 @@ fn run_scenario(ops: &[Op]) {
426439 let content = fs:: read_to_string ( target) . unwrap_or_default ( ) ;
427440 let new_content = content
428441 . lines ( )
429- . map ( |l| if l == old_marker_line { format ! ( "// {marker}" ) } else { l. to_string ( ) } )
442+ . map ( |l| {
443+ if l == old_marker_line {
444+ format ! ( "// {marker}" )
445+ } else {
446+ l. to_string ( )
447+ }
448+ } )
430449 . collect :: < Vec < _ > > ( )
431450 . join ( "\n " )
432451 + "\n " ;
@@ -436,8 +455,7 @@ fn run_scenario(ops: &[Op]) {
436455 tracked[ pos] . last_write_sec = epoch_secs ( ) ;
437456 } else {
438457 // First edit: inject marker at a deterministic line
439- let original = inject_marker ( target, & marker, * seed)
440- . unwrap_or_default ( ) ;
458+ let original = inject_marker ( target, & marker, * seed) . unwrap_or_default ( ) ;
441459 tracked. push ( TrackedFile {
442460 relative,
443461 marker,
@@ -540,7 +558,9 @@ fn run_scenario(ops: &[Op]) {
540558 last_failure = Some ( format ! (
541559 "{mode_name} grep for {:?} in {:?} not found\n \
542560 is_created={} exists={} on_disk_has_marker={}",
543- tf. marker, tf. relative, tf. is_created,
561+ tf. marker,
562+ tf. relative,
563+ tf. is_created,
544564 workdir. join( & tf. relative) . exists( ) ,
545565 fs:: read_to_string( workdir. join( & tf. relative) )
546566 . map( |c| c. contains( & tf. marker) )
@@ -561,9 +581,7 @@ fn run_scenario(ops: &[Op]) {
561581 let found = grep_finds ( picker, dead, GrepMode :: PlainText ) ;
562582 drop ( guard) ;
563583 if found {
564- last_failure = Some ( format ! (
565- "dead marker {dead:?} still findable"
566- ) ) ;
584+ last_failure = Some ( format ! ( "dead marker {dead:?} still findable" ) ) ;
567585 all_ok = false ;
568586 break ;
569587 }
@@ -578,9 +596,8 @@ fn run_scenario(ops: &[Op]) {
578596 let files = grep_file_list ( picker, ig, GrepMode :: PlainText ) ;
579597 drop ( guard) ;
580598 if !files. is_empty ( ) {
581- last_failure = Some ( format ! (
582- "ignored marker {ig:?} found in {files:?}"
583- ) ) ;
599+ last_failure =
600+ Some ( format ! ( "ignored marker {ig:?} found in {files:?}" ) ) ;
584601 all_ok = false ;
585602 break ;
586603 }
@@ -590,7 +607,9 @@ fn run_scenario(ops: &[Op]) {
590607 if all_ok {
591608 eprintln ! (
592609 " op[{op_idx}] verify OK: {mode_name} mode, {} live, {} dead, {} ignored" ,
593- tracked. len( ) , dead_markers. len( ) , ignored_markers. len( ) ,
610+ tracked. len( ) ,
611+ dead_markers. len( ) ,
612+ ignored_markers. len( ) ,
594613 ) ;
595614 break ;
596615 }
@@ -616,8 +635,12 @@ fn run_scenario(ops: &[Op]) {
616635 let guard = shared_picker. read ( ) . unwrap ( ) ;
617636 let picker = guard. as_ref ( ) . unwrap ( ) ;
618637
619- let live_ok = tracked. iter ( ) . all ( |tf| grep_finds ( picker, & tf. marker , GrepMode :: PlainText ) ) ;
620- let dead_ok = dead_markers. iter ( ) . all ( |d| !grep_finds ( picker, d, GrepMode :: PlainText ) ) ;
638+ let live_ok = tracked
639+ . iter ( )
640+ . all ( |tf| grep_finds ( picker, & tf. marker , GrepMode :: PlainText ) ) ;
641+ let dead_ok = dead_markers
642+ . iter ( )
643+ . all ( |d| !grep_finds ( picker, d, GrepMode :: PlainText ) ) ;
621644 drop ( guard) ;
622645
623646 if live_ok && dead_ok {
0 commit comments