Skip to content

Commit 791f619

Browse files
Merge branch 'main' into egor/mocks_traverser
2 parents dd8d491 + 196dc2a commit 791f619

17 files changed

Lines changed: 165 additions & 23 deletions

File tree

utbot-framework/src/main/kotlin/org/utbot/engine/ArtificialErrors.kt renamed to utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ArtificialErrors.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.engine
1+
package org.utbot.framework.plugin.api
22

33
/**
44
* Represents an error that may be detected or not
@@ -15,4 +15,9 @@ sealed class ArtificialError(message: String): Error(message)
1515
*
1616
* See [TraversalContext.intOverflowCheck] for more details.
1717
*/
18-
class OverflowDetectionError(message: String): ArtificialError(message)
18+
class OverflowDetectionError(message: String): ArtificialError(message)
19+
20+
fun ArtificialError.getPrettyName(): String =
21+
when (this) {
22+
is OverflowDetectionError -> "Overflow"
23+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.utbot.examples.math
22

33
import org.junit.jupiter.api.Disabled
44
import org.junit.jupiter.api.Test
5-
import org.utbot.engine.OverflowDetectionError
5+
import org.utbot.framework.plugin.api.OverflowDetectionError
66
import org.utbot.examples.algorithms.Sort
77
import org.utbot.framework.plugin.api.CodegenLanguage
88
import org.utbot.testcheckers.eq

utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import kotlin.math.max
9090
import kotlin.math.min
9191
import kotlinx.collections.immutable.persistentListOf
9292
import kotlinx.collections.immutable.persistentSetOf
93+
import org.utbot.framework.plugin.api.OverflowDetectionError
9394
import org.utbot.engine.types.CLASS_REF_CLASSNAME
9495
import org.utbot.engine.types.CLASS_REF_CLASS_ID
9596
import org.utbot.engine.types.CLASS_REF_NUM_DIMENSIONS_DESCRIPTOR

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import kotlinx.collections.immutable.toPersistentList
88
import kotlinx.collections.immutable.toPersistentMap
99
import kotlinx.collections.immutable.toPersistentSet
1010
import mu.KotlinLogging
11+
import org.utbot.framework.plugin.api.ArtificialError
12+
import org.utbot.framework.plugin.api.OverflowDetectionError
1113
import org.utbot.common.WorkaroundReason.HACK
1214
import org.utbot.framework.UtSettings.ignoreStaticsFromTrustedLibraries
1315
import org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package org.utbot.framework.codegen.tree
33
import org.utbot.common.WorkaroundReason
44
import org.utbot.common.isStatic
55
import org.utbot.common.workaround
6-
import org.utbot.engine.ArtificialError
76
import org.utbot.framework.UtSettings
7+
import org.utbot.framework.plugin.api.ArtificialError
88
import org.utbot.framework.assemble.assemble
99
import org.utbot.framework.codegen.domain.ForceStaticMocking
1010
import org.utbot.framework.codegen.domain.ParametrizedTestSource

utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.utbot.framework.util
22

33
import org.utbot.common.FileUtil
44
import org.utbot.engine.jimpleBody
5-
import org.utbot.engine.overrides.collections.UtLinkedList
65
import org.utbot.engine.pureJavaSignature
76
import org.utbot.framework.UtSettings
87
import org.utbot.framework.plugin.api.ExecutableId
@@ -208,7 +207,7 @@ private val classesToLoad = arrayOf(
208207
org.utbot.engine.overrides.stream.IntStream::class,
209208
org.utbot.engine.overrides.stream.LongStream::class,
210209
org.utbot.engine.overrides.stream.DoubleStream::class,
211-
org.utbot.engine.OverflowDetectionError::class,
210+
org.utbot.framework.plugin.api.OverflowDetectionError::class,
212211
).map { it.java }.toTypedArray()
213212

214213
private const val UTBOT_PACKAGE_PREFIX = "org.utbot"

utbot-intellij-js/src/main/kotlin/org/utbot/intellij/plugin/language/js/JsDialogProcessor.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import settings.JsDynamicSettings
2929
import settings.JsExportsSettings.endComment
3030
import settings.JsExportsSettings.startComment
3131
import settings.JsPackagesSettings.mochaData
32+
import settings.JsPackagesSettings.nycData
33+
import settings.JsPackagesSettings.ternData
3234
import settings.JsTestGenerationSettings.dummyClassName
3335
import settings.PackageData
3436
import utils.JsCmdExec
@@ -56,9 +58,9 @@ object JsDialogProcessor {
5658
) {
5759
override fun run(indicator: ProgressIndicator) {
5860
invokeLater {
59-
if (!mochaData.findPackageByNpm(model.project.basePath!!, model.pathToNPM)) {
60-
installMissingRequirement(model.project, model.pathToNPM, mochaData)
61-
}
61+
checkAndInstallRequirement(model.project, model.pathToNPM, mochaData)
62+
checkAndInstallRequirement(model.project, model.pathToNPM, nycData)
63+
checkAndInstallRequirement(model.project, model.pathToNPM, ternData)
6264
createDialog(model)?.let { dialogProcessor ->
6365
if (!dialogProcessor.showAndGet()) return@invokeLater
6466
// Since Tern.js accesses containing file, sync with file system required before test generation.
@@ -263,8 +265,21 @@ object JsDialogProcessor {
263265
}
264266
}
265267

266-
// TODO(MINOR): Add indicator.text for each installation
267-
fun installMissingRequirement(project: Project, pathToNPM: String, requirement: PackageData) {
268+
fun checkAndInstallRequirement(
269+
project: Project,
270+
pathToNPM: String,
271+
requirement: PackageData,
272+
) {
273+
if (!requirement.findPackageByNpm(project.basePath!!, pathToNPM)) {
274+
installMissingRequirement(project, pathToNPM, requirement)
275+
}
276+
}
277+
278+
private fun installMissingRequirement(
279+
project: Project,
280+
pathToNPM: String,
281+
requirement: PackageData,
282+
) {
268283
val message = """
269284
Requirement is not installed:
270285
${requirement.packageName}

utbot-intellij-js/src/main/kotlin/org/utbot/intellij/plugin/language/js/NycSourceFileChooser.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class NycSourceFileChooser(val model: JsTestsModel) : TextFieldWithBrowseButton(
2424
addBrowseFolderListener(
2525
TextBrowseFolderListener(descriptor, model.project)
2626
)
27-
nycData.findPackagePath() ?: installMissingRequirement(model.project, model.pathToNPM, nycData)
2827
text = (replaceSeparator(nycData.findPackagePath() ?: "Nyc was not found")
2928
+ OsProvider.getProviderByOs().npmPackagePostfix)
3029
}

utbot-js/src/main/kotlin/settings/JsPackagesSettings.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import utils.OsProvider
66
object JsPackagesSettings {
77
val mochaData: PackageData = PackageData("mocha", "-l")
88
val nycData: PackageData = PackageData("nyc", "-g")
9-
10-
// TODO(MINOR): Add tern auto installation
11-
val ternData: PackageData? = null
9+
val ternData: PackageData = PackageData("tern", "-l")
1210
}
1311

1412
data class PackageData(
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package math
2+
3+
import examples.CustomJavaDocTagsEnabler
4+
import examples.SummaryTestCaseGeneratorTest
5+
import org.junit.jupiter.api.Test
6+
import org.junit.jupiter.api.extension.ExtendWith
7+
import org.utbot.examples.math.OverflowExamples
8+
import org.utbot.framework.plugin.api.MockStrategyApi
9+
import org.utbot.testcheckers.withTreatingOverflowAsError
10+
import org.utbot.testing.DoNotCalculate
11+
12+
@ExtendWith(CustomJavaDocTagsEnabler::class)
13+
class SummaryOverflowExamples : SummaryTestCaseGeneratorTest(
14+
OverflowExamples::class
15+
) {
16+
@Test
17+
fun testShortMulOverflow() {
18+
val summary1 = "@utbot.classUnderTest {@link OverflowExamples}\n" +
19+
"@utbot.methodUnderTest {@link org.utbot.examples.math.OverflowExamples#shortMulOverflow(short,short)}\n" +
20+
"@utbot.returnsFrom {@code return (short) (x * y);}\n"
21+
val summary2 = "@utbot.classUnderTest {@link OverflowExamples}\n" +
22+
"@utbot.methodUnderTest {@link org.utbot.examples.math.OverflowExamples#shortMulOverflow(short,short)}\n" +
23+
"@utbot.detectsSuspiciousBehavior in: return (short) (x * y);\n"
24+
25+
val methodName1 = "testShortMulOverflow_ReturnXy"
26+
val methodName2 = "testShortMulOverflow_DetectOverflow"
27+
28+
val displayName1 = "-> return (short) (x * y)"
29+
val displayName2 = "return (short) (x * y) : True -> DetectOverflow"
30+
31+
val summaryKeys = listOf(
32+
summary1,
33+
summary2
34+
)
35+
36+
val displayNames = listOf(
37+
displayName1,
38+
displayName2
39+
)
40+
41+
val methodNames = listOf(
42+
methodName1,
43+
methodName2
44+
)
45+
46+
val method = OverflowExamples::shortMulOverflow
47+
val mockStrategy = MockStrategyApi.NO_MOCKS
48+
val coverage = DoNotCalculate
49+
50+
withTreatingOverflowAsError {
51+
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)