use xshell::Shell;
use crate::environment::{get_workspace_packages, OutputMode, ProgressGuard};
use crate::lock::LockFile;
use crate::toolchain::{prepare_toolchain, Toolchain};
pub fn run(
sh: &Shell,
lockfile: LockFile,
packages: &[String],
) -> Result<(), Box<dyn std::error::Error>> {
let packages = get_workspace_packages(sh, packages)?;
let _lockfile_guard = lockfile.activate(sh)?;
let _progress = ProgressGuard::new();
prepare_toolchain(sh, Toolchain::Nightly)?;
rbmt_eprintln!("Running bench tests for {} crates", packages.len());
for package in packages {
rbmt_eprintln!("Running bench tests in: {}", package.dir.display());
let _dir = sh.push_dir(&package.dir);
let output =
rbmt_cmd!(sh, "cargo --locked bench").env("RUSTFLAGS", "--cfg=bench").read()?;
if matches!(OutputMode::from_env(), OutputMode::Verbose) {
println!("{}", output);
}
}
rbmt_eprintln!("Benches complete.");
Ok(())
}