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    /// Arguments to pass to the test runner.
12    test_args: Option<Vec<String>>,
13    /// Don't isolate the user environment (keep `HOME` and `XDG` environment variables).
14    #[arg(long)]
15    impure: bool,
16
17    /// Ignore the project's lockfile and don't create one.
18    #[arg(long)]
19    no_lock: bool,
20}
21
22pub async fn test(test: Test, config: Config) -> Result<()> {
23    let project = Project::current()?
24        .ok_or_eyre("'lux test' must be run in a project root, with a 'project.rockspec'")?;
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}