Skip to content

Commit 7922e63

Browse files
authored
Added CgLanguageAssistant to CodeGeneration constructor #1639 (#1640)
1 parent c1c10ff commit 7922e63

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.utbot.framework.codegen.domain.MockitoStaticMocking
2222
import org.utbot.framework.codegen.domain.NoStaticMocking
2323
import org.utbot.framework.codegen.domain.StaticsMocking
2424
import org.utbot.framework.codegen.domain.testFrameworkByName
25+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
2526
import org.utbot.framework.plugin.api.ClassId
2627
import org.utbot.framework.plugin.api.CodegenLanguage
2728
import org.utbot.framework.plugin.api.ExecutableId
@@ -211,6 +212,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
211212
testFramework = testFrameworkByName(testFramework),
212213
classUnderTest = classUnderTest,
213214
codegenLanguage = codegenLanguage,
215+
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(codegenLanguage),
214216
staticsMocking = staticsMocking,
215217
forceStaticMocking = forceStaticMocking,
216218
generateWarningsForStaticMocking = generateWarningsForStaticMocking,

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.utbot.framework.codegen.domain.Junit5
99
import org.utbot.framework.codegen.domain.NoStaticMocking
1010
import org.utbot.framework.codegen.domain.StaticsMocking
1111
import org.utbot.framework.codegen.domain.TestFramework
12+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
1213
import org.utbot.framework.concrete.UtConcreteExecutionData
1314
import org.utbot.framework.concrete.UtConcreteExecutionResult
1415
import org.utbot.framework.concrete.UtExecutionInstrumentation
@@ -85,6 +86,7 @@ object UtBotJavaApi {
8586
testFramework = testFramework,
8687
mockFramework = mockFramework,
8788
codegenLanguage = codegenLanguage,
89+
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(codegenLanguage),
8890
staticsMocking = staticsMocking,
8991
forceStaticMocking = forceStaticMocking,
9092
generateWarningsForStaticMocking = generateWarningsForStaticMocking,

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/CodeGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ open class CodeGenerator(
3333
forceStaticMocking: ForceStaticMocking = ForceStaticMocking.defaultItem,
3434
generateWarningsForStaticMocking: Boolean = true,
3535
codegenLanguage: CodegenLanguage = CodegenLanguage.defaultItem,
36+
cgLanguageAssistant: CgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(CodegenLanguage.defaultItem),
3637
parameterizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem,
3738
runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour = RuntimeExceptionTestsBehaviour.defaultItem,
3839
hangingTestsTimeout: HangingTestsTimeout = HangingTestsTimeout(),
@@ -49,7 +50,7 @@ open class CodeGenerator(
4950
testFramework = testFramework,
5051
mockFramework = mockFramework,
5152
codegenLanguage = codegenLanguage,
52-
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(codegenLanguage),
53+
cgLanguageAssistant = cgLanguageAssistant,
5354
parametrizedTestSource = parameterizedTestSource,
5455
staticsMocking = staticsMocking,
5556
forceStaticMocking = forceStaticMocking,

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.framework.plugin.sarif
33
import org.utbot.framework.codegen.CodeGenerator
44
import org.utbot.framework.codegen.domain.ForceStaticMocking
55
import org.utbot.framework.codegen.domain.NoStaticMocking
6+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
67
import org.utbot.framework.plugin.api.TestCaseGenerator
78
import org.utbot.framework.plugin.api.UtMethodTestSet
89
import org.utbot.framework.plugin.api.util.id
@@ -77,7 +78,8 @@ class GenerateTestsAndSarifReportFacade(
7778
staticsMocking = sarifProperties.staticsMocking,
7879
forceStaticMocking = sarifProperties.forceStaticMocking,
7980
generateWarningsForStaticMocking = isNoStaticMocking && isForceStaticMocking,
80-
codegenLanguage = sarifProperties.codegenLanguage
81+
codegenLanguage = sarifProperties.codegenLanguage,
82+
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(sarifProperties.codegenLanguage),
8183
)
8284
}
8385

utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import kotlinx.coroutines.newSingleThreadContext
6060
import kotlinx.coroutines.runBlocking
6161
import kotlinx.coroutines.withTimeoutOrNull
6262
import kotlinx.coroutines.yield
63+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
6364
import org.utbot.framework.plugin.api.util.isSynthetic
6465

6566
internal const val junitVersion = 4
@@ -223,7 +224,8 @@ fun runGeneration(
223224
testFramework = junitByVersion(junitVersion),
224225
staticsMocking = staticsMocking,
225226
forceStaticMocking = forceStaticMocking,
226-
generateWarningsForStaticMocking = false
227+
generateWarningsForStaticMocking = false,
228+
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(CodegenLanguage.defaultItem),
227229
)
228230

229231
logger.info().bracket("class ${cut.fqn}", { statsForClass }) {

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/PythonCodeGenerator.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.utbot.framework.codegen.domain.ParametrizedTestSource
88
import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour
99
import org.utbot.framework.codegen.domain.StaticsMocking
1010
import org.utbot.framework.codegen.domain.TestFramework
11-
import org.utbot.framework.codegen.domain.context.CgContext
1211
import org.utbot.framework.codegen.domain.models.CgLiteral
1312
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
1413
import org.utbot.framework.codegen.domain.models.CgVariable
@@ -61,24 +60,9 @@ class PythonCodeGenerator(
6160
runtimeExceptionTestsBehaviour=runtimeExceptionTestsBehaviour,
6261
hangingTestsTimeout=hangingTestsTimeout,
6362
enableTestsTimeout=enableTestsTimeout,
64-
testClassPackageName=testClassPackageName
63+
testClassPackageName=testClassPackageName,
64+
cgLanguageAssistant = PythonCgLanguageAssistant,
6565
) {
66-
override var context: CgContext = CgContext(
67-
classUnderTest = classUnderTest,
68-
paramNames = paramNames,
69-
testFramework = testFramework,
70-
mockFramework = mockFramework,
71-
cgLanguageAssistant = PythonCgLanguageAssistant,
72-
parametrizedTestSource = parameterizedTestSource,
73-
staticsMocking = staticsMocking,
74-
forceStaticMocking = forceStaticMocking,
75-
generateWarningsForStaticMocking = generateWarningsForStaticMocking,
76-
runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour,
77-
hangingTestsTimeout = hangingTestsTimeout,
78-
enableTestsTimeout = enableTestsTimeout,
79-
testClassPackageName = testClassPackageName
80-
)
81-
8266
fun pythonGenerateAsStringWithTestReport(
8367
cgTestSets: List<CgMethodTestSet>,
8468
importModules: Set<PythonImport>,

utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.utbot.framework.codegen.domain.ForceStaticMocking
1111
import org.utbot.framework.codegen.domain.ParametrizedTestSource
1212
import org.utbot.framework.codegen.domain.StaticsMocking
1313
import org.utbot.framework.codegen.domain.TestFramework
14+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
1415
import org.utbot.framework.codegen.tree.ututils.UtilClassKind
1516
import org.utbot.framework.codegen.tree.ututils.UtilClassKind.Companion.UT_UTILS_INSTANCE_NAME
1617
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -271,6 +272,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram
271272
forceStaticMocking = forceStaticMocking,
272273
generateWarningsForStaticMocking = false,
273274
codegenLanguage = codegenLanguage,
275+
cgLanguageAssistant = CgLanguageAssistant.getByCodegenLanguage(codegenLanguage),
274276
parameterizedTestSource = parametrizedTestSource,
275277
runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour,
276278
enableTestsTimeout = enableTestsTimeout

0 commit comments

Comments
 (0)