Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit-test-kind option to allow choosing bin or lib #322

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/bin/cargo-flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use clap::{Args, Parser};

use flamegraph::Workload;

#[derive(Debug, Clone, Copy, clap::ValueEnum)]
#[clap(rename_all = "snake_case")]
enum UnitTestTargetKind {
Bin,
Lib,
}

#[derive(Args, Debug)]
struct Opt {
/// Build with the dev profile
Expand Down Expand Up @@ -42,6 +49,11 @@ struct Opt {
#[clap(long, group = "exec-args")]
unit_test: Option<Option<String>>,

/// Kind of target (lib or bin) when running with <unit-test> which is may be
/// required when we have two targets with the same name.
#[clap(long)]
unit_test_kind: Option<UnitTestTargetKind>,

/// Crate target to unit benchmark, <bench> may be omitted if crate only has one target
/// (currently profiles the test harness and all tests in the binary; test selection
/// can be passed as trailing arguments after `--` as separator)
Expand Down Expand Up @@ -436,8 +448,14 @@ fn main() -> anyhow::Result<()> {
opt.package = Some(target.package);
target.kind
} else if let Some(unit_test) = opt.unit_test {
let kinds = match opt.unit_test_kind {
Some(UnitTestTargetKind::Bin) => &["bin"][..], // get slice to help type inference
Some(UnitTestTargetKind::Lib) => &["lib"],
None => &["bin", "lib"],
};

let target = find_unique_target(
&["bin", "lib"],
kinds,
opt.package.as_deref(),
opt.manifest_path.as_deref(),
unit_test.as_deref(),
Expand Down
Loading