Add a warning to cargo clean --dry-run

This makes it more consistent with other `--dry-run` commands, and
makes it clearer to the user that cargo did not do anything.
This commit is contained in:
Eric Huss 2023-09-10 12:07:49 -07:00
parent ebee726d8f
commit f61d42d5ef
2 changed files with 19 additions and 4 deletions

View File

@ -417,7 +417,13 @@ impl<'cfg> CleanContext<'cfg> {
}; };
self.config self.config
.shell() .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. /// Deletes all of the given paths, showing a progress bar as it proceeds.

View File

@ -817,13 +817,19 @@ fn clean_dry_run() {
// Start with no files. // Start with no files.
p.cargo("clean --dry-run") p.cargo("clean --dry-run")
.with_stdout("") .with_stdout("")
.with_stderr("[SUMMARY] 0 files") .with_stderr(
"[SUMMARY] 0 files\n\
[WARNING] no files deleted due to --dry-run",
)
.run(); .run();
p.cargo("check").run(); p.cargo("check").run();
let before = ls_r(); let before = ls_r();
p.cargo("clean --dry-run") p.cargo("clean --dry-run")
.with_stdout("[CWD]/target") .with_stdout("[CWD]/target")
.with_stderr("[SUMMARY] [..] files, [..] total") .with_stderr(
"[SUMMARY] [..] files, [..] total\n\
[WARNING] no files deleted due to --dry-run",
)
.run(); .run();
// Verify it didn't delete anything. // Verify it didn't delete anything.
let after = ls_r(); let after = ls_r();
@ -833,7 +839,10 @@ fn clean_dry_run() {
// Verify the verbose output. // Verify the verbose output.
p.cargo("clean --dry-run -v") p.cargo("clean --dry-run -v")
.with_stdout_unordered(expected) .with_stdout_unordered(expected)
.with_stderr("[SUMMARY] [..] files, [..] total") .with_stderr(
"[SUMMARY] [..] files, [..] total\n\
[WARNING] no files deleted due to --dry-run",
)
.run(); .run();
} }