-
Notifications
You must be signed in to change notification settings - Fork 736
[tests/mock_logger] Add substr as Description() for distinction #4074
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4074 +/- ##
=======================================
Coverage 89.50% 89.50%
=======================================
Files 259 259
Lines 14740 14740
=======================================
Hits 13193 13193
Misses 1547 1547 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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, but the sentence looks a little strange. Could do Description(fmt::format("log with {}", substr)) or maybe just use operator << ?
Hmm, EXPECT_CALL does not seem to implement "operator <<". I agree that we could use a nicer message, though. How about sth like: |
|
Hmm, it's |
The main problem comes from the assumed placement of the description. It's right between the [actual] and [expected], and whatever we write into the description will be associated with the actual part as a cognitive default. Given that we don't have an easy way to manipulate this ordering, let's ditch the function name altogether then. How about: |
|
There is maybe something I am missing, but why don't you say this?
IOW, the actual call count for function |
I suppose so. There's a slight disconnect between what we actually write in unit tests (expect_log) vs. what's actually being logged (log), but ok. I could live with that. |
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 makes sense to me, thanks!
Regarding the disconnect you mention, perhaps I haven't been sleeping enough and I may be short-circuiting, but expect_log is what the unit tests call to set a call-count expectation on log... That is what the message is saying doesn't match. If anything, it's EXPECT_CALL that could be replaced with expect_log (not necessary).
Yeah, log() is hidden behind the expect_log() call, so what I'm saying is it might be slightly harder to correlate the output with the actual unit test case, but that's not that important. I'd take any single clue that would lead to the correct expect_log() line when something goes wrong, so I don't have any strong preference on that. Regarding the EXPECT_CALL part: unfortunately we can't easily touch the EXPECT_CALL part of the description. I agree that it would look much cleaner, but IMO it's not worth the effort. |
|
|
Hey @xmkg to keep the web a little simpler, we normally avoid merging the target branch back into the topic branch and rebase instead (except if there are many commits with conflicts). Would you mind doing that here, please? |
Right now, it's hard to tell which expect_log call is failed to
be satisfied because the output is ambiguous:
error: Actual function call count doesn't match EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr)))...
Expected: to be called once
Actual: never called - unsatisfied and active
The patch fixes that by utilizing the matcher description:
error: Actual function "my expected log string" call count doesn't match EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr)))...
Expected: to be called once
Actual: never called - unsatisfied and active
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
9bdb3c5 to
e8e9756
Compare
Done |
|
Thank you! |
|
@georgeliao, can I get a secondary review when you're available? The changes are trivial. |
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.
+1 from me
Thanks Scott! |
Right now, it's hard to tell which expect_log call is failed to be satisfied because the output is ambiguous:
The patch fixes that by utilizing the matcher description: