use std::process::Command;
#[derive(Debug)]
pub struct OracleResult {
pub shell: String,
pub status: i32,
pub stdout: String,
pub stderr: String,
}
pub fn run_oracle(script: &str, shell: &str) -> Option<OracleResult> {
if std::env::var("WASMSH_ORACLE").is_err() {
return None;
}
let output = Command::new(shell).arg("-c").arg(script).output().ok()?;
Some(OracleResult {
shell: shell.to_string(),
status: output.status.code().unwrap_or(-1),
stdout: String::from_utf8_lossy(&output.stdout).to_string(),
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
})
}
pub fn compare_oracle(
wasmsh_status: i32,
wasmsh_stdout: &str,
oracle: &OracleResult,
ignore_stderr: bool,
) -> Vec<String> {
let mut diffs = Vec::new();
if wasmsh_status != oracle.status {
diffs.push(format!(
"[{}] status: wasmsh={}, oracle={}",
oracle.shell, wasmsh_status, oracle.status
));
}
if wasmsh_stdout != oracle.stdout {
diffs.push(format!(
"[{}] stdout differs:\n wasmsh: {:?}\n oracle: {:?}",
oracle.shell, wasmsh_stdout, oracle.stdout
));
}
if !ignore_stderr {
}
diffs
}