use std::path::PathBuf;
use std::process::Command;
fn bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_xpile"))
}
fn fixture() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join("trait_determinism_demo.py")
}
fn run_transpile(target: &str) -> String {
let out = Command::new(bin())
.arg("transpile")
.arg(fixture())
.arg("--target")
.arg(target)
.output()
.expect("spawn xpile transpile");
assert!(
out.status.success(),
"xpile transpile --target {target} failed: {}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8(out.stdout).expect("xpile stdout is utf-8")
}
#[test]
fn transpile_python_to_rust_is_byte_identical_on_repeat() {
let first = run_transpile("rust");
let second = run_transpile("rust");
assert_eq!(
first, second,
"xpile transpile --target rust must be deterministic per \
C-XPILE-FRONTEND-TRAIT + C-XPILE-BACKEND-TRAIT"
);
}
#[test]
fn transpile_python_to_ruchy_is_byte_identical_on_repeat() {
let first = run_transpile("ruchy");
let second = run_transpile("ruchy");
assert_eq!(
first, second,
"xpile transpile --target ruchy must be deterministic per \
C-XPILE-FRONTEND-TRAIT + C-XPILE-BACKEND-TRAIT"
);
}
#[test]
fn transpile_python_to_lean_is_byte_identical_on_repeat() {
let first = run_transpile("lean");
let second = run_transpile("lean");
assert_eq!(
first, second,
"xpile transpile --target lean must be deterministic per \
C-XPILE-FRONTEND-TRAIT + C-XPILE-BACKEND-TRAIT"
);
}
#[test]
fn bashrs_round_trip_is_byte_identical_on_repeat() {
let shell_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join("bashrs_realistic_demo.sh");
let run = |_: ()| {
let out = Command::new(bin())
.arg("transpile")
.arg(&shell_fixture)
.arg("--target")
.arg("shell")
.output()
.expect("spawn xpile transpile");
assert!(
out.status.success(),
"bashrs round-trip failed: {}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8(out.stdout).expect("utf-8 stdout")
};
let first = run(());
let second = run(());
assert_eq!(
first, second,
"xpile transpile foo.sh --target shell must be deterministic \
per C-BASHRS-POSIX-IDEMPOTENCE"
);
}