@@ -2,7 +2,6 @@ package org.utbot.framework.codegen.model.constructor.tree
2
2
3
3
import org.utbot.common.PathUtil
4
4
import org.utbot.common.packageName
5
- import org.utbot.engine.isStatic
6
5
import org.utbot.framework.assemble.assemble
7
6
import org.utbot.framework.codegen.ForceStaticMocking
8
7
import org.utbot.framework.codegen.JUNIT5_PARAMETERIZED_PACKAGE
@@ -93,6 +92,7 @@ import org.utbot.framework.fields.ExecutionStateAnalyzer
93
92
import org.utbot.framework.fields.FieldPath
94
93
import org.utbot.framework.plugin.api.BuiltinClassId
95
94
import org.utbot.framework.plugin.api.BuiltinMethodId
95
+ import org.utbot.framework.plugin.api.CgMethodTestSet
96
96
import org.utbot.framework.plugin.api.ClassId
97
97
import org.utbot.framework.plugin.api.CodegenLanguage
98
98
import org.utbot.framework.plugin.api.ConcreteExecutionFailureException
@@ -113,8 +113,6 @@ import org.utbot.framework.plugin.api.UtExecution
113
113
import org.utbot.framework.plugin.api.UtExecutionFailure
114
114
import org.utbot.framework.plugin.api.UtExecutionSuccess
115
115
import org.utbot.framework.plugin.api.UtExplicitlyThrownException
116
- import org.utbot.framework.plugin.api.UtMethod
117
- import org.utbot.framework.plugin.api.UtMethodTestSet
118
116
import org.utbot.framework.plugin.api.UtModel
119
117
import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
120
118
import org.utbot.framework.plugin.api.UtNullModel
@@ -129,6 +127,7 @@ import org.utbot.framework.plugin.api.util.booleanClassId
129
127
import org.utbot.framework.plugin.api.util.doubleArrayClassId
130
128
import org.utbot.framework.plugin.api.util.doubleClassId
131
129
import org.utbot.framework.plugin.api.util.doubleWrapperClassId
130
+ import org.utbot.framework.plugin.api.util.executable
132
131
import org.utbot.framework.plugin.api.util.field
133
132
import org.utbot.framework.plugin.api.util.floatArrayClassId
134
133
import org.utbot.framework.plugin.api.util.floatClassId
@@ -155,7 +154,6 @@ import org.utbot.framework.util.isUnit
155
154
import org.utbot.summary.SummarySentenceConstants.TAB
156
155
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
157
156
import java.lang.reflect.InvocationTargetException
158
- import kotlin.reflect.jvm.javaType
159
157
160
158
private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings?
161
159
@@ -1136,11 +1134,11 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1136
1134
}
1137
1135
}
1138
1136
1139
- fun createTestMethod (utMethod : UtMethod < * > , execution : UtExecution ): CgTestMethod =
1137
+ fun createTestMethod (executableId : ExecutableId , execution : UtExecution ): CgTestMethod =
1140
1138
withTestMethodScope(execution) {
1141
- val testMethodName = nameGenerator.testMethodNameFor(utMethod , execution.testMethodName)
1139
+ val testMethodName = nameGenerator.testMethodNameFor(executableId , execution.testMethodName)
1142
1140
// TODO: remove this line when SAT-1273 is completed
1143
- execution.displayName = execution.displayName?.let { " ${utMethod.callable .name} : $it " }
1141
+ execution.displayName = execution.displayName?.let { " ${executableId .name} : $it " }
1144
1142
testMethod(testMethodName, execution.displayName) {
1145
1143
rememberInitialStaticFields()
1146
1144
val stateAnalyzer = ExecutionStateAnalyzer (execution)
@@ -1155,7 +1153,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1155
1153
}
1156
1154
// build arguments
1157
1155
for ((index, param) in execution.stateBefore.parameters.withIndex()) {
1158
- val name = paramNames[utMethod ]?.get(index)
1156
+ val name = paramNames[executableId ]?.get(index)
1159
1157
methodArguments + = variableConstructor.getOrCreateVariable(param, name)
1160
1158
}
1161
1159
rememberInitialEnvironmentState(modificationInfo)
@@ -1215,7 +1213,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1215
1213
private val expectedResultVarName = " expectedResult"
1216
1214
private val expectedErrorVarName = " expectedError"
1217
1215
1218
- fun createParameterizedTestMethod (testSet : UtMethodTestSet , dataProviderMethodName : String ): CgTestMethod {
1216
+ fun createParameterizedTestMethod (testSet : CgMethodTestSet , dataProviderMethodName : String ): CgTestMethod {
1219
1217
// TODO: orientation on generic execution may be misleading, but what is the alternative?
1220
1218
// may be a heuristic to select a model with minimal number of internal nulls should be used
1221
1219
val genericExecution = testSet.executions
@@ -1267,11 +1265,11 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1267
1265
}
1268
1266
1269
1267
private fun createParameterDeclarations (
1270
- testSet : UtMethodTestSet ,
1268
+ testSet : CgMethodTestSet ,
1271
1269
genericExecution : UtExecution ,
1272
1270
): List <CgParameterDeclaration > {
1273
- val methodUnderTest = testSet.method
1274
- val methodUnderTestParameters = testSet.method.callable .parameters
1271
+ val executableUnderTest = testSet.executableId
1272
+ val executableUnderTestParameters = testSet.executableId.executable .parameters
1275
1273
1276
1274
return mutableListOf<CgParameterDeclaration >().apply {
1277
1275
// this instance
@@ -1290,9 +1288,9 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1290
1288
}
1291
1289
// arguments
1292
1290
for (index in genericExecution.stateBefore.parameters.indices) {
1293
- val argumentName = paramNames[methodUnderTest ]?.get(index)
1294
- val paramIndex = if (methodUnderTest .isStatic) index else index + 1
1295
- val paramType = methodUnderTestParameters [paramIndex].type.javaType
1291
+ val argumentName = paramNames[executableUnderTest ]?.get(index)
1292
+ val paramIndex = if (executableUnderTest is MethodId && executableUnderTest .isStatic) index else index + 1
1293
+ val paramType = executableUnderTestParameters [paramIndex].parameterizedType
1296
1294
1297
1295
val argumentType = when {
1298
1296
paramType is Class <* > && paramType.isArray -> paramType.id
@@ -1353,7 +1351,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1353
1351
* Standard logic for generating each test case parameter code is used.
1354
1352
*/
1355
1353
fun createParameterizedTestDataProvider (
1356
- testSet : UtMethodTestSet ,
1354
+ testSet : CgMethodTestSet ,
1357
1355
dataProviderMethodName : String
1358
1356
): CgParameterizedTestDataProviderMethod {
1359
1357
val dataProviderStatements = mutableListOf<CgStatement >()
@@ -1376,7 +1374,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1376
1374
}
1377
1375
1378
1376
for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) {
1379
- val argumentName = paramNames[testSet.method ]?.get(paramIndex)
1377
+ val argumentName = paramNames[testSet.executableId ]?.get(paramIndex)
1380
1378
arguments + = variableConstructor.getOrCreateVariable(paramModel, argumentName)
1381
1379
}
1382
1380
@@ -1572,7 +1570,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1572
1570
)
1573
1571
}
1574
1572
1575
- private fun containsFailureExecution (testSet : UtMethodTestSet ) =
1573
+ private fun containsFailureExecution (testSet : CgMethodTestSet ) =
1576
1574
testSet.executions.any { it.result is UtExecutionFailure }
1577
1575
1578
1576
/* *
@@ -1670,7 +1668,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1670
1668
return testMethod
1671
1669
}
1672
1670
1673
- fun errorMethod (method : UtMethod < * > , errors : Map <String , Int >): CgRegion <CgMethod > {
1671
+ fun errorMethod (method : ExecutableId , errors : Map <String , Int >): CgRegion <CgMethod > {
1674
1672
val name = nameGenerator.errorMethodNameFor(method)
1675
1673
val body = block {
1676
1674
comment(" Couldn't generate some tests. List of errors:" )
@@ -1699,7 +1697,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1699
1697
}
1700
1698
}
1701
1699
val errorTestMethod = CgErrorTestMethod (name, body)
1702
- return CgSimpleRegion (" Errors report for ${method.callable. name} " , listOf (errorTestMethod))
1700
+ return CgSimpleRegion (" Errors report for ${method.name} " , listOf (errorTestMethod))
1703
1701
}
1704
1702
1705
1703
private fun getJvmReportDocumentation (jvmReportPath : String ): String {
0 commit comments