use assert_cmd::{cargo_bin, Command};
use predicates::prelude::*;
use proptest::prelude::*;
use proptest::test_runner::Config as ProptestConfig;
use std::fs;
use tempfile::TempDir;
proptest! {
#![proptest_config(ProptestConfig::with_cases(10))] #[test]
fn test_error_stream_separation(
search_text in "[a-zA-Z0-9]{1,20}", invalid_path in "[a-zA-Z0-9/]{5,30}",
) {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("")
.assert()
.failure()
.stderr(predicate::str::contains("empty"))
.stdout(predicate::str::is_empty());
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg(" ")
.assert()
.failure()
.stderr(predicate::str::contains("empty"))
.stdout(predicate::str::is_empty());
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg(&search_text)
.arg(format!("/nonexistent/{}", invalid_path))
.assert()
.success() .stdout(predicate::str::contains("No matches found"))
.stderr(predicate::str::is_empty());
let temp_dir = TempDir::new().unwrap();
let yaml_path = temp_dir.path().join("locales");
fs::create_dir_all(&yaml_path).unwrap();
fs::write(yaml_path.join("bad.yml"), "key: [unclosed bracket").unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg(&search_text)
.arg("--verbose")
.current_dir(temp_dir.path())
.assert()
.success();
}
}
#[test]
fn test_cache_errors_go_to_stderr() {
let mut cmd = Command::new(cargo_bin!("cs"));
let result = cmd.arg("--clear-cache").assert();
if !result.get_output().status.success() {
result.stderr(predicate::str::is_empty().not());
} else {
result.stdout(predicate::str::contains("Cache cleared successfully"));
}
}
#[test]
fn test_successful_operations_use_stdout() {
let temp_dir = TempDir::new().unwrap();
fs::write(temp_dir.path().join("test.txt"), "hello world").unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("hello")
.current_dir(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::is_empty().not()) .stderr(predicate::str::is_empty()); }
#[test]
fn test_no_matches_message_goes_to_stdout() {
let temp_dir = TempDir::new().unwrap();
fs::write(temp_dir.path().join("test.txt"), "foo bar baz").unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("nonexistent")
.current_dir(temp_dir.path())
.assert()
.success() .stdout(predicate::str::contains("No matches found"))
.stderr(predicate::str::is_empty()); }
#[test]
fn test_simple_format_errors_go_to_stderr() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("")
.arg("--simple")
.assert()
.failure()
.stderr(predicate::str::contains("empty"))
.stdout(predicate::str::is_empty());
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg(" ")
.arg("--simple")
.assert()
.failure()
.stderr(predicate::str::contains("empty"))
.stdout(predicate::str::is_empty());
}