https://kotlinlang.org logo
#konsist
Title
# konsist
p

Piotr Krzemiński

10/04/2023, 6:23 AM
hi, I'm following this article: https://proandroiddev.com/konsist-first-experience-with-the-new-linter-for-kotlin-9153b0e7e2c3 and want to add a simple check first:
Copy code
Konsist.scopeFromProduction()
   .withModifier(KoModifier.DATA)
   .properties(includeNested = true, includeLocal = true)
   .assertNot {
      it.hasValModifier
   }
one thing is that there's
.classes()
missing after getting the scope (I'll report it to the author), but even after adding it, I'm getting this when running the test:
Copy code
java.lang.ClassCastException: class org.jetbrains.kotlin.idea.KotlinFileType cannot be cast to class com.intellij.openapi.fileTypes.FileType (org.jetbrains.kotlin.idea.KotlinFileType and com.intellij.openapi.fileTypes.FileType are in unnamed module of loader 'app')
	at com.lemonappdev.konsist.core.util.KotlinFileParser.getKtFile(KotlinFileParser.kt:42)
A full reproducer is here. Am I doing something wrong?
👀 1
p

PoisonedYouth

10/04/2023, 7:05 AM
Sorry that was my mistake. I not copied the correct code. Just update it as below
Copy code
Konsist.scopeFromProduction()
            .classes()
            .withModifier(KoModifier.DATA)
            .properties(includeNested = true, includeLocal = true)
            .assert {
                it.hasValModifier
            }
👍 1
I will correct it in the article. Thank you very much 🙂
🙌 2
p

Piotr Krzemiński

10/04/2023, 7:06 AM
@PoisonedYouth does the test work fine for you, even after adding
classes()
? do you have a clue why it may not work in my case?
p

PoisonedYouth

10/04/2023, 7:09 AM
For me it is working after updating as shown above. What is the failure you get?
p

Piotr Krzemiński

10/04/2023, 7:09 AM
see the original message in this thread
my project is not related to Android
but I recall there’s this convention for Android to have the
app
module - maybe it’s about this?
p

PoisonedYouth

10/04/2023, 7:19 AM
I'm not sure if this is related to the test. There is a type problem while parsing the input.
i

igor.wojda

10/05/2023, 4:32 AM
@Piotr Krzemiński I have opened your repo (interesting project). Actually heaving branch witch issue helps a lot to speed up things (thx). Your test fails because you have used
assertNot
Copy code
.assertNot {
      it.hasValModifier
   }
which means you are asserting that these declarations don't have
val
modifier. Just change it to
assert
and test will run
Copy code
.assert {
      it.hasValModifier
   }
BTW In upcoming release these assertion will be renamed to
assertTrue
and
assertFalse
👍 1
p

PoisonedYouth

10/05/2023, 4:46 AM
Thanks for checking the issue, but what was the reason for the ClassCastException?
i

igor.wojda

10/05/2023, 5:12 AM
There are few issues here that have piled up: 1. Test output has almost 6000K lines f code 😅 with
2192
properties 🚀 2. Konsist is not displaying right name for the KoTest test for ki tests
..Assert 'invokeSuspend' was violated (2192 times)...
(will be fixed in next release) 3. It looks like Gradle cuts the logs (they are not full) I am unable to reproduce class cast exception issue after checking out this project - long story short some Kotlin file can't be parsed 🤔 (I guess they may be in some temp/build dir). @Piotr Krzemiński can make this cast problem reproducable on your side, zip entire project and send it my way?
👍 1
p

Piotr Krzemiński

10/05/2023, 6:31 AM
Just tried it on GitHub Actions and there's no ClassCastException: https://github.com/typesafegithub/github-workflows-kt/actions/runs/6415411375/job/17417290875?pr=1006 - will try to prepare a reproducer later
❤️ 1
i

igor.wojda

10/05/2023, 10:42 AM
BTW @Piotr Krzemiński I see that in your repo these logs for failing Konsist test are not complete, beginning is missing (not sure why). You should either update your configuration somehow or upload this JUnit report as artifact, to facilitate debugging
github-workflows-kt/library/build/reports/tests/test/index.html
(this artifact contains a complete log for failing test) BTW KoTest support is coming, soon so you will be able to see meaningful method names in crash logs
p

Piotr Krzemiński

10/05/2023, 11:02 AM
do you know if
build/reports/tests/test/index.html
can be retrieved there somehow?
I can only see
com.lemonappdev.konsist.core.exception.KoCheckFailedException: Assert 'invokeSuspend' was violated (2192 times).
here which looks like a false positive
i

igor.wojda

10/05/2023, 2:37 PM
this is the false because you where using
assertNot
instead of
assert
to retrieve
build/reports/tests/test/index.html
from CI you have to store it as build artifact
Copy code
- uses: actions/upload-artifact@v3
        with:
          name: dokka-html-doc.jar
          path: ./build/reports/tests/*
👍 1
BTW We have been able to reproduce the casting issue - I have never see bug like this 🤯 We are investigating
🎉 1
p

PoisonedYouth

10/05/2023, 3:06 PM
Is it related to Kotest or can you reproduce it with Junit5?
p

Piotr Krzemiński

10/05/2023, 3:19 PM
Good catch!
Do you track it in some ticket?
i

igor.wojda

10/05/2023, 4:22 PM
Yes we do track all of this in our backlog. We are currently in the process of transitioning to make the backlog public. but you should be already able to see the ticket in read only. https://lemonappdev.atlassian.net/browse/KON-534
👍 1
@PoisonedYouth if you have time to play with it you can find a link to the project added to the ticket. If you find something let us know.
p

PoisonedYouth

10/06/2023, 2:03 PM
I will have a look on it this weekend.
❤️ 1
i

igor.wojda

10/06/2023, 2:13 PM
Great I am curious what you will find here. BTW We are planning to do the next release at the beginning of the week, so it would be good to have a better understanding on this (maybe even a bug fix)
p

PoisonedYouth

10/06/2023, 5:27 PM
As a first check, the same error does not occur when running the test with Junit5 (independent of running it separately or the complete test file). That is very interesting.
The exception is really confusing. It seams that
LightVirtualFile
has a parameter of type
com.intellij.openapi.fileTypes.FileType
but
KotlinFileParser
is providing
org.jetbrains.kotlin.idea.KotlinFileType
. That does not make sense. I made some tests with Kotest but was not able to reproduce the issue in any of my private projects.
i

igor.wojda

10/08/2023, 7:25 PM
I was able to reproduce this for a brief moment, now issue is gone. I will add a bit more logging , but it looks like project cache was broken. @Piotr Krzemiński I will close this ticket for now. If you will be able to reproduce this issue, then please share a project so we can investigate further.
👍 1
I am able to reproduce this again - now I see
NoClassDefFoundError
- I have no idea whats going on, but I am hoping that Kotest community will help. For now it looks like cmd run works, you cna run all tests from class using IDE, however single test run may fail. https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1696872615996559
🤞 1
p

Piotr Krzemiński

10/09/2023, 6:32 PM
I got this today as well, both when running the entire test class and a single test
i

igor.wojda

10/09/2023, 7:14 PM
FOr now it looks like a bug in kotest plugin - fortunately cmd works. It may be worth mentioning in the above post - maybe you will provide some valuable information for kotest maintainers.
4 Views