I’ve just tried out Konsist and I like it a lot! B...
# konsist
m
I’ve just tried out Konsist and I like it a lot! But I have a question, I used it together with #kotest, and I think they pair up great. However I’m not sure how can I suppress a Konsist rule.
@Suppress("Use cases are in a usecase package")
does not work.
❤️ 1
i
Thx Suppressions are not supported for KoTest ATM. For JUnit based suppression we retrieve konsist test method name from the test call stack and kotest follows totally different approach. We had very brief initial look at this and we where not able to succeed. That's being said we still have this in our backlog, so we will take a loot at this at some point. If you would like to explore and debug this the entire suppression code is in the
KoDeclarationAndProviderAssertCore.kt
file. I am happy to help kicking this off.
@Jonathan Sarco you can help by investigating this
j
Sure! I'll investigate a bit of it. I might have some questions but I'll come back to you after checking it properly.
👍 1
i
@Jonathan Sarco more context on this. When you use
@Supress
annotation you need to pass
name
(ot the check that you want to suppress). Konsist is retrieving this method name by using call stack of current thread (
CommonAssert.kt
contains methods used in
KoDeclarationAndProviderAssertCore.kt
). KoTest is using custom DSL, so I am not even sure if this approach will work for Konsist. I am not sure if name can be retrieved in this context. The best approach would be to try to get kotest test name inside
KoDeclarationAndProviderAssertCore.kt
). See https://github.com/kotest/kotest/issues/3546 If the above approach will fail we will have to introduce a new nullable argument to both
assert
and
assertNot
methods (
KoDeclarationAndProviderAssertCore.kt
) called
suppressName
. They way it could work is that: • If
suppressName
argument is passed then use this name as the test name to be supresses • If
suppressName
argument is not passed then default to function name (that will obviously work only for JUnit tests) Code
Copy code
...
.classes()
.assert(suppressName = "my konsist test") {
    ....
}
Production code
Copy code
@Suppress("my konsist test") 
class Car
🤙🏽 1
j
Hey @igor.wojda Managed to reproduce the error. Doing some tests about it (based on your input). I'll keep you posted
❤️ 1
🔥 1
Some findings about it. Until now, I couldn’t find a way to get the “method name” from within
KoDeclarationAndProviderAssertCore.kt
. Because the context is different (at least for now, I couldn’t get it. It should be a way 💡). What I can do it’s the second option, using a
suppress name
when calling the assert method (I think this should be improved, not the cleanest way I would say). So taking the context of
FreeSpec (KoTest)
, I can get the method name with
this.testCase.name.testName
WIP.
👍 1
i
Since we will not be able to get the name of the koTest, so it has to be passed explicitly API proposal:
Copy code
.assert(suppressName = this.testCase.name.testName)
We will also add
koTestName
extension, so final usage will be like this:
Copy code
.assert(suppressName = koTestName)