use std::fs;
use std::process::Command;
use tempfile::TempDir;
fn seams_bin() -> &'static str {
env!("CARGO_BIN_EXE_seams")
}
#[test]
fn test_cli_accepts_arbitrary_txt_filename() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("my_novel.txt");
fs::write(&file, "Hello world. This is a test. Another sentence here.").unwrap();
let output = Command::new(seams_bin())
.arg(&file)
.current_dir(dir.path())
.output()
.expect("failed to run seams binary");
assert!(
output.status.success(),
"seams should accept any readable .txt file, not only files ending in '-0.txt'.\n\
stderr: {}\nstdout: {}",
String::from_utf8_lossy(&output.stderr),
String::from_utf8_lossy(&output.stdout),
);
}
#[test]
fn test_cli_accepts_hyphenated_name_without_zero() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("pg12345.txt");
fs::write(&file, "Once upon a time. The end.").unwrap();
let output = Command::new(seams_bin())
.arg(&file)
.current_dir(dir.path())
.output()
.expect("failed to run seams binary");
assert!(
output.status.success(),
"seams should process 'pg12345.txt' without requiring the '-0' suffix.\n\
stderr: {}\nstdout: {}",
String::from_utf8_lossy(&output.stderr),
String::from_utf8_lossy(&output.stdout),
);
}
#[test]
fn test_cli_file_mode_stdout_contains_no_json_tracing() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("book-0.txt");
fs::write(&file, "Hello world. This is a test. Another sentence here.").unwrap();
let output = Command::new(seams_bin())
.arg(&file)
.current_dir(dir.path())
.output()
.expect("failed to run seams binary");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("{\"timestamp\""),
"stdout must not contain JSON tracing output.\n\
Structured logs should go to stderr, not stdout.\n\
stdout was:\n{}",
stdout,
);
}
#[test]
fn test_cli_debug_text_stdout_contains_no_json_tracing() {
let output = Command::new(seams_bin())
.args(["--debug-text", "Hello world. This is a test."])
.output()
.expect("failed to run seams binary");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("{\"timestamp\""),
"--debug-text stdout must not contain JSON tracing lines.\n\
Only TSV sentence output should appear on stdout.\n\
stdout was:\n{}",
stdout,
);
}
#[test]
fn test_cli_json_tracing_appears_on_stderr_not_stdout() {
let output = Command::new(seams_bin())
.args(["--debug-text", "Hello world. This is a test."])
.output()
.expect("failed to run seams binary");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("Starting seams"),
"Structured log messages should appear on stderr.\n\
stderr was empty (logs are going to stdout instead).\n\
stderr: {}\nstdout: {}",
stderr,
String::from_utf8_lossy(&output.stdout),
);
}