neue Optionen (-r, Installskript) installiert

This commit is contained in:
Dieter Schlüter 2026-02-10 15:38:53 +01:00
commit d78e318d8a
15 changed files with 273 additions and 42 deletions

View file

@ -30,7 +30,7 @@ fn test_dry_run_no_changes() {
fs::write(&file_path, "test content").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("--dry-run").arg(temp_dir.path());
cmd.arg("--dry-run").arg("-r").arg(temp_dir.path());
cmd.assert().success();
// File should still have spaces (not renamed)
@ -45,7 +45,7 @@ fn test_actual_rename() {
fs::write(&file_path, "test content").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// File should be renamed
@ -60,7 +60,7 @@ fn test_hidden_files_preserved() {
fs::write(&file_path, "*.tmp").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Hidden file should not be renamed
@ -74,7 +74,7 @@ fn test_hidden_file_with_spaces() {
fs::write(&file_path, "config content").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Hidden file should be renamed but keep leading dot
@ -89,7 +89,7 @@ fn test_umlaut_conversion() {
fs::write(&file_path, "test").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Umlaut should be converted
@ -104,7 +104,7 @@ fn test_double_extension() {
fs::write(&file_path, "archive").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Should keep .tar.gz intact
@ -123,6 +123,7 @@ fn test_exclude_pattern() {
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("--exclude")
.arg("*.tmp")
.arg("-r")
.arg(temp_dir.path());
cmd.assert().success();
@ -139,7 +140,7 @@ fn test_quiet_mode() {
fs::write(&file_path, "test").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("--quiet").arg(temp_dir.path());
cmd.arg("--quiet").arg("-r").arg(temp_dir.path());
cmd.assert()
.success()
.stdout(predicate::str::is_empty());
@ -155,7 +156,7 @@ fn test_multiple_paths() {
fs::write(&file2, "test2").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir1.path()).arg(temp_dir2.path());
cmd.arg("-r").arg(temp_dir1.path()).arg(temp_dir2.path());
cmd.assert().success();
// Both files should be renamed
@ -170,7 +171,7 @@ fn test_parentheses_removed() {
fs::write(&file_path, "test").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Parentheses should be replaced with underscores
@ -185,10 +186,74 @@ fn test_special_identifiers_preserved() {
fs::write(&file_path, "test").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// C++ should be preserved
assert!(!file_path.exists());
assert!(temp_dir.path().join("C++_Guide.pdf").exists());
}
#[test]
fn test_non_recursive_default() {
let temp_dir = TempDir::new().unwrap();
fs::create_dir(temp_dir.path().join("subdir")).unwrap();
let file1 = temp_dir.path().join("top file.txt");
let file2 = temp_dir.path().join("subdir").join("nested file.txt");
fs::write(&file1, "test1").unwrap();
fs::write(&file2, "test2").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg(temp_dir.path());
cmd.assert().success();
// Top-Level umbenannt
assert!(temp_dir.path().join("top_file.txt").exists());
// Nested NICHT umbenannt (non-recursive)
assert!(file2.exists());
}
#[test]
fn test_recursive_flag() {
let temp_dir = TempDir::new().unwrap();
fs::create_dir(temp_dir.path().join("subdir")).unwrap();
let file1 = temp_dir.path().join("top file.txt");
let file2 = temp_dir.path().join("subdir").join("nested file.txt");
fs::write(&file1, "test1").unwrap();
fs::write(&file2, "test2").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("-r").arg(temp_dir.path());
cmd.assert().success();
// Beide umbenannt
assert!(temp_dir.path().join("top_file.txt").exists());
assert!(temp_dir.path().join("subdir").join("nested_file.txt").exists());
}
#[test]
fn test_conf_option_valid_file() {
let temp_dir = TempDir::new().unwrap();
let config_file = temp_dir.path().join("custom.toml");
fs::write(&config_file, "[replacements]\n\"test\" = \"xyz\"").unwrap();
let file_path = temp_dir.path().join("test_file.txt");
fs::write(&file_path, "content").unwrap();
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("--conf").arg(&config_file).arg(temp_dir.path());
cmd.assert().success();
assert!(temp_dir.path().join("xyz_file.txt").exists());
}
#[test]
fn test_conf_option_missing_file() {
let temp_dir = TempDir::new().unwrap();
let nonexistent = temp_dir.path().join("nonexistent.toml");
let mut cmd = Command::new(cargo_bin!("ntu"));
cmd.arg("--conf").arg(&nonexistent).arg(temp_dir.path());
cmd.assert()
.failure()
.stderr(predicate::str::contains("nicht gefunden"));
}