lux_cli/
test.rs

1use clap::Args;
2use eyre::{OptionExt, Result};
3use lux_lib::{
4    config::Config,
5    operations::{self, TestEnv},
6    project::Project,
7};
8
9#[derive(Args)]
10pub struct Test {
11    /// Extra arguments to pass to the test runner or test script.
12    test_args: Option<Vec<String>>,
13
14    /// Don't isolate the user environment (keep `HOME` and `XDG` environment variables).
15    #[arg(long)]
16    impure: bool,
17
18    /// Ignore the project's lockfile and don't create one.
19    #[arg(long)]
20    no_lock: bool,
21}
22
23pub async fn test(test: Test, config: Config) -> Result<()> {
24    let project = Project::current()?
25        .ok_or_eyre("'lux test' must be run in a project root, with a 'project.rockspec'")?;
26    let test_args = test.test_args.unwrap_or_default();
27    let test_env = if test.impure {
28        TestEnv::Impure
29    } else {
30        TestEnv::Pure
31    };
32    operations::Test::new(project, &config)
33        .args(test_args)
34        .env(test_env)
35        .no_lock(test.no_lock)
36        .run()
37        .await?;
38    Ok(())
39}