-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add support for top-level Kotlin functions #847 #1147
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
volivan239
force-pushed
the
volivan239/make_top_level_methods_testable
branch
from
October 12, 2022 14:50
e3fb541
to
d9aa881
Compare
Note that this doesn't resolve all problems featured by #847, as currently this doesn't work for extension functions. Needs a little bit more investigation and additional commit/PR |
volivan239
force-pushed
the
volivan239/make_top_level_methods_testable
branch
5 times, most recently
from
October 18, 2022 17:40
1c4543c
to
16d859b
Compare
UPD. Now extension functions should also work fine, see PR description for details |
volivan239
force-pushed
the
volivan239/make_top_level_methods_testable
branch
from
October 19, 2022 14:26
16d859b
to
85795ac
Compare
EgorkaKulikov
requested changes
Oct 20, 2022
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt
Show resolved
Hide resolved
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt
Show resolved
Hide resolved
...t-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/Domain.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt
Show resolved
Hide resolved
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgJavaRenderer.kt
Outdated
Show resolved
Hide resolved
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt
Outdated
Show resolved
Hide resolved
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt
Show resolved
Hide resolved
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/util/SignaturesHelper.kt
Show resolved
Hide resolved
volivan239
force-pushed
the
volivan239/make_top_level_methods_testable
branch
2 times, most recently
from
October 23, 2022 23:06
92d3f5d
to
2b56cb2
Compare
volivan239
force-pushed
the
volivan239/make_top_level_methods_testable
branch
from
October 25, 2022 14:21
2b56cb2
to
cfe5932
Compare
EgorkaKulikov
approved these changes
Oct 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With these changes, UtBot is able to generate tests for top-level Kotlin functions including extension functions. There are two main subjects that were changed:
KtFile
s and theirFacadeClass
es among the other classes that we were already looking for. Note that as Kotlin reflection is not fully supported for such classes (see issue), some pieces of code were rewritten to use Java reflection.MainKt
when rendering top-level function calls. In order to support this, methodClassId.isKotlinFile
was added, which checkskind
in Kotlin's@Metadata
annotation (see docs for more info). Also, for extension functions we should replace fictive caller with extension receiver, borrowing it from arguments (see comment toCgMethodCall.takeCallerFromArgumentsIfNeeded()
for more detials).Alongside with above changes in plugin and codegen, following side-changes were made to handle exploited problems:
KClass<*>.signature()
andMemberInfo.signature()
name
in builtin-classidstimeunitClassId
anddurationClassId
KCallable<*>.declaringClazz
andMemberInfo
.paramNames were slightly changed to work properly when given function is an extension functionFixes #847
Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Automated Testing
Added tests to
org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt
Manual Scenario
Checked on some top-level methods (including
fun main()
in main class) -- generates correct tests both in Java and KotlinChecklist (remove irrelevant options):