use std::path::Path;
use std::process::Command;
const BED_FIXTURE: &str = "/tmp/bed/bed_v0.2.8_linux_amd64/bed";
const RSLEIGH_BIN: &str = env!("CARGO_BIN_EXE_rsleigh");
fn fixture_available() -> bool {
if Path::new(BED_FIXTURE).exists() {
return true;
}
if std::env::var_os("RSLEIGH_REQUIRE_BED_FIXTURE").is_some() {
panic!("bed fixture missing at {BED_FIXTURE}, RSLEIGH_REQUIRE_BED_FIXTURE set");
}
eprintln!("[skip] bed fixture missing at {BED_FIXTURE}");
false
}
fn run(args: &[&str]) -> String {
let out = Command::new(RSLEIGH_BIN)
.args(args)
.output()
.expect("rsleigh CLI invocation");
assert!(
out.status.success(),
"rsleigh failed:\n{}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8(out.stdout).expect("rsleigh output is UTF-8")
}
#[test]
fn go_preamble_stackguard_variant_0x10_extends_decode_range() {
if !fixture_available() {
return;
}
let out = run(&[BED_FIXTURE, "--disasm", "0x4af120"]);
let nlines = out.lines().count();
assert!(
nlines > 3,
"0x10 variant truncated: {nlines} lines of disasm (expected >3)\n{out}"
);
}
#[test]
fn go_preamble_preempt_variant_0x18_extends_decode_range() {
if !fixture_available() {
return;
}
let out = run(&[BED_FIXTURE, "0x426780"]);
let nlines = out.lines().count();
assert!(
nlines > 10,
"0x18 variant truncated: {nlines} lines of decompile (expected >10)\n{out}"
);
assert!(
!out.contains("// thunk"),
"0x18 variant decoded only the preamble → empty thunk\n{out}"
);
}