1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{path::Path, process::Output};

use anyhow::{Context, Error};

use crate::{CommandOutput, FullName, TestContext};

pub(crate) fn rune_output(
    full_name: &FullName,
    directory: &Path,
    ctx: &TestContext,
) -> Result<Output, Error> {
    log::debug!("Compiling");
    let output = crate::compile::rune_output(full_name, directory, ctx)?;

    if !output.status.success() {
        return Err(Error::msg("Unable to compile the Rune")
            .context(CommandOutput::new(output)));
    }

    anyhow::ensure!(output.status.success(), "Unable to compile the Rune");

    let mut cmd = ctx.rune_cmd();

    cmd.arg("run").arg(format!("{}.rune", full_name.name));

    for entry in directory
        .read_dir()
        .context("Unable to read the directory")?
    {
        let entry = entry?;
        let filename = entry.path();
        let extension = match filename.extension().and_then(|ext| ext.to_str())
        {
            Some(ext) => ext,
            None => continue,
        };

        let argument = match extension {
            "png" | "jpg" => "--image",
            "wav" => "--sound",
            "csv" => "--accelerometer",
            "rand" => "--random",
            "bin" => "--raw",
            _ => continue,
        };

        cmd.arg(argument).arg(filename);
    }

    cmd.arg("--engine").arg(&ctx.engine);

    log::debug!("Executing {:?}", cmd);

    cmd.current_dir(directory)
        .output()
        .context("Unable to run `rune`")
}