-
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
Conversation
Evalir
left a comment
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.
| format_aggregated_summary(num_test_suites, total_passed, total_failed, total_skipped) | ||
| ); | ||
|
|
||
| if summary { |
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 if as 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!
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.
I think this is a reasonable addition, and because this is opt-in, I don't see why we shouldn't include it.
pending nits
also I think we should sort the contracts by name
crates/forge/bin/cmd/test/mod.rs
Outdated
| Cell::new("Failed") | ||
| .set_alignment(CellAlignment::Center) | ||
| .add_attribute(Attribute::Bold) | ||
| .fg(Color::Red), |
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.
I know we already showed red, but I'd avoid showing any red unless we actually have a failure. If there is a failure, the header name can be red, and the cells where there were failures, but the rest should be the default color
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.
Good idea. Should we do the same for all 3 columns or only for failures?
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.
Hmm good question. What do other frameworks do? I don't want to overcomplicate it, mainly just don't like that we currently always show red—it looks bad at a glance since everyone associates red=bad
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.
imo, I think we could go for something simple: Unless the number is 0, show the corresponding color. I htink this works well because:
- If it's 0, no need to look at it.
- Ideally all your passed suites should look green :)
- If you have failed or skipped tests, you probably want something to grab your attention so you can double check or at least acknowledge it.
crates/forge/bin/cmd/test/mod.rs
Outdated
| fn create_test_summary_table_header(summary_table: &mut Table) -> Row { | ||
| summary_table.apply_modifier(UTF8_ROUND_CORNERS); | ||
| Row::from(vec

Motivation
For projects with large number of testcases, the current output format is not friendly enough to quickly glance through the test suites. Scrolling through the output in the terminal is not quite user-friendly especially if the output is huge. It would be nice to have the test command to accept a flag and print the tests summary in a tabular format.
Solution
This pull request introduces a
--summaryflag for the test command. When this flag is passed, the test runner will output a summary of test results in a neatly formatted table. This tabular format will include columns for the test suite name, number of tests passed, failed, and skipped.Example:
forge test --summarySample Output (Seaport codebase):
This can be further developed into something as sophisticated as hardhat-gas-report table in the future if required.