WIP: test: Assert log warnings and errors - #8457
Draft
j-g00da wants to merge 1 commit into
Draft
Conversation
j-g00da
commented
Jul 24, 2026
| .unwrap() | ||
| .unwrap(); | ||
|
|
||
| t.log_sink.assert_warn("No from in message"); |
Contributor
Author
There was a problem hiding this comment.
Usage example, all logged errors and warnings will cause tests to fail unless we explicitly assert (maybe this should be renamed to expect) that error/warn should be logged.
I will probably expose these methods directly in TestContext and TestContextManager instead of exposing log_sink.
Collaborator
|
After talking to @link2xt, we found some simplifications that are possible, and one bugfix that is needed:
|
j-g00da
force-pushed
the
j-g00da/log_asserts
branch
4 times, most recently
from
July 30, 2026 12:24
8249945 to
2d7664d
Compare
j-g00da
commented
Jul 30, 2026
Comment on lines
+1364
to
+1389
| #[derive(Debug, Copy, Clone, PartialEq)] | ||
| pub enum LogAssertType { | ||
| Warn, | ||
| Error, | ||
| } | ||
|
|
||
| impl Display for LogAssertType { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| let str = match self { | ||
| Self::Warn => "a warning".to_string(), | ||
| Self::Error => "an error".to_string(), | ||
| }; | ||
| write!(f, "{}", str) | ||
| } | ||
| } | ||
|
|
||
| impl Not for LogAssertType { | ||
| type Output = Self; | ||
|
|
||
| fn not(self) -> Self::Output { | ||
| match self { | ||
| LogAssertType::Warn => LogAssertType::Error, | ||
| LogAssertType::Error => LogAssertType::Warn, | ||
| } | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
(I guess it's just bloat, will change it back to "is_error" bool later.)
Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
j-g00da
force-pushed
the
j-g00da/log_asserts
branch
from
July 31, 2026 19:29
2d7664d to
afff615
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.