xtask/commands/
devtools_test.rs
1use std::error::Error;
2
3use xshell::{cmd, Shell};
4
5use crate::{
6 cli::devtools_test::DevtoolsTestArg,
7 extendrtests::with_absolute_path::{swap_extendr_api_path, R_FOLDER_PATH},
8};
9
10pub(crate) fn run(shell: &Shell, args: DevtoolsTestArg) -> Result<(), Box<dyn Error>> {
11 let _document_handle = swap_extendr_api_path(shell)?;
12
13 run_tests(shell, args)?;
14
15 Ok(())
16}
17
18fn run_tests(shell: &Shell, args: DevtoolsTestArg) -> Result<(), Box<dyn Error>> {
19 let _r_path = shell.push_dir(R_FOLDER_PATH);
20 if args.accept_snapshot {
21 cmd!(
22 shell,
23 "Rscript -e testthat::snapshot_accept(\"macro-snapshot\")"
24 )
25 .run()?;
26 }
27 if let Some(filter) = args.filter {
28 shell
29 .cmd("Rscript")
30 .arg("-e")
31 .arg(format!("devtools::test(filter = \"{filter}\")"))
32 .run()?;
33 } else {
34 cmd!(shell, "Rscript -e devtools::test()").run()?;
35 }
36
37 Ok(())
38}