use std::path::Path;
use std::process::Command;
const RSLEIGH_BIN: &str = env!("CARGO_BIN_EXE_rsleigh");
fn fixture() -> Option<&'static str> {
let p = "target/decomp-bench/pseudocode_core_O0";
if Path::new(p).exists() {
Some(p)
} else {
eprintln!("[skip] bench fixture missing — run scripts/decomp-regress.py");
None
}
}
#[test]
fn struct_accum_keeps_both_arithmetic_writes() {
let Some(fixture) = fixture() else {
return;
};
let out = Command::new(RSLEIGH_BIN)
.args([fixture, "struct_accum"])
.output()
.expect("rsleigh invocation");
assert!(
out.status.success(),
"rsleigh failed:\n{}",
String::from_utf8_lossy(&out.stderr)
);
let text = String::from_utf8(out.stdout).expect("UTF-8");
let plus_lines = text
.lines()
.filter(|l| l.contains("total = total +") || l.contains("total = total + *("))
.count();
let minus_lines = text
.lines()
.filter(|l| l.contains("total = total -") || l.contains("total = total - "))
.count();
assert!(
plus_lines >= 1,
"missing `total = total + ...` add stmt:\n{}",
text
);
assert!(
minus_lines >= 1,
"missing `total = total - ...` subtract stmt — \
cross-line DCE dropped it (pre-fix regression):\n{}",
text
);
}