1use std::process::Command;
7
8#[derive(Debug)]
10pub struct OracleResult {
11 pub shell: String,
12 pub status: i32,
13 pub stdout: String,
14 pub stderr: String,
15}
16
17pub fn run_oracle(script: &str, shell: &str) -> Option<OracleResult> {
20 if std::env::var("WASMSH_ORACLE").is_err() {
21 return None;
22 }
23
24 let output = Command::new(shell).arg("-c").arg(script).output().ok()?;
25
26 Some(OracleResult {
27 shell: shell.to_string(),
28 status: output.status.code().unwrap_or(-1),
29 stdout: String::from_utf8_lossy(&output.stdout).to_string(),
30 stderr: String::from_utf8_lossy(&output.stderr).to_string(),
31 })
32}
33
34pub fn compare_oracle(
36 wasmsh_status: i32,
37 wasmsh_stdout: &str,
38 oracle: &OracleResult,
39 ignore_stderr: bool,
40) -> Vec<String> {
41 let mut diffs = Vec::new();
42
43 if wasmsh_status != oracle.status {
44 diffs.push(format!(
45 "[{}] status: wasmsh={}, oracle={}",
46 oracle.shell, wasmsh_status, oracle.status
47 ));
48 }
49
50 if wasmsh_stdout != oracle.stdout {
51 diffs.push(format!(
52 "[{}] stdout differs:\n wasmsh: {:?}\n oracle: {:?}",
53 oracle.shell, wasmsh_stdout, oracle.stdout
54 ));
55 }
56
57 if !ignore_stderr {
58 }
60
61 diffs
62}