use std::path::Path;
use std::process::Command;
fn binary() -> std::path::PathBuf {
if let Ok(p) = std::env::var("CARGO_BIN_EXE_markdown-reader") {
return p.into();
}
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("debug")
.join("markdown-reader")
}
#[test]
fn export_html_produces_valid_html_document() {
let sample = Path::new(env!("CARGO_MANIFEST_DIR")).join("sample.md");
assert!(
sample.exists(),
"sample.md not found at {}: integration test requires it",
sample.display()
);
let output = Command::new(binary())
.args(["--export-html", &sample.to_string_lossy()])
.output()
.expect("failed to run markdown-reader binary");
assert!(
output.status.success(),
"binary exited with non-zero status: {}\nstderr: {}",
output.status,
String::from_utf8_lossy(&output.stderr),
);
let html = String::from_utf8(output.stdout).expect("output is not valid UTF-8");
assert!(!html.is_empty(), "expected non-empty HTML output");
assert!(
html.starts_with("<!DOCTYPE html>"),
"output must start with DOCTYPE declaration"
);
assert!(
html.contains("<style>"),
"output must contain an inline <style> block"
);
assert!(
html.contains("</html>"),
"output must be a complete HTML document"
);
assert!(
html.contains("<h1") || html.contains("<h2"),
"expected at least one heading element in output"
);
}