Uh oh!
There was an error while loading. Please reload this page.
Add support for top-level Kotlin functions #847 - #1147
Conversation
e3fb541 to
d9aa881Comparevolivan239
commented
Oct 12, 2022
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 |
1c4543c to
16d859bComparevolivan239
commented
Oct 18, 2022
UPD. Now extension functions should also work fine, see PR description for details |
16d859b to
85795acCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
92d3f5d to
2b56cb2Compare2b56cb2 to
cfe5932Compare
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:
KtFiles and theirFacadeClasses 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.MainKtwhen rendering top-level function calls. In order to support this, methodClassId.isKotlinFilewas added, which checkskindin Kotlin's@Metadataannotation (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()namein builtin-classidstimeunitClassIdanddurationClassIdKCallable<*>.declaringClazzandMemberInfo.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.ktManual Scenario
Checked on some top-level methods (including
fun main()in main class) -- generates correct tests both in Java and KotlinChecklist (remove irrelevant options):