Skip to main content

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()?.ok_or_eyre("'lx test' must be run in a Lux project root.")?;
25    let test_args = test.test_args.unwrap_or_default();
26    let test_env = if test.impure {
27        TestEnv::Impure
28    } else {
29        TestEnv::Pure
30    };
31    operations::Test::new(project, &config)
32        .args(test_args)
33        .env(test_env)
34        .no_lock(test.no_lock)
35        .run()
36        .await?;
37    Ok(())
38}