Skip to content

Fix IU plugin compilation #1808

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

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions utbot-js/src/main/kotlin/codegen/JsCodeGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package codegen

import framework.api.js.JsClassId
import framework.codegen.JsCgLanguageAssistant
import framework.codegen.Mocha
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.MockFramework
import framework.api.js.JsClassId
import org.utbot.framework.codegen.CodeGeneratorResult
import org.utbot.framework.codegen.domain.ForceStaticMocking
import org.utbot.framework.codegen.domain.HangingTestsTimeout
Expand All @@ -17,9 +14,12 @@ import org.utbot.framework.codegen.domain.TestFramework
import org.utbot.framework.codegen.domain.context.CgContext
import org.utbot.framework.codegen.domain.models.CgClassFile
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
import org.utbot.framework.codegen.domain.models.TestClassModel
import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
import org.utbot.framework.codegen.renderer.CgAbstractRenderer
import org.utbot.framework.codegen.tree.CgSimpleTestClassConstructor
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.MockFramework
import settings.JsTestGenerationSettings.fileUnderTestAliases

class JsCodeGenerator(
Expand Down Expand Up @@ -60,7 +60,7 @@ class JsCodeGenerator(
cgTestSets: List<CgMethodTestSet>,
testClassCustomName: String? = null,
): CodeGeneratorResult = withCustomContext(testClassCustomName) {
val testClassModel = TestClassModel(classUnderTest, cgTestSets)
val testClassModel = SimpleTestClassModel(classUnderTest, cgTestSets)
val astConstructor = CgSimpleTestClassConstructor(context)
val testClassFile = astConstructor.construct(testClassModel)
CodeGeneratorResult(renderClassFile(testClassFile), astConstructor.testsGenerationReport)
Expand All @@ -84,4 +84,4 @@ class JsCodeGenerator(
file.accept(renderer)
return renderer.toString()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
package framework.codegen.model.constructor.tree

import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtReferenceModel
import framework.api.js.JsPrimitiveModel
import org.utbot.framework.codegen.domain.context.CgContext
import org.utbot.framework.codegen.domain.models.CgLiteral
import org.utbot.framework.codegen.domain.models.CgValue
import org.utbot.framework.codegen.tree.CgComponents
import org.utbot.framework.codegen.tree.CgVariableConstructor
import org.utbot.framework.codegen.util.nullLiteral
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtReferenceModel

class JsCgVariableConstructor(ctx: CgContext) : CgVariableConstructor(ctx) {

private val nameGenerator = CgComponents.getNameGeneratorBy(ctx)


override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
val baseName = name ?: nameGenerator.nameFrom(model.classId)
return if (model is UtReferenceModel) valueByModelId.getOrPut(model.id) {
when (model) {
is UtCompositeModel -> TODO()
is UtAssembleModel -> constructAssemble(model, baseName)
is UtArrayModel -> TODO()
else -> TODO()
}
// TODO SEVERE: May lead to unexpected behavior in case of changes to the original method
super.getOrCreateVariable(model, name)
} else valueByModel.getOrPut(model) {
when (model) {
is JsPrimitiveModel -> CgLiteral(model.classId, model.value)
else -> nullLiteral()
}
}
}
}
}
2 changes: 1 addition & 1 deletion utbot-js/src/main/kotlin/service/BasicCoverageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BasicCoverageService(
val json = JSONObject(rawResult)
coverageList.add(index to json.getJSONObject("s"))
val resultData = ResultData(
rawString = json.get("result").toString(),
rawString = if (json.has("result")) json.get("result").toString() else "undefined",
type = json.get("type").toString(),
index = index,
isNan = json.getBoolean("is_nan"),
Expand Down
54 changes: 27 additions & 27 deletions utbot-js/src/main/kotlin/service/FastCoverageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ class FastCoverageService(
) : CoverageService(context, scriptTexts, baseCoverage) {

override fun generateCoverageReport() {
val (_, errorText) = JsCmdExec.runCommand(
cmd = arrayOf("\"${settings.pathToNode}\"", "\"$utbotDirPath/$tempFileName" + "0.js\""),
dir = projectPath,
shouldWait = true,
timeout = settings.timeout,
val (_, errorText) = JsCmdExec.runCommand(
cmd = arrayOf("\"${settings.pathToNode}\"", "\"$utbotDirPath/$tempFileName" + "0.js\""),
dir = projectPath,
shouldWait = true,
timeout = settings.timeout,
)
for (i in 0..minOf(fuzzingThreshold - 1, testCaseIndices.last)) {
val resFile = File("$utbotDirPath/$tempFileName$i.json")
val rawResult = resFile.readText()
resFile.delete()
val json = JSONObject(rawResult)
val index = json.getInt("index")
if (index != i) logger.error { "Index $index != i $i" }
coverageList.add(index to json.getJSONObject("s"))
val resultData = ResultData(
rawString = if (json.has("result")) json.get("result").toString() else "undefined",
type = json.get("type").toString(),
index = index,
isNan = json.getBoolean("is_nan"),
isInf = json.getBoolean("is_inf"),
isError = json.getBoolean("is_error"),
specSign = json.getInt("spec_sign").toByte()
)
for (i in 0..minOf(fuzzingThreshold - 1, testCaseIndices.last)) {
val resFile = File("$utbotDirPath/$tempFileName$i.json")
val rawResult = resFile.readText()
resFile.delete()
val json = JSONObject(rawResult)
val index = json.getInt("index")
if (index != i) logger.error { "Index $index != i $i" }
coverageList.add(index to json.getJSONObject("s"))
val resultData = ResultData(
rawString = json.get("result").toString(),
type = json.get("type").toString(),
index = index,
isNan = json.getBoolean("is_nan"),
isInf = json.getBoolean("is_inf"),
isError = json.getBoolean("is_error"),
specSign = json.getInt("spec_sign").toByte()
)
_resultList.add(resultData)
}
if (errorText.isNotEmpty()) {
logger.error { errorText }
}
_resultList.add(resultData)
}
if (errorText.isNotEmpty()) {
logger.error { errorText }
}
}
}