-
Notifications
You must be signed in to change notification settings - Fork 623
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 Stacktrace Substring Matching to Throwable Matchers #3998
base: master
Are you sure you want to change the base?
Conversation
Could you please ensure that the failure message is tested as well? E.g. shouldFail {
Throwable() shouldHaveStackTraceContaining "foobar"
}.message shouldBe """
exact message here
""" |
Also, exceptions spell it as "stackTrace", so IMO we should also capitalize the T. |
Hi @Kantis, thank you for your feedback. I've implemented your suggestions 👍🏻 I noticed that the message with all its stack trace frames can make the test for the message in it's entirety exceptionally lengthy. Considering this, I thought about using a regex to assert on what follows the actual. What are your thoughts on this approach? Do you think it maintains the integrity of the test while addressing the length concern? This is my first time contributing to open source, so any feedback is greatly appreciated! |
Looks good to me. Happy to merge if @Kantis is happy. |
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.
Looks good. I added a small test for the failure messages for the regex matchers as well. Thanks for contributing @neBM 🙌🏼
This PR introduces the ability to match substrings and regular expressions in the stacktrace of a
Throwable
in the Kotest assertions library. This feature can be useful when writing tests that need to assert on specific parts of a stacktrace.Changes:
shouldHaveStacktraceContaining
andshouldNotHaveStacktraceContaining
to theThrowable
class. These functions accept aString
orRegex
and use it to match against the stacktrace of theThrowable
.haveStacktraceContaining
that create aMatcher<Throwable>
to perform the actual matching logic.ThrowableMatchersTest.kt
.This enhancement provides more flexibility when writing tests involving exceptions and their stacktraces.