openrunner-rs 1.0.0

A Rust library for running OpenScript
Documentation
use openrunner_rs::{run_file, ScriptOptions};
use serial_test::serial;
use std::io::Write;

#[tokio::test]
#[serial]
async fn test_simple_run() {
    let options = ScriptOptions::new().openscript_path("/bin/sh");
    let result = openrunner_rs::run("echo 'hello'", options).await.unwrap();
    assert!(result.stdout.contains("hello"));
    assert_eq!(result.exit_code, 0);
}

#[tokio::test]
#[serial]
async fn test_with_args() {
    let options = ScriptOptions::new()
        .openscript_path("/bin/sh")
        .args(vec!["foo".to_string(), "bar".to_string()]);
    let result = openrunner_rs::run("echo $1 $2", options).await.unwrap();
    assert!(result.stdout.contains("foo bar"));
}

#[tokio::test]
#[serial]
async fn test_timeout() {
    let options = ScriptOptions::new()
        .openscript_path("/bin/sh")
        .timeout(std::time::Duration::from_secs(1));
    let result = openrunner_rs::run("sleep 5", options).await.unwrap();
    assert!(result.timed_out);
    assert_eq!(result.exit_code, -1);
}

#[tokio::test]
#[serial]
async fn test_spawn_and_wait() {
    let options = ScriptOptions::new().openscript_path("/bin/sh");
    let spawn_result = openrunner_rs::spawn("echo 'spawned'", options)
        .await
        .unwrap();
    let output = spawn_result.child.wait_with_output().await.unwrap();
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("spawned"));
}

#[tokio::test]
#[serial]
async fn test_run_file() {
    let mut file = tempfile::NamedTempFile::new().unwrap();
    writeln!(file, "echo 'file test'").unwrap();
    let path = file.path().to_path_buf();
    let options = ScriptOptions::new().openscript_path("/bin/sh");
    let result = run_file(&path, options).await.unwrap();
    assert!(result.stdout.contains("file test"));
}