@@ -41,6 +41,30 @@ impl Tester {
4141 let _ = LintRunner :: new ( options, None ) . with_cwd ( self . cwd . clone ( ) ) . run ( & mut output) ;
4242 }
4343
44+ pub fn test_fix ( file : & str , before : & str , after : & str ) {
45+ use std:: fs;
46+ #[ expect( clippy:: disallowed_methods) ]
47+ let content_original = fs:: read_to_string ( file) . unwrap ( ) . replace ( "\r \n " , "\n " ) ;
48+ assert_eq ! ( content_original, before) ;
49+
50+ Tester :: new ( ) . test ( & [ "--fix" , file] ) ;
51+
52+ #[ expect( clippy:: disallowed_methods) ]
53+ let new_content = fs:: read_to_string ( file) . unwrap ( ) . replace ( "\r \n " , "\n " ) ;
54+ assert_eq ! ( new_content, after) ;
55+
56+ Tester :: new ( ) . test ( & [ "--fix" , file] ) ;
57+
58+ // File should not be modified if no fix is applied.
59+ let modified_before: std:: time:: SystemTime =
60+ fs:: metadata ( file) . unwrap ( ) . modified ( ) . unwrap ( ) ;
61+ let modified_after = fs:: metadata ( file) . unwrap ( ) . modified ( ) . unwrap ( ) ;
62+ assert_eq ! ( modified_before, modified_after) ;
63+
64+ // Write the file back.
65+ fs:: write ( file, before) . unwrap ( ) ;
66+ }
67+
4468 pub fn test_and_snapshot ( & self , args : & [ & str ] ) {
4569 self . test_and_snapshot_multiple ( & [ args] ) ;
4670 }
0 commit comments