test: 13 Integration-Tests hinzugefügt + .gitignore optimiert
Integration-Tests: - test_help_flag, test_version_flag - test_dry_run_no_changes, test_actual_rename - test_hidden_files_preserved, test_hidden_file_with_spaces - test_umlaut_conversion, test_double_extension - test_exclude_pattern, test_quiet_mode - test_multiple_paths, test_parentheses_removed - test_special_identifiers_preserved .gitignore: - Besser organisiert (Kategorien) - Cargo.lock hinzugefügt - Temporäre Dateien (*.tmp, *.log, *.bak) - OS-spezifische Dateien (Thumbs.db) - Test-Artefakte Gesamt: 22 Tests (9 Unit + 13 Integration) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
77aa782718
commit
1b9ad5a74f
4 changed files with 250 additions and 0 deletions
194
tests/integration_tests.rs
Normal file
194
tests/integration_tests.rs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
use assert_cmd::assert::OutputAssertExt;
|
||||
use assert_cmd::cargo::CommandCargoExt;
|
||||
use predicates::prelude::*;
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_help_flag() {
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg("--help");
|
||||
cmd.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("Usage: ntu"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version_flag() {
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg("--version");
|
||||
cmd.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("NameToUnix"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dry_run_no_changes() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("test file.txt");
|
||||
fs::write(&file_path, "test content").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg("--dry-run").arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// File should still have spaces (not renamed)
|
||||
assert!(file_path.exists());
|
||||
assert!(!temp_dir.path().join("test_file.txt").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_actual_rename() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("test file.txt");
|
||||
fs::write(&file_path, "test content").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// File should be renamed
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join("test_file.txt").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hidden_files_preserved() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join(".gitignore");
|
||||
fs::write(&file_path, "*.tmp").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Hidden file should not be renamed
|
||||
assert!(file_path.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hidden_file_with_spaces() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join(".my config");
|
||||
fs::write(&file_path, "config content").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Hidden file should be renamed but keep leading dot
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join(".my_config").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_umlaut_conversion() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("Müller.txt");
|
||||
fs::write(&file_path, "test").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Umlaut should be converted
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join("Mueller.txt").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_extension() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("my archive.tar.gz");
|
||||
fs::write(&file_path, "archive").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Should keep .tar.gz intact
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join("my_archive.tar.gz").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exclude_pattern() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file1 = temp_dir.path().join("test file.txt");
|
||||
let file2 = temp_dir.path().join("test file.tmp");
|
||||
fs::write(&file1, "test1").unwrap();
|
||||
fs::write(&file2, "test2").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg("--exclude")
|
||||
.arg("*.tmp")
|
||||
.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// .txt should be renamed, .tmp should not
|
||||
assert!(!file1.exists());
|
||||
assert!(temp_dir.path().join("test_file.txt").exists());
|
||||
assert!(file2.exists()); // Excluded
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quiet_mode() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("test file.txt");
|
||||
fs::write(&file_path, "test").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg("--quiet").arg(temp_dir.path());
|
||||
cmd.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_paths() {
|
||||
let temp_dir1 = TempDir::new().unwrap();
|
||||
let temp_dir2 = TempDir::new().unwrap();
|
||||
let file1 = temp_dir1.path().join("file 1.txt");
|
||||
let file2 = temp_dir2.path().join("file 2.txt");
|
||||
fs::write(&file1, "test1").unwrap();
|
||||
fs::write(&file2, "test2").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir1.path()).arg(temp_dir2.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Both files should be renamed
|
||||
assert!(temp_dir1.path().join("file_1.txt").exists());
|
||||
assert!(temp_dir2.path().join("file_2.txt").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parentheses_removed() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("Document (1).txt");
|
||||
fs::write(&file_path, "test").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// Parentheses should be replaced with underscores
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join("Document_1.txt").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_special_identifiers_preserved() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("C++ Guide.pdf");
|
||||
fs::write(&file_path, "test").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("ntu").unwrap();
|
||||
cmd.arg(temp_dir.path());
|
||||
cmd.assert().success();
|
||||
|
||||
// C++ should be preserved
|
||||
assert!(!file_path.exists());
|
||||
assert!(temp_dir.path().join("C++_Guide.pdf").exists());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue