mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-11 05:35:53 +03:00
Add summary option
This commit is contained in:
parent
a6fd634191
commit
8e8d3fad09
@ -260,6 +260,10 @@ Ignore the remaining of the file. It is useful for debugging a session.
|
||||
Write output to <file> instead of stdout.
|
||||
|
||||
|
||||
### --summary {#summary}
|
||||
|
||||
Print test metrics at the end of the run
|
||||
|
||||
|
||||
### -x, --proxy [protocol://]host[:port] {#proxy}
|
||||
|
||||
|
@ -47,6 +47,7 @@ pub struct CliOptions {
|
||||
pub no_proxy: Option<String>,
|
||||
pub output: Option<String>,
|
||||
pub proxy: Option<String>,
|
||||
pub summary: bool,
|
||||
pub timeout: Duration,
|
||||
pub to_entry: Option<usize>,
|
||||
pub user: Option<String>,
|
||||
@ -195,6 +196,11 @@ pub fn app() -> clap::App<'static, 'static> {
|
||||
.value_name("[PROTOCOL://]HOST[:PORT]")
|
||||
.help("Use proxy on given protocol/host/port"),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::with_name("summary")
|
||||
.long("summary")
|
||||
.help("Print test metrics at the end of the run"),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::with_name("to_entry")
|
||||
.long("to-entry")
|
||||
@ -303,6 +309,7 @@ pub fn parse_options(matches: ArgMatches) -> Result<CliOptions, CliError> {
|
||||
let no_proxy = matches.value_of("proxy").map(|x| x.to_string());
|
||||
let output = matches.value_of("output").map(|x| x.to_string());
|
||||
let proxy = matches.value_of("proxy").map(|x| x.to_string());
|
||||
let summary = matches.is_present("summary");
|
||||
let timeout = match matches.value_of("max_time") {
|
||||
None => ClientOptions::default().timeout,
|
||||
Some(s) => match s.parse::<u64>() {
|
||||
@ -343,6 +350,7 @@ pub fn parse_options(matches: ArgMatches) -> Result<CliOptions, CliError> {
|
||||
no_proxy,
|
||||
output,
|
||||
proxy,
|
||||
summary,
|
||||
timeout,
|
||||
to_entry,
|
||||
user,
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::io::prelude::*;
|
||||
use std::io::{self};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
|
||||
use atty::Stream;
|
||||
|
||||
@ -238,6 +239,7 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let start = Instant::now();
|
||||
for filename in filenames.clone() {
|
||||
let contents = match cli::read_to_string(filename) {
|
||||
Ok(v) => v,
|
||||
@ -321,6 +323,7 @@ fn main() {
|
||||
|
||||
hurl_results.push(hurl_result.clone());
|
||||
}
|
||||
let duration = start.elapsed().as_millis();
|
||||
|
||||
if let Some(file_path) = cli_options.json_file {
|
||||
log_verbose(format!("Writing json report to {}", file_path.display()).as_str());
|
||||
@ -350,6 +353,10 @@ fn main() {
|
||||
);
|
||||
}
|
||||
|
||||
if cli_options.summary {
|
||||
print_summary(duration, hurl_results.clone())
|
||||
}
|
||||
|
||||
std::process::exit(exit_code(hurl_results));
|
||||
}
|
||||
|
||||
@ -480,3 +487,22 @@ fn write_cookies_file(file_path: PathBuf, hurl_results: Vec<HurlResult>) -> Resu
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_summary(duration: u128, hurl_results: Vec<HurlResult>) {
|
||||
let total = hurl_results.len();
|
||||
let success = hurl_results.iter().filter(|r| r.success).count();
|
||||
let failed = total - success;
|
||||
eprintln!("--------------------------------------------------------------------------------");
|
||||
eprintln!("executed: {}", total);
|
||||
eprintln!(
|
||||
"success: {} ({:.1}%)",
|
||||
success,
|
||||
100.0 * success as f32 / total as f32
|
||||
);
|
||||
eprintln!(
|
||||
"failed: {} ({:.1}%)",
|
||||
failed,
|
||||
100.0 * failed as f32 / total as f32
|
||||
);
|
||||
eprintln!("execution time: {}ms", duration);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user