xtask/commands/
devtools_test.rs

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
use std::error::Error;

use xshell::{cmd, Shell};

use crate::{
    cli::devtools_test::DevtoolsTestArg,
    extendrtests::with_absolute_path::{swap_extendr_api_path, R_FOLDER_PATH},
};

pub(crate) fn run(shell: &Shell, args: DevtoolsTestArg) -> Result<(), Box<dyn Error>> {
    let _document_handle = swap_extendr_api_path(shell)?;

    run_tests(shell, args)?;

    Ok(())
}

fn run_tests(shell: &Shell, args: DevtoolsTestArg) -> Result<(), Box<dyn Error>> {
    let _r_path = shell.push_dir(R_FOLDER_PATH);
    if args.accept_snapshot {
        cmd!(
            shell,
            "Rscript -e testthat::snapshot_accept(\"macro-snapshot\")"
        )
        .run()?;
    }
    if let Some(filter) = args.filter {
        shell
            .cmd("Rscript")
            .arg("-e")
            .arg(format!("devtools::test(filter = \"{filter}\")"))
            .run()?;
    } else {
        cmd!(shell, "Rscript -e devtools::test()").run()?;
    }

    Ok(())
}