-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add new command-line option to specify a threshold for test duration printing #1910
Add new command-line option to specify a threshold for test duration printing #1910
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1910 +/- ##
==========================================
+ Coverage 88.61% 88.74% +0.13%
==========================================
Files 138 138
Lines 5627 5629 +2
==========================================
+ Hits 4986 4995 +9
+ Misses 641 634 -7 |
6533c60
to
33d1568
Compare
@@ -52,6 +52,7 @@ namespace Catch { | |||
Verbosity verbosity = Verbosity::Normal; | |||
WarnAbout::What warnings = WarnAbout::Nothing; | |||
ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; | |||
double minDuration = -1; |
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 having 0.
mean "turned off" is fine here. If an user wants all durations to be shown, they can set up showDurations::Always
.
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'm always leery of using a value that might possibly have been intended as valid for a sentinel value. You never know when there might be extra layers between the user and the value (e.g. a GUI or a wrapper script) which makes it less easy to pass other arguments.
I think For testing, I would suggest adding a hidden test non-approval test that sleeps for, say, 100 ms, and another that sleeps for 500 ms and then check that they are (not) reported as appropriate... All in all the changes look reasonable, but I'll definitely need one more look later. |
Some extra thoughts on combining
|
To verify I've understood you: by "hidden" do you mean "marked |
In |
33d1568
to
08af3e6
Compare
My instinct is not to prevent it. You might e.g. be calling the test runner through a wrapper script that uses |
Yes.
And yes. You will also need [approvals] to prevent them from being run during approvals. |
A test runner already has a --durations option to print durations. However, this isn't entirely satisfactory. When there are many tests, this produces output spam which makes it hard to find the test failure output. Nevertheless, it is helpful to be informed of tests which are unusually slow. Therefore, introduce a new option --min-duration that causes all durations above a certain threshold to be printed. This allows slow tests to be visible without mentioning every test.
08af3e6
to
336e27c
Compare
I have refactored and updated the tests as suggested. Over to you. |
There are some things I am still not quite happy with, but it will be fastest if I merge the PR as is and fix it later. |
Would it be possible to group the output according to the test case and tag? |
@nandanvasudevan Everything is possible with a custom reporter. 🤷 |
Description
A test runner already has a --durations option to print durations. However, this isn't entirely satisfactory.
When there are many tests, this produces output spam which makes it hard to find the test failure output. Nevertheless, it is helpful to be informed of tests which are unusually slow.
Therefore, introduce a new option --min-duration that causes all durations above a certain threshold to be printed. This allows slow tests to be visible without mentioning every test.
In our CI we're currently emulating this with some ugly grep on the output, but this is a bit limited, and harder to use when running the tests outside of CI.
I've made a bunch of choices in this implementation that could have gone differently:
--min-duration
is independent of--durations
. Specifying either will cause things to be printed. I could have rolled them into a single option that takes either a string or numeric argument, or made--min-duration
do nothing if--durations
was not also given.IConfig::shouldShowDuration
a member function. It could have been a free function, but I wouldn't know where to put it.--min-duration
only affects the console and compact reporters, not e.g. the XML reporter, because I figured output spam is not an issue there.SelfTest
is so fast that it is printed as0.000 s
. So for now the test just verifies that no durations are printed if a minimum of 1s is specified. But it's written in such a way that it should do something more interesting if slower tests are ever added.