@@ -157,6 +157,12 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
157157 let cache_dir = clang_params. repo_root . join ( ClangParams :: CACHE_DIR ) ;
158158 std:: fs:: create_dir_all ( & cache_dir)
159159 . with_context ( || "Failed to create a local cache directory." ) ?;
160+ // delete old patch file
161+ let patch_file = cache_dir. join ( ClangParams :: AUTO_FIX_PATCH ) ;
162+ if patch_file. exists ( ) {
163+ std:: fs:: remove_file ( & patch_file)
164+ . with_context ( || "Failed to remove old patch file from previous runs." ) ?;
165+ }
160166 // add gitignore file in project cache dir
161167 std:: fs:: write (
162168 cache_dir. join ( ".gitignore" ) ,
@@ -193,7 +199,7 @@ pub(crate) mod test {
193199 #![ allow( clippy:: unwrap_used) ]
194200
195201 use super :: run_main;
196- use crate :: test_common:: setup_tmp_workspace;
202+ use crate :: { cli :: ClangParams , test_common:: setup_tmp_workspace} ;
197203 use std:: env;
198204
199205 /// helper to avoid writing to the same GITHUB_OUTPUT file in parallel-running tests.
@@ -238,6 +244,13 @@ pub(crate) mod test {
238244 async fn force_debug_output ( ) {
239245 let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
240246 let tmp_workspace = setup_tmp_workspace ( ) ;
247+
248+ // create a dummy patch file to ensure it is deleted (in code coverage).
249+ let cache_dir = tmp_workspace. path ( ) . join ( ClangParams :: CACHE_DIR ) ;
250+ std:: fs:: create_dir_all ( & cache_dir) . unwrap ( ) ;
251+ let patch_path = cache_dir. join ( ClangParams :: AUTO_FIX_PATCH ) ;
252+ std:: fs:: write ( & patch_path, "" ) . unwrap ( ) ;
253+
241254 run_main ( vec ! [
242255 "cpp-linter" . to_string( ) ,
243256 "-l" . to_string( ) ,
0 commit comments