use afterburner::{Afterburner, Language};
fn main() -> Result<(), afterburner::AfterburnerError> {
let ab = Afterburner::new()?;
let js_out = ab.run_source(Language::Js, "console.log('hello from js')")?;
println!(
"[js] ok={} stdout={:?}",
js_out.ok,
js_out.stdout.trim()
);
assert!(
js_out.stdout.contains("hello from js"),
"js stdout: {:?}",
js_out.stdout
);
#[cfg(feature = "wasm")]
{
match ab.run_source(Language::Python, "print('hello from python')") {
Ok(py_out) => {
println!(
"[python] ok={} stdout={:?}",
py_out.ok,
py_out.stdout.trim()
);
}
Err(e) => {
println!("[python] skip - runtime not available: {e}");
}
}
}
#[cfg(not(feature = "wasm"))]
println!("[python] skip - wasm feature not enabled");
#[cfg(feature = "wasm")]
{
match ab.run_source(Language::Ruby, "puts 'hello from ruby'") {
Ok(rb_out) => {
println!(
"[ruby] ok={} stdout={:?}",
rb_out.ok,
rb_out.stdout.trim()
);
}
Err(e) => {
println!("[ruby] skip - runtime not available: {e}");
}
}
}
#[cfg(not(feature = "wasm"))]
println!("[ruby] skip - wasm feature not enabled");
let rust_result = ab.run_source(Language::Rust, "fn main() { println!(\"hi\"); }");
assert!(
rust_result.is_err(),
"Rust run_source must return Err (no source interpreter)"
);
let msg = rust_result.unwrap_err().to_string();
assert!(
msg.contains("register_precompiled"),
"Rust error must mention register_precompiled: {msg}"
);
println!("[rust] correctly rejected: pre-compile required");
Ok(())
}