-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
Migrate detekt-rules-style tests to JUnit #4575
Conversation
Is there anything I can do to support? Monkey work is my specialty ;) . |
That's ok, I'll try and wrap it up this |
0db7641
to
78b2089
Compare
Codecov Report
@@ Coverage Diff @@
## main #4575 +/- ##
=========================================
Coverage 84.58% 84.58%
Complexity 3434 3434
=========================================
Files 492 492
Lines 11329 11329
Branches 2058 2058
=========================================
Hits 9583 9583
Misses 701 701
Partials 1045 1045 Continue to review full report at Codecov.
|
c784f26
to
c8b0adc
Compare
@Nested | ||
inner class JavaSourceTests { | ||
|
||
private val environmentWrapper = |
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.
👀
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.
How about this?
class ObjectLiteralToLambdaSpec() {
val subject = ObjectLiteralToLambda()
@Nested
@KotlinCoreEnvironmentTest
inner class DefaultSourceTests(val env: KotlinCoreEnvironment) {
// ...
}
@Nested
@KotlinCoreEnvironmentTest(additionalJavaSourcePaths = ["java"])
inner class JavaSourceTests(val env: KotlinCoreEnvironment) {
// ...
}
}
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.
It would be really good, If test authors do not have to create and dispose the environment manually
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.
It would be really good, If test authors do not have to create and dispose the environment manually
Agree though out of the ~1300 style tests there are only 4 using this setup, so it's very much an exception, so perhaps the manual option is OK?
As for options, I did try what you suggested above, but annotation parameters cannot be nullable, so this would mean every time the annotation is used you'd have to pass an empty list to the annotation.
We could instead have a separate annotation like @KotlinCoreEnvironmentTestWithJavaRoot
that accepts the parameter. It feels awkward though to use just for these few cases, but it would be good to have a general solution for including Java sources in a test like this.
I'll wait for feedback.
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.
Annotation parameters May not be null, but they can have defaults. I did get this to work but the Code is not ready to be commited. I think it is fine to merge this and come back to it later.
} | ||
""" | ||
assertThat(subject.lintWithContext(env, code)).isEmpty() | ||
private val environmentWrapper = |
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.
👀
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.
I was going to suggest to extend the annotation to something like @KotlinCoreEnvironmentTest(additionalJavaSourcePaths = ["java"])
. But something seems to be wrong with the test as it does not fail even when the regular env
is used.
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.
it does not fail even when the regular env is used.
I noticed this too, but I only picked up that that I didn't use the custom environment here when the coverage report showed a change in coverage for the rule under test.
Agree this doesn't seem to be testing what it appears to be at first glance, but fixing that can be done another time.
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.
Thank you for taking this. I did not realize how many style rules there are.
detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt
Outdated
Show resolved
Hide resolved
detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt
Outdated
Show resolved
Hide resolved
detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt
Outdated
Show resolved
Hide resolved
…/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com>
…/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com>
…/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com>
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.
Approve because
- Coverage does not seem to change 84.58% -> 84.58%
- All checks are passing
- Scroll through the PR briefly and did not find undesired changes.
I don't think it's worth time reading every line of code changes
Any objections to merging this? |
Not from my side. Let's do it. |
* Migrate detekt-rules-style tests to JUnit * Replace Spek in test cases with MockK * Revert inadvertent changes * Update detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com> * Update detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com> * Update detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MagicNumberSpec.kt Co-authored-by: marschwar <marschwar@users.noreply.github.com> Co-authored-by: Chao Zhang <zhangchao6865@gmail.com> Co-authored-by: marschwar <marschwar@users.noreply.github.com>
#4450