Skip to content

Commit

Permalink
Report when no files were found. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleury authored Sep 8, 2024
1 parent ffc9ffa commit 5706b80
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
70 changes: 70 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ spinoff = { version = "0.8.0", features = ["dots"] }
[dev-dependencies]
assert_cmd = "2.0.16"
predicates = "3.1.2"
tempfile = "3.12.0"
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ fn main() -> anyhow::Result<()> {
let results = find_top_n_largest_files(&args.path, args.number)?;
sp.clear();

println!("*** Top {} largest files ***", results.len());
for (size, path) in results {
println!("{} {}", size, path.display());
if results.is_empty() {
println!("No files found.");
} else {
println!("*** Top {} largest files ***", results.len());
for (size, path) in results {
println!("{} {}", size, path.display());
}
}

Ok(())
Expand Down
12 changes: 12 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io::BufRead;

use assert_cmd::Command;
use tempfile::TempDir;

#[test]
fn binary_with_version_flag_prints_version() {
Expand Down Expand Up @@ -68,6 +69,17 @@ fn binary_with_the_number_arg_prints_the_top_n_largest_files_under_the_current_w
.stdout(predicates::str::contains("*** Top 10 largest files ***"));
}

#[test]
fn binary_reports_that_the_directory_is_empty_if_it_contains_zero_files() {
let dir = TempDir::new().expect("failed to create temporary directory");
Command::cargo_bin("spacehog")
.unwrap()
.arg(dir.path())
.assert()
.success()
.stdout(predicates::str::contains("No files found."));
}

#[test]
fn binary_with_invalid_path_arg_prints_an_error_message_and_exits_with_failure_code() {
#[cfg(windows)]
Expand Down

0 comments on commit 5706b80

Please sign in to comment.