-
Notifications
You must be signed in to change notification settings - Fork 642
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
Improves Failures implementation #465
Improves Failures implementation #465
Conversation
As it was, the Failures class would fail to filter classes that are neither from `sun.reflect.*` nor from `java.*`. This commit aims to create a generic implementation that correctly filters stacktraces. The implemented behavior observes a pattern to clean the stacktrace: - There may be elements that are not from Kotlintest and are not from User Classes, such as Reflection elements or Java elements (but may be others). These elements are removed. - Then the code tries to find elements that are indeed from Kotlintest, such as runners and other internals - After this, it's expected for user classes to be in the stacktrace, so the algorithm stops and returns the stacktrace By observation of the FailuresTest class, one may believe that only classes from `io.kotlintest` and `sun.reflect` would be in the way of user classes, but that's not the case, and this commit fixes it.
@ajalt |
Some context here - the reason for my change overnight was because when you have threads > 1, we execute these on a thread pool, and if threads == 1 we execute in the main thread. So the stack trace can vary. It won't always be the case that the "last" io.kotlintest stack element is directly before the user's own code. |
That's correct. |
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.
Do you have examples of stacktraces that were being filtered incorrectly before? We should add tests for them.
kotlintest-assertions/src/main/kotlin/io/kotlintest/Failures.kt
Outdated
Show resolved
Hide resolved
@ajalt
With the fix the stacktrace is correct |
… of val Users may want to change this property dynamically, at runtime, for whichever reason. Changing it to a `var` won't impact anything else, so it's good to give users this freedom.
@Kerooker @ajalt Why would it be a var ? It's detected from the system properties so is still settable. If so, this is better off being part of ProjectConfig which contains all the other "settings" that uses can override ? |
From what @ajalt said, I expected users to use |
Having the programmatic version is useful, but I think it should be controlled from |
We had the same discussion when I implemented this. Quoting from that PR:
|
Makes sense to me to keep them separated. But my concern is another one: Why is this customizable? Do we have any use for displaying Kotlintest internal stacktraces ever? I mean as an user. As a KT developer it may be interesting, but as an user I don't see use for this. What do you guys think? |
Kotlintest is generally a very customizable framework. There isn't any cost to allowing this functionality to be configured, so why not? I'm sure that someone will want to turn off the magic at some point to help them debug. |
Yes of course. Sorry I've blinked since we had that convo 😨 |
Agreed. Val back to a var and I think we're good. |
Alright. Can we merge this then? |
I'm happy. |
* Improves Failures implementation As it was, the Failures class would fail to filter classes that are neither from `sun.reflect.*` nor from `java.*`. This commit aims to create a generic implementation that correctly filters stacktraces. The implemented behavior observes a pattern to clean the stacktrace: - There may be elements that are not from Kotlintest and are not from User Classes, such as Reflection elements or Java elements (but may be others). These elements are removed. - Then the code tries to find elements that are indeed from Kotlintest, such as runners and other internals - After this, it's expected for user classes to be in the stacktrace, so the algorithm stops and returns the stacktrace By observation of the FailuresTest class, one may believe that only classes from `io.kotlintest` and `sun.reflect` would be in the way of user classes, but that's not the case, and this commit fixes it. * Changes `shouldRemoveKotlintestElementsFromStacktrace` to var instead of val Users may want to change this property dynamically, at runtime, for whichever reason. Changing it to a `var` won't impact anything else, so it's good to give users this freedom. (cherry picked from commit 7b17e62)
As it was, the Failures class would fail to filter classes that are neither from
sun.reflect.*
nor fromjava.*
. This commit aims to create a generic implementation that correctly filters stacktraces.The implemented behavior observes a pattern to clean the stacktrace:
By observation of the FailuresTest class, one may believe that only classes from
io.kotlintest
andsun.reflect
would be in the way of user classes, but that's not the case, and this commit fixes it.Very related to this commit