Skip to content

Commit

Permalink
Improve text summary.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Aug 23, 2022
1 parent 4991df0 commit 651f3bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
10 changes: 5 additions & 5 deletions integration/tests_ok/test.err.pattern
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests_ok/test.hurl: Running [1/1]
tests_ok/test.hurl: Success
tests_ok/test.hurl: Success (1 request(s) in ~~~ ms)
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: ~~~ms
Executed files: 1
Succeeded files: 1 (100.0%)
Failed files: 0 (0.0%)
Duration: ~~~ ms

10 changes: 5 additions & 5 deletions packages/hurl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn execute(
logger,
);
if cli_options.progress {
logger.test_completed(result.success);
logger.test_completed(&result);
}
result
}
Expand Down Expand Up @@ -571,23 +571,23 @@ fn get_summary(duration: u128, hurl_results: &[HurlResult]) -> String {
let mut s =
"--------------------------------------------------------------------------------\n"
.to_string();
s.push_str(format!("Executed: {}\n", total).as_str());
s.push_str(format!("Executed files: {}\n", total).as_str());
s.push_str(
format!(
"Succeeded: {} ({:.1}%)\n",
"Succeeded files: {} ({:.1}%)\n",
success,
100.0 * success as f32 / total as f32
)
.as_str(),
);
s.push_str(
format!(
"Failed: {} ({:.1}%)\n",
"Failed files: {} ({:.1}%)\n",
failed,
100.0 * failed as f32 / total as f32
)
.as_str(),
);
s.push_str(format!("Duration: {}ms\n", duration).as_str());
s.push_str(format!("Duration: {} ms\n", duration).as_str());
s
}
38 changes: 29 additions & 9 deletions packages/hurl/src/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/

use crate::runner::HurlResult;
use colored::*;
use hurl_core::error::Error;

Expand Down Expand Up @@ -90,7 +91,7 @@ pub struct Logger<'a> {
pub header_in: fn(&str, &str),
pub header_out: fn(&str, &str),
pub test_running: fn(&str, usize, usize),
pub test_completed: fn(&str, bool),
pub test_completed: fn(result: &HurlResult),
pub color: bool,
pub verbose: bool,
pub filename: &'a str,
Expand Down Expand Up @@ -220,8 +221,8 @@ impl<'a> Logger<'a> {
(self.test_running)(self.filename, current, total)
}

pub fn test_completed(&self, success: bool) {
(self.test_completed)(self.filename, success)
pub fn test_completed(&self, result: &HurlResult) {
(self.test_completed)(result)
}
}

Expand Down Expand Up @@ -329,18 +330,37 @@ fn log_test_running_no_color(filename: &str, current: usize, total: usize) {
eprintln!("{}: Running [{}/{}]", filename, current, total)
}

fn log_test_completed(filename: &str, success: bool) {
let state = if success {
fn log_test_completed(result: &HurlResult) {
let state = if result.success {
"Success".green().bold()
} else {
"Failure".red().bold()
};
eprintln!("{}: {}", filename.bold(), state)
let count = result
.entries
.iter()
.filter(|r| r.request.is_some())
.count();
eprintln!(
"{}: {} ({} request(s) in {} ms)",
result.filename.bold(),
state,
count,
result.time_in_ms
)
}

fn log_test_completed_no_color(filename: &str, success: bool) {
let state = if success { "Success" } else { "Failure" };
eprintln!("{}: {}", filename, state)
fn log_test_completed_no_color(result: &HurlResult) {
let state = if result.success { "Success" } else { "Failure" };
let count = result
.entries
.iter()
.filter(|r| r.request.is_some())
.count();
eprintln!(
"{}: {} ({} request(s) in {} ms)",
result.filename, state, count, result.time_in_ms
)
}

pub fn error_string_no_color(filename: &str, content: &str, error: &dyn Error) -> String {
Expand Down

0 comments on commit 651f3bd

Please sign in to comment.