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 Criterion::configure_from #771

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -760,8 +761,18 @@ impl<M: Measurement> Criterion<M> {
/// Configure this criterion struct based on the command-line arguments to
/// this process.
#[must_use]
pub fn configure_from_args(self) -> Criterion<M> {
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<M> {
pub fn configure_from<I, T>(mut self, itr: I) -> Criterion<M>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
use clap::{value_parser, Arg, Command};
let matches = Command::new("Criterion Benchmark")
.arg(Arg::new("FILTER")
Expand Down Expand Up @@ -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::<String>("color") {
Expand Down