Skip to content

Commit 91001ef

Browse files
authored
Fix IU plugin compilation (#1808)
1 parent 4413a7e commit 91001ef

File tree

4 files changed

+41
-52
lines changed

4 files changed

+41
-52
lines changed

utbot-js/src/main/kotlin/codegen/JsCodeGenerator.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package codegen
22

3+
import framework.api.js.JsClassId
34
import framework.codegen.JsCgLanguageAssistant
45
import framework.codegen.Mocha
5-
import org.utbot.framework.plugin.api.CodegenLanguage
6-
import org.utbot.framework.plugin.api.ExecutableId
7-
import org.utbot.framework.plugin.api.MockFramework
8-
import framework.api.js.JsClassId
96
import org.utbot.framework.codegen.CodeGeneratorResult
107
import org.utbot.framework.codegen.domain.ForceStaticMocking
118
import org.utbot.framework.codegen.domain.HangingTestsTimeout
@@ -17,9 +14,12 @@ import org.utbot.framework.codegen.domain.TestFramework
1714
import org.utbot.framework.codegen.domain.context.CgContext
1815
import org.utbot.framework.codegen.domain.models.CgClassFile
1916
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
20-
import org.utbot.framework.codegen.domain.models.TestClassModel
17+
import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
2118
import org.utbot.framework.codegen.renderer.CgAbstractRenderer
2219
import org.utbot.framework.codegen.tree.CgSimpleTestClassConstructor
20+
import org.utbot.framework.plugin.api.CodegenLanguage
21+
import org.utbot.framework.plugin.api.ExecutableId
22+
import org.utbot.framework.plugin.api.MockFramework
2323
import settings.JsTestGenerationSettings.fileUnderTestAliases
2424

2525
class JsCodeGenerator(
@@ -60,7 +60,7 @@ class JsCodeGenerator(
6060
cgTestSets: List<CgMethodTestSet>,
6161
testClassCustomName: String? = null,
6262
): CodeGeneratorResult = withCustomContext(testClassCustomName) {
63-
val testClassModel = TestClassModel(classUnderTest, cgTestSets)
63+
val testClassModel = SimpleTestClassModel(classUnderTest, cgTestSets)
6464
val astConstructor = CgSimpleTestClassConstructor(context)
6565
val testClassFile = astConstructor.construct(testClassModel)
6666
CodeGeneratorResult(renderClassFile(testClassFile), astConstructor.testsGenerationReport)
@@ -84,4 +84,4 @@ class JsCodeGenerator(
8484
file.accept(renderer)
8585
return renderer.toString()
8686
}
87-
}
87+
}
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
package framework.codegen.model.constructor.tree
22

3-
import org.utbot.framework.plugin.api.UtArrayModel
4-
import org.utbot.framework.plugin.api.UtAssembleModel
5-
import org.utbot.framework.plugin.api.UtCompositeModel
6-
import org.utbot.framework.plugin.api.UtModel
7-
import org.utbot.framework.plugin.api.UtReferenceModel
83
import framework.api.js.JsPrimitiveModel
94
import org.utbot.framework.codegen.domain.context.CgContext
105
import org.utbot.framework.codegen.domain.models.CgLiteral
116
import org.utbot.framework.codegen.domain.models.CgValue
12-
import org.utbot.framework.codegen.tree.CgComponents
137
import org.utbot.framework.codegen.tree.CgVariableConstructor
148
import org.utbot.framework.codegen.util.nullLiteral
9+
import org.utbot.framework.plugin.api.UtModel
10+
import org.utbot.framework.plugin.api.UtReferenceModel
1511

1612
class JsCgVariableConstructor(ctx: CgContext) : CgVariableConstructor(ctx) {
17-
18-
private val nameGenerator = CgComponents.getNameGeneratorBy(ctx)
19-
13+
2014
override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
21-
val baseName = name ?: nameGenerator.nameFrom(model.classId)
2215
return if (model is UtReferenceModel) valueByModelId.getOrPut(model.id) {
23-
when (model) {
24-
is UtCompositeModel -> TODO()
25-
is UtAssembleModel -> constructAssemble(model, baseName)
26-
is UtArrayModel -> TODO()
27-
else -> TODO()
28-
}
16+
// TODO SEVERE: May lead to unexpected behavior in case of changes to the original method
17+
super.getOrCreateVariable(model, name)
2918
} else valueByModel.getOrPut(model) {
3019
when (model) {
3120
is JsPrimitiveModel -> CgLiteral(model.classId, model.value)
3221
else -> nullLiteral()
3322
}
3423
}
3524
}
36-
}
25+
}

utbot-js/src/main/kotlin/service/BasicCoverageService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BasicCoverageService(
3131
val json = JSONObject(rawResult)
3232
coverageList.add(index to json.getJSONObject("s"))
3333
val resultData = ResultData(
34-
rawString = json.get("result").toString(),
34+
rawString = if (json.has("result")) json.get("result").toString() else "undefined",
3535
type = json.get("type").toString(),
3636
index = index,
3737
isNan = json.getBoolean("is_nan"),

utbot-js/src/main/kotlin/service/FastCoverageService.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ class FastCoverageService(
1818
) : CoverageService(context, scriptTexts, baseCoverage) {
1919

2020
override fun generateCoverageReport() {
21-
val (_, errorText) = JsCmdExec.runCommand(
22-
cmd = arrayOf("\"${settings.pathToNode}\"", "\"$utbotDirPath/$tempFileName" + "0.js\""),
23-
dir = projectPath,
24-
shouldWait = true,
25-
timeout = settings.timeout,
21+
val (_, errorText) = JsCmdExec.runCommand(
22+
cmd = arrayOf("\"${settings.pathToNode}\"", "\"$utbotDirPath/$tempFileName" + "0.js\""),
23+
dir = projectPath,
24+
shouldWait = true,
25+
timeout = settings.timeout,
26+
)
27+
for (i in 0..minOf(fuzzingThreshold - 1, testCaseIndices.last)) {
28+
val resFile = File("$utbotDirPath/$tempFileName$i.json")
29+
val rawResult = resFile.readText()
30+
resFile.delete()
31+
val json = JSONObject(rawResult)
32+
val index = json.getInt("index")
33+
if (index != i) logger.error { "Index $index != i $i" }
34+
coverageList.add(index to json.getJSONObject("s"))
35+
val resultData = ResultData(
36+
rawString = if (json.has("result")) json.get("result").toString() else "undefined",
37+
type = json.get("type").toString(),
38+
index = index,
39+
isNan = json.getBoolean("is_nan"),
40+
isInf = json.getBoolean("is_inf"),
41+
isError = json.getBoolean("is_error"),
42+
specSign = json.getInt("spec_sign").toByte()
2643
)
27-
for (i in 0..minOf(fuzzingThreshold - 1, testCaseIndices.last)) {
28-
val resFile = File("$utbotDirPath/$tempFileName$i.json")
29-
val rawResult = resFile.readText()
30-
resFile.delete()
31-
val json = JSONObject(rawResult)
32-
val index = json.getInt("index")
33-
if (index != i) logger.error { "Index $index != i $i" }
34-
coverageList.add(index to json.getJSONObject("s"))
35-
val resultData = ResultData(
36-
rawString = json.get("result").toString(),
37-
type = json.get("type").toString(),
38-
index = index,
39-
isNan = json.getBoolean("is_nan"),
40-
isInf = json.getBoolean("is_inf"),
41-
isError = json.getBoolean("is_error"),
42-
specSign = json.getInt("spec_sign").toByte()
43-
)
44-
_resultList.add(resultData)
45-
}
46-
if (errorText.isNotEmpty()) {
47-
logger.error { errorText }
48-
}
44+
_resultList.add(resultData)
45+
}
46+
if (errorText.isNotEmpty()) {
47+
logger.error { errorText }
48+
}
4949
}
5050
}

0 commit comments

Comments
 (0)