Skip to content

Commit

Permalink
Correct casts for negative numbers and test file name for inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorkaKulikov authored Aug 17, 2023
1 parent 8ef6bd5 commit 870153f
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ internal class CgJavaRenderer(context: CgRendererContext, printer: CgPrinter = C
return
}

val isNegativeNumber = element.expression is CgLiteral
&& element.expression.value is Number && element.expression.value.toDouble() < 0

print("(")

print("(")
print(wrappedTargetType.asString())
print(") ")

if (isNegativeNumber) print("(")
element.expression.accept(this)
if (isNegativeNumber) print(")")

print(")")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.utbot.framework.codegen.renderer.CgJavaRenderer
import org.utbot.framework.codegen.renderer.CgRendererContext
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.JVMTestFrameworkManager
import org.utbot.framework.plugin.api.utils.testClassNameGenerator
import org.utbot.framework.plugin.api.utils.ClassNameUtils.generateTestClassName

object JavaCgLanguageAssistant : AbstractCgLanguageAssistant() {

Expand All @@ -26,7 +26,7 @@ object JavaCgLanguageAssistant : AbstractCgLanguageAssistant() {
testClassPackageName: String,
classUnderTest: ClassId
): Pair<String, String> {
return testClassNameGenerator(testClassCustomName, testClassPackageName, classUnderTest)
return generateTestClassName(testClassCustomName, testClassPackageName, classUnderTest)
}

override fun getLanguageTestFrameworkManager() = JVMTestFrameworkManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.utbot.framework.codegen.renderer.CgKotlinRenderer
import org.utbot.framework.codegen.renderer.CgRendererContext
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.JVMTestFrameworkManager
import org.utbot.framework.plugin.api.utils.testClassNameGenerator
import org.utbot.framework.plugin.api.utils.ClassNameUtils.generateTestClassName

object KotlinCgLanguageAssistant : AbstractCgLanguageAssistant() {

Expand All @@ -24,7 +24,7 @@ object KotlinCgLanguageAssistant : AbstractCgLanguageAssistant() {
testClassPackageName: String,
classUnderTest: ClassId
): Pair<String, String> {
return testClassNameGenerator(testClassCustomName, testClassPackageName, classUnderTest)
return generateTestClassName(testClassCustomName, testClassPackageName, classUnderTest)
}

override fun getLanguageTestFrameworkManager() = JVMTestFrameworkManager()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.utbot.framework.plugin.api.utils

import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.util.nameWithEnclosingClassesAsContigousString

object ClassNameUtils {
fun generateTestClassName(
testClassCustomName: String?,
testClassPackageName: String,
classUnderTest: ClassId,
): Pair<String, String> {
val packagePrefix = if (testClassPackageName.isNotEmpty()) "$testClassPackageName." else ""
val simpleName = testClassCustomName ?: generateTestClassShortName(classUnderTest)
val name = "$packagePrefix$simpleName"
return Pair(name, simpleName)
}

fun generateTestClassShortName(classUnderTest: ClassId): String =
"${classUnderTest.nameWithEnclosingClassesAsContigousString}Test"
}


This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.jClass
import org.utbot.framework.plugin.api.util.method
import org.utbot.framework.plugin.api.utils.ClassNameUtils
import org.utbot.framework.plugin.services.JdkInfo
import org.utbot.framework.process.generated.*
import org.utbot.framework.process.generated.BeanAdditionalData
Expand Down Expand Up @@ -121,6 +122,11 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch
}
)
}
watchdog.measureTimeForActiveCall(findTestClassName, "Creating test class name") { params ->
val classUnderTest: ClassId = kryoHelper.readObject(params.classUnderTest)
val testClassName = ClassNameUtils.generateTestClassShortName(classUnderTest)
TestClassNameResult(testClassName)
}
watchdog.measureTimeForActiveCall(generate, "Generating tests") { params ->
val methods: List<ExecutableId> = kryoHelper.readObject(params.methods)
logger.debug()
Expand Down
Loading

0 comments on commit 870153f

Please sign in to comment.