Skip to main content

lux_cli/
test.rs

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