diff --git a/sdk/cargo-test-bpf/src/main.rs b/sdk/cargo-test-bpf/src/main.rs index 6adfa29cb..bc829d4bb 100644 --- a/sdk/cargo-test-bpf/src/main.rs +++ b/sdk/cargo-test-bpf/src/main.rs @@ -16,6 +16,7 @@ struct Config { cargo_build_bpf: PathBuf, extra_cargo_test_args: Vec, features: Vec, + test_name: Option, no_default_features: bool, offline: bool, verbose: bool, @@ -31,6 +32,7 @@ impl Default for Config { cargo_build_bpf: PathBuf::from("cargo-build-bpf"), extra_cargo_test_args: vec![], features: vec![], + test_name: None, no_default_features: false, offline: false, verbose: false, @@ -106,6 +108,11 @@ fn test_bpf_package( cargo_args.insert(0, "test"); + if let Some(test_name) = &config.test_name { + cargo_args.push("--test"); + cargo_args.push(test_name); + } + // If the program crate declares the "test-bpf" feature, pass it along to the tests so they can // distinguish between `cargo test` and `cargo test-bpf` if set_test_bpf_feature { @@ -191,6 +198,13 @@ fn main() { .takes_value(false) .help("Do not activate the `default` feature"), ) + .arg( + Arg::with_name("test") + .long("test") + .value_name("NAME") + .takes_value(true) + .help("Test only the specified test target"), + ) .arg( Arg::with_name("manifest_path") .long("manifest-path") @@ -243,6 +257,7 @@ fn main() { features: values_t!(matches, "features", String) .ok() .unwrap_or_else(Vec::new), + test_name: value_t!(matches, "test", String).ok(), no_default_features: matches.is_present("no_default_features"), offline: matches.is_present("offline"), verbose: matches.is_present("verbose"),