@@ -52,6 +52,13 @@ pub struct WatchArgs {
5252 #[ arg( long) ]
5353 pub run_all : bool ,
5454
55+ /// Re-run only previously failed tests first when a change is made.
56+ ///
57+ /// If all previously failed tests pass, the full test suite will be run automatically.
58+ /// This is particularly useful for TDD workflows where you want fast feedback on failures.
59+ #[ arg( long, alias = "rerun-failures" ) ]
60+ pub rerun_failed : bool ,
61+
5562 /// File update debounce delay.
5663 ///
5764 /// During the delay, incoming change events are accumulated and
@@ -303,9 +310,23 @@ pub async fn watch_test(args: TestArgs) -> Result<()> {
303310
304311 let last_test_files = Mutex :: new ( HashSet :: < String > :: default ( ) ) ;
305312 let project_root = config. root . to_string_lossy ( ) . into_owned ( ) ;
313+ let test_failures_file = config. test_failures_file . clone ( ) ;
314+ let rerun_failed = args. watch . rerun_failed ;
315+
306316 let config = args. watch . watchexec_config_with_override (
307317 || Ok ( [ & config. test , & config. src ] ) ,
308318 move |events, command| {
319+ // Check if we should prioritize rerunning failed tests
320+ let has_failures = rerun_failed && test_failures_file. exists ( ) ;
321+
322+ if has_failures {
323+ // Smart mode: rerun failed tests first
324+ trace ! ( "Smart watch mode: will rerun failed tests first" ) ;
325+ command. arg ( "--rerun" ) ;
326+ // Don't add file-specific filters when rerunning failures
327+ return ;
328+ }
329+
309330 let mut changed_sol_test_files: HashSet < _ > = events
310331 . iter ( )
311332 . flat_map ( |e| e. paths ( ) )
0 commit comments