Skip to content
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

Merged
merged 6 commits into from
Apr 5, 2022

Conversation

3flex
Copy link
Member

@3flex 3flex commented Feb 8, 2022

@3flex 3flex mentioned this pull request Feb 8, 2022
26 tasks
@3flex 3flex marked this pull request as draft February 8, 2022 12:15
@3flex 3flex added the housekeeping Marker for housekeeping tasks and refactorings label Feb 8, 2022
@marschwar
Copy link
Contributor

Is there anything I can do to support? Monkey work is my specialty ;) .

@3flex
Copy link
Member Author

3flex commented Mar 18, 2022

That's ok, I'll try and wrap it up this weekend! week! Thanks though.

@3flex 3flex force-pushed the junit-rules-style branch 2 times, most recently from 0db7641 to 78b2089 Compare April 3, 2022 04:42
@codecov
Copy link

codecov bot commented Apr 3, 2022

Codecov Report

Merging #4575 (fe6f3e3) into main (afdb999) will not change coverage.
The diff coverage is n/a.

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afdb999...fe6f3e3. Read the comment docs.

@3flex 3flex force-pushed the junit-rules-style branch 2 times, most recently from c784f26 to c8b0adc Compare April 3, 2022 05:04
@Nested
inner class JavaSourceTests {

private val environmentWrapper =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor

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) {
      // ...
    }
}

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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 =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor

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.

Copy link
Member Author

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.

@3flex 3flex marked this pull request as ready for review April 3, 2022 05:59
@3flex 3flex mentioned this pull request Apr 3, 2022
Copy link
Contributor

@marschwar marschwar left a 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.

chao2zhang and others added 3 commits April 3, 2022 10:39
…/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>
Copy link
Member

@chao2zhang chao2zhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve because

  1. Coverage does not seem to change 84.58% -> 84.58%
  2. All checks are passing
  3. 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

@marschwar
Copy link
Contributor

Any objections to merging this?

@chao2zhang
Copy link
Member

Not from my side. Let's do it.

@marschwar marschwar merged commit 0be7775 into detekt:main Apr 5, 2022
@3flex 3flex deleted the junit-rules-style branch April 5, 2022 21:45
chao2zhang added a commit that referenced this pull request Apr 8, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Marker for housekeeping tasks and refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants