Skip to main content

outl_exec/runtimes/
echo.rs

1//! `echo` runtime — echoes the block's source back on stdout.
2//!
3//! Purpose: smoke-test the pipeline (UI keybind → orchestrate → result
4//! subblock) without needing a real interpreter. Also useful in
5//! integration tests as a fast, deterministic stand-in.
6//!
7//! Yes, it would let users run their text as-is. But the fence info
8//! string would have to be `echo` deliberately — nobody types
9//! ` ```echo ` by accident.
10
11use std::time::Instant;
12
13use crate::runtime::{ExecContext, ExecError, ExecOutput, ExitStatus, OutputFormat, Runtime};
14
15/// See module docs.
16pub struct EchoRuntime;
17
18impl Runtime for EchoRuntime {
19    fn language(&self) -> &'static str {
20        "echo"
21    }
22
23    fn execute(&self, source: &str, _ctx: &ExecContext) -> Result<ExecOutput, ExecError> {
24        let start = Instant::now();
25        Ok(ExecOutput {
26            stdout: source.to_string(),
27            stderr: String::new(),
28            duration: start.elapsed(),
29            exit: ExitStatus::Ok,
30            format: OutputFormat::Text,
31        })
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn echoes_single_line() {
41        let out = EchoRuntime
42            .execute("hello", &ExecContext::default())
43            .unwrap();
44        assert_eq!(out.stdout, "hello");
45        assert!(matches!(out.exit, ExitStatus::Ok));
46    }
47
48    #[test]
49    fn echoes_multi_line() {
50        let out = EchoRuntime
51            .execute("one\ntwo\nthree", &ExecContext::default())
52            .unwrap();
53        assert_eq!(out.stdout, "one\ntwo\nthree");
54    }
55}