diff --git a/crates/cairo-coverage/src/commands/clean.rs b/crates/cairo-coverage/src/commands/clean.rs index c699776..f20bbf6 100644 --- a/crates/cairo-coverage/src/commands/clean.rs +++ b/crates/cairo-coverage/src/commands/clean.rs @@ -33,3 +33,70 @@ pub fn run(args: CleanArgs) -> Result<()> { println!("Cleanup complete."); Ok(()) } + +#[cfg(test)] +mod tests { + use super::super::clean; + use super::CleanArgs; + use assert_fs::fixture::PathChild; + use assert_fs::TempDir; + use test_utils::{CreateFile, Utf8PathBufConversion}; + + #[test] + fn test_clean_removes_target_files() { + let temp_dir = TempDir::new().unwrap(); + + let sub_dir = temp_dir.child("sub_dir"); + let sub_sub_dir = sub_dir.child("nested_dir"); + + let file_to_delete_1 = temp_dir.create_file("coverage.lcov"); + let file_to_delete_2 = sub_dir.create_file("coverage.lcov"); + let file_to_delete_3 = sub_sub_dir.create_file("coverage.lcov"); + let non_target_file = temp_dir.create_file("keep_this.txt"); + + let clean_args = CleanArgs { + root_dir: temp_dir.to_utf8_path_buf(), + files_to_delete: "coverage.lcov".into(), + }; + + clean::run(clean_args).unwrap(); + + assert!(!file_to_delete_1.exists()); + assert!(!file_to_delete_2.exists()); + assert!(!file_to_delete_3.exists()); + assert!(non_target_file.exists()); + } + + #[test] + fn test_clean_does_nothing_for_nonexistent_files() { + let temp_dir = TempDir::new().unwrap(); + + let sub_dir = temp_dir.child("sub_dir"); + let file_1 = temp_dir.create_file("some_file.txt"); + let file_2 = sub_dir.create_file("another_file.rs"); + + let clean_args = CleanArgs { + root_dir: temp_dir.to_utf8_path_buf(), + files_to_delete: "nonexistent_file.txt".into(), + }; + + clean::run(clean_args).unwrap(); + + assert!(file_1.exists()); + assert!(file_2.exists()); + } + + #[test] + fn test_clean_handles_empty_directory() { + let temp_dir = TempDir::new().unwrap(); + + let clean_args = CleanArgs { + root_dir: temp_dir.to_utf8_path_buf(), + files_to_delete: "coverage.lcov".into(), + }; + + clean::run(clean_args).unwrap(); + + // No assertion needed—just ensuring no panics or errors occur + } +}