Skip to content

Commit

Permalink
Add a warning to cargo clean --dry-run
Browse files Browse the repository at this point in the history
This makes it more consistent with other `--dry-run` commands, and
makes it clearer to the user that cargo did not do anything.
  • Loading branch information
ehuss committed Sep 20, 2023
1 parent ebee726 commit f61d42d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ impl<'cfg> CleanContext<'cfg> {
};
self.config
.shell()
.status(status, format!("{file_count}{byte_count}"))
.status(status, format!("{file_count}{byte_count}"))?;
if self.dry_run {
self.config
.shell()
.warn("no files deleted due to --dry-run")?;
}
Ok(())
}

/// Deletes all of the given paths, showing a progress bar as it proceeds.
Expand Down
15 changes: 12 additions & 3 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,19 @@ fn clean_dry_run() {
// Start with no files.
p.cargo("clean --dry-run")
.with_stdout("")
.with_stderr("[SUMMARY] 0 files")
.with_stderr(
"[SUMMARY] 0 files\n\
[WARNING] no files deleted due to --dry-run",
)
.run();
p.cargo("check").run();
let before = ls_r();
p.cargo("clean --dry-run")
.with_stdout("[CWD]/target")
.with_stderr("[SUMMARY] [..] files, [..] total")
.with_stderr(
"[SUMMARY] [..] files, [..] total\n\
[WARNING] no files deleted due to --dry-run",
)
.run();
// Verify it didn't delete anything.
let after = ls_r();
Expand All @@ -833,7 +839,10 @@ fn clean_dry_run() {
// Verify the verbose output.
p.cargo("clean --dry-run -v")
.with_stdout_unordered(expected)
.with_stderr("[SUMMARY] [..] files, [..] total")
.with_stderr(
"[SUMMARY] [..] files, [..] total\n\
[WARNING] no files deleted due to --dry-run",
)
.run();
}

Expand Down

0 comments on commit f61d42d

Please sign in to comment.