-
Notifications
You must be signed in to change notification settings - Fork 2.3k
♻️ Add --summary flag to print test summary table
#5961
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fd60738
feat: test summary table
PraneshASP 0f85877
chore: update comment format
PraneshASP f3447e9
refactor: add test summary reporter struct
PraneshASP d0bcd66
chore: remove old code
PraneshASP 128d4a8
refactor: add is_detailed option to struct
PraneshASP 10779ce
chore: add help_heading
PraneshASP d25e719
feat: add conditional coloring to cells
PraneshASP 02a8c4a
feat: sort based on test suite name
PraneshASP 445682f
Merge branch 'master' into feat/test-summary
PraneshASP 3428bb1
chore: fix fmt and clippy warns
PraneshASP eea945a
pull latest changes
PraneshASP 3952c74
chore: fmt
PraneshASP b6f5ee7
chore: update column name
PraneshASP f45b2ec
some touchups
mattsse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| use crate::cmd::test::TestOutcome; | ||
| use comfy_table::{ | ||
| modifiers::UTF8_ROUND_CORNERS, Attribute, Cell, CellAlignment, Color, Row, Table, | ||
| }; | ||
|
|
||
| /// A simple summary reporter that prints the test results in a table. | ||
| pub struct TestSummaryReporter { | ||
| /// The test summary table. | ||
| pub(crate) table: Table, | ||
| pub(crate) is_detailed: bool, | ||
| } | ||
|
|
||
| impl TestSummaryReporter { | ||
| pub(crate) fn new(is_detailed: bool) -> Self { | ||
| let mut table = Table::new(); | ||
| table.apply_modifier(UTF8_ROUND_CORNERS); | ||
| let mut row = Row::from(vec![ | ||
| Cell::new("Test Suite") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold), | ||
| Cell::new("Passed") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold) | ||
| .fg(Color::Green), | ||
| Cell::new("Failed") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold) | ||
| .fg(Color::Red), | ||
| Cell::new("Skipped") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold) | ||
| .fg(Color::Yellow), | ||
| ]); | ||
| if is_detailed { | ||
| row.add_cell( | ||
| Cell::new("File Path") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold), | ||
| ); | ||
| row.add_cell( | ||
| Cell::new("Duration") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold), | ||
| ); | ||
| } | ||
| table.set_header(row); | ||
|
|
||
| Self { table, is_detailed } | ||
| } | ||
|
|
||
| pub(crate) fn print_summary(&mut self, mut test_results: Vec<TestOutcome>) { | ||
| // Sort by suite name first | ||
|
|
||
| // Using `sort_by_cached_key` so that the key extraction logic runs only once | ||
| test_results.sort_by_cached_key(|test_outcome| { | ||
| test_outcome | ||
| .results | ||
| .keys() | ||
| .next() | ||
| .and_then(|suite| suite.split(':').nth(1)) | ||
| .unwrap() | ||
| .to_string() | ||
| }); | ||
|
|
||
| // Traverse the test_results vector and build the table | ||
| for suite in &test_results { | ||
| for contract in suite.results.keys() { | ||
| let mut row = Row::new(); | ||
| let suite_name = contract.split(':').nth(1).unwrap(); | ||
| let suite_path = contract.split(':').nth(0).unwrap(); | ||
|
|
||
| let passed = suite.successes().count(); | ||
| let mut passed_cell = Cell::new(passed).set_alignment(CellAlignment::Center); | ||
|
|
||
| let failed = suite.failures().count(); | ||
| let mut failed_cell = Cell::new(failed).set_alignment(CellAlignment::Center); | ||
|
|
||
| let skipped = suite.skips().count(); | ||
| let mut skipped_cell = Cell::new(skipped).set_alignment(CellAlignment::Center); | ||
|
|
||
| let duration = suite.duration(); | ||
|
|
||
| row.add_cell(Cell::new(suite_name)); | ||
|
|
||
| if passed > 0 { | ||
| passed_cell = passed_cell.fg(Color::Green); | ||
| } | ||
| row.add_cell(passed_cell); | ||
|
|
||
| if failed > 0 { | ||
| failed_cell = failed_cell.fg(Color::Red); | ||
| } | ||
| row.add_cell(failed_cell); | ||
|
|
||
| if skipped > 0 { | ||
| skipped_cell = skipped_cell.fg(Color::Yellow); | ||
| } | ||
| row.add_cell(skipped_cell); | ||
|
|
||
| if self.is_detailed { | ||
| row.add_cell(Cell::new(suite_path)); | ||
| row.add_cell(Cell::new(format!("{:.2?}", duration).to_string())); | ||
| } | ||
|
|
||
| self.table.add_row(row); | ||
| } | ||
| } | ||
| // Print the summary table | ||
| println!("\n{}", self.table); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering, can we move all the work for building and displaying the table to this
ifas it's only necessary if it's actually going to be displayed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require storing all the test suite name and results to a separate object inside the loop and then later read inside the if block? I wanted to avoid adding new variable/storage.
We have to do the same to display the contract names in sorted order as well I guess. What do you guys think? Do you suggest storing the test results? @mds1 @Evalir @mattsse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think in the end if we have to sort the contracts we have to do it—so feel free to go ahead!