Skip to content

Commit

Permalink
Fix do not fail when summarizing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 11, 2023
1 parent eec5c47 commit 25b2990
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async fn main() -> Result<()> {
result
}
Commands::FormatTestReports { reports } => {
summary::print_summary_table(&reports).await?;
summary::print_summary_table(&reports).await;
Ok(())
}
Commands::Update { name } => {
Expand Down
22 changes: 14 additions & 8 deletions test/test-manager/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ pub struct Summary {

impl Summary {
/// Read test summary from `path`.
pub async fn parse_log(path: &Path) -> Result<Summary, Error> {
pub async fn parse_log<P: AsRef<Path>>(path: P) -> Result<Summary, Error> {
let file = fs::OpenOptions::new()
.read(true)
.open(path)
.open(&path)
.await
.map_err(|err| Error::Open(err, path.to_path_buf()))?;
.map_err(|err| Error::Open(err, path.as_ref().to_path_buf()))?;

let mut lines = tokio::io::BufReader::new(file).lines();

Expand Down Expand Up @@ -160,10 +160,18 @@ impl Summary {
}

/// Outputs an HTML table, to stdout, containing the results of the given log files.
pub async fn print_summary_table<P: AsRef<Path>>(summary_files: &[P]) -> Result<(), Error> {
let mut summaries = vec![];
///
/// This is a best effort attempt at summarizing the log files which do
/// exist. If some log file which is expected to exist, but for any reason fails to
/// be parsed, we should not abort the entire summarization.
pub async fn print_summary_table<P: AsRef<Path>>(summary_files: &[P]) {
let mut summaries = Vec::new();
let mut failed_to_parse = Vec::new();
for sumfile in summary_files {
summaries.push(Summary::parse_log(sumfile.as_ref()).await?);
match Summary::parse_log(sumfile).await {
Ok(summary) => summaries.push(summary),
Err(_) => failed_to_parse.push(sumfile),
}
}

// Collect test details
Expand Down Expand Up @@ -274,6 +282,4 @@ pub async fn print_summary_table<P: AsRef<Path>>(summary_files: &[P]) -> Result<
// Print explanation of test result
println!("<p>{} = Test passed</p>", TestResult::PASS_STR);
println!("<p>{} = Test failed</p>", TestResult::FAIL_STR);

Ok(())
}

0 comments on commit 25b2990

Please sign in to comment.