Add Test number in progress mode

This commit is contained in:
Fabrice Reix 2021-09-01 11:51:10 +02:00
parent 69aec13eb4
commit cf2fd14aea

View File

@ -52,6 +52,12 @@ pub fn init_colored() {
colored::control::set_virtual_terminal(true); colored::control::set_virtual_terminal(true);
} }
#[derive(Clone, Debug, PartialEq, Eq)]
struct Progress {
pub current: usize,
pub total: usize,
}
fn execute( fn execute(
filename: &str, filename: &str,
contents: String, contents: String,
@ -59,6 +65,7 @@ fn execute(
cli_options: CliOptions, cli_options: CliOptions,
log_verbose: &impl Fn(&str), log_verbose: &impl Fn(&str),
log_error_message: &impl Fn(bool, &str), log_error_message: &impl Fn(bool, &str),
progress: Option<Progress>,
) -> HurlResult { ) -> HurlResult {
let lines: Vec<String> = regex::Regex::new(r"\n|\r\n") let lines: Vec<String> = regex::Regex::new(r"\n|\r\n")
.unwrap() .unwrap()
@ -71,8 +78,8 @@ fn execute(
Some(filename.to_string()) Some(filename.to_string())
}; };
if cli_options.progress { if let Some(Progress { current, total }) = progress {
eprintln!("{}: running", filename); eprintln!("{}: running [{}/{}]", filename, current + 1, total);
} }
let log_parser_error = let log_parser_error =
cli::make_logger_parser_error(lines.clone(), cli_options.color, optional_filename.clone()); cli::make_logger_parser_error(lines.clone(), cli_options.color, optional_filename.clone());
@ -254,7 +261,7 @@ fn main() {
}; };
let start = Instant::now(); let start = Instant::now();
for filename in filenames.clone() { for (current, filename) in filenames.iter().enumerate() {
let contents = match cli::read_to_string(filename) { let contents = match cli::read_to_string(filename) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
@ -263,6 +270,14 @@ fn main() {
} }
}; };
let progress = if cli_options.progress {
Some(Progress {
current,
total: filenames.len(),
})
} else {
None
};
let hurl_result = execute( let hurl_result = execute(
filename, filename,
contents, contents,
@ -270,6 +285,7 @@ fn main() {
cli_options.clone(), cli_options.clone(),
&log_verbose, &log_verbose,
&log_error_message, &log_error_message,
progress,
); );
if hurl_result.errors().is_empty() && !cli_options.interactive { if hurl_result.errors().is_empty() && !cli_options.interactive {
@ -323,7 +339,7 @@ fn main() {
cli::log_info("no response has been received"); cli::log_info("no response has been received");
} }
} else { } else {
let source = if filename == "-" { let source = if *filename == "-" {
"".to_string() "".to_string()
} else { } else {
format!("for file {}", filename).to_string() format!("for file {}", filename).to_string()