From d2d2bfeb16a0660c179fbfdd9a53d7a90790bdab Mon Sep 17 00:00:00 2001 From: "Remy D. Farley" Date: Sun, 7 Apr 2024 12:55:07 +0000 Subject: [PATCH] Add `Criterion::configure_from` --- src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e3f70f49..fc1c2fe3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,6 +72,7 @@ mod stats; use std::cell::RefCell; use std::collections::HashSet; use std::env; +use std::ffi::OsString; use std::io::{stdout, IsTerminal}; use std::net::TcpStream; use std::path::{Path, PathBuf}; @@ -760,8 +761,18 @@ impl Criterion { /// Configure this criterion struct based on the command-line arguments to /// this process. #[must_use] + pub fn configure_from_args(self) -> Criterion { + self.configure_from(env::args_os()) + } + + /// Configure this criterion struct based on the provided command-line arguments. + #[must_use] #[allow(clippy::cognitive_complexity)] - pub fn configure_from_args(mut self) -> Criterion { + pub fn configure_from(mut self, itr: I) -> Criterion + where + I: IntoIterator, + T: Into + Clone, + { use clap::{value_parser, Arg, Command}; let matches = Command::new("Criterion Benchmark") .arg(Arg::new("FILTER") @@ -923,7 +934,7 @@ To test that the benchmarks work, run `cargo test --benches` NOTE: If you see an 'unrecognized option' error using any of the options above, see: https://bheisler.github.io/criterion.rs/book/faq.html ") - .get_matches(); + .get_matches_from(itr); if self.connection.is_some() { if let Some(color) = matches.get_one::("color") {