]> git.proxmox.com Git - cargo.git/commitdiff
Explicitly mention testname argument for cargo test/bench
authorManish Goregaokar <manishsmail@gmail.com>
Thu, 11 Jan 2018 07:26:43 +0000 (12:56 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 11 Jan 2018 09:08:51 +0000 (14:38 +0530)
src/bin/bench.rs
src/bin/test.rs

index eaf4c0d6b86a4f1919ce5aa3740fbb3012836a9f..e00002ebe97f73e1c8db5eaf1ee4801b31096763 100644 (file)
@@ -37,15 +37,18 @@ pub struct Options {
     flag_exclude: Vec<String>,
     #[serde(rename = "flag_Z")]
     flag_z: Vec<String>,
+    #[serde(rename = "arg_BENCHNAME")]
+    arg_benchname: Option<String>,
 }
 
 pub const USAGE: &'static str = "
 Execute all benchmarks of a local package
 
 Usage:
-    cargo bench [options] [--] [<args>...]
+    cargo bench [options] [BENCHNAME] [--] [<args>...]
 
 Options:
+    BENCHNAME                    If specified, only run benches containing this string in their names
     -h, --help                   Print this message
     --lib                        Benchmark only this package's library
     --bin NAME ...               Benchmark only the specified binary
@@ -95,7 +98,7 @@ not affect how many jobs are used when running the benchmarks.
 Compilation can be customized with the `bench` profile in the manifest.
 ";
 
-pub fn execute(options: Options, config: &mut Config) -> CliResult {
+pub fn execute(mut options: Options, config: &mut Config) -> CliResult {
     debug!("executing; cmd=cargo-bench; args={:?}",
            env::args().collect::<Vec<_>>());
 
@@ -139,6 +142,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
         },
     };
 
+    if let Some(test) = options.arg_benchname.take() {
+         options.arg_args.insert(0, test);
+     }
+
     let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
     match err {
         None => Ok(()),
index c4c2bac3daaa2c6f06259b7422b9e6e51ab78873..242f1ebb25cc147eb232be03929325d2bc710fe6 100644 (file)
@@ -39,15 +39,18 @@ pub struct Options {
     flag_exclude: Vec<String>,
     #[serde(rename = "flag_Z")]
     flag_z: Vec<String>,
+    #[serde(rename = "arg_TESTNAME")]
+    arg_testname: Option<String>,
 }
 
 pub const USAGE: &'static str = "
 Execute all unit and integration tests of a local package
 
 Usage:
-    cargo test [options] [--] [<args>...]
+    cargo test [options] [TESTNAME] [--] [<args>...]
 
 Options:
+    TESTNAME                     If specified, only run tests containing this string in their names
     -h, --help                   Print this message
     --lib                        Test only this package's library
     --doc                        Test only this library's documentation
@@ -116,7 +119,7 @@ To get the list of all options available for the test binaries use this:
     cargo test -- --help
 ";
 
-pub fn execute(options: Options, config: &mut Config) -> CliResult {
+pub fn execute(mut options: Options, config: &mut Config) -> CliResult {
     debug!("executing; cmd=cargo-test; args={:?}",
            env::args().collect::<Vec<_>>());
 
@@ -172,6 +175,12 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
         },
     };
 
+    // TESTNAME is actually an argument of the test binary, but it's
+    // important so we explicitly mention it and reconfigure
+    if let Some(test) = options.arg_testname.take() {
+         options.arg_args.insert(0, test);
+     }
+
     let err = ops::run_tests(&ws, &ops, &options.arg_args)?;
     match err {
         None => Ok(()),