Files
sized/tests/cli.rs
T
gamertan db9059e2fc feat: optimization refactor, test suite, and dependency cleanup
Refactored the application to improve performance, maintainability, and binary size.

Key Changes:
- **Core Algorithm**: Switched to a parallel, single-pass tree construction algorithm for O(N) traversal.
- **Architecture**: Extract core logic from `main.rs` to `lib.rs` to enable unit testing.
- **Testing**: Added comprehensive unit tests and integration tests (`tests/cli.rs`) covering CLI arguments and output formats.
- **Benchmarking**: Added `criterion` benchmarks for performance tracking.
- **Dependencies**:
  - Removed `walkdir` (logic replaced by `ignore` + custom tree).
  - Removed `humansize` (consolidated to `byte-unit`).
  - Replaced `chrono` with lightweight `time` crate.
  - Removed unused `atty`.
- **Reporting**: Optimized CSV and JSON output for correctness and zero-copy performance.
- **Documentation**: Updated CHANGELOG.md and bumped version to 0.2.0.
2026-01-22 13:33:38 -05:00

48 lines
1.3 KiB
Rust

use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::fs::File;
use std::io::Write;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn test_basic_cli_run() {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_sized"));
cmd.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("sized 0.2.0"));
}
#[test]
fn test_run_on_directory() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test_file.txt");
File::create(&file_path)
.unwrap()
.write_all(b"Hello")
.unwrap();
let mut cmd = Command::new(env!("CARGO_BIN_EXE_sized"));
cmd.arg(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains("test_file.txt")); // Basic check
}
#[test]
fn test_json_output() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("data.json");
File::create(&file_path).unwrap().write_all(b"{}").unwrap();
let mut cmd = Command::new(env!("CARGO_BIN_EXE_sized"));
cmd.arg(temp_dir.path())
.arg("--format")
.arg("json")
.assert()
.success()
.stdout(predicate::str::contains("\"entry_type\":\"File\""))
.stdout(predicate::str::contains("\"path\":"));
}