Skip to content

Commit 9eeb771

Browse files
committed
Review fixes
1 parent 390bdea commit 9eeb771

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,13 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
510510
* Depending on this option, <clinit> sections might be analyzed or not.
511511
* Note that some clinit sections still will be initialized using runtime information.
512512
*/
513-
var disableClinitSectionsAnalysis by getBooleanProperty(false)
513+
var enableClinitSectionsAnalysis by getBooleanProperty(true)
514514

515515
/**
516516
* Process all clinit sections concretely.
517517
*
518-
* If [disableClinitSectionsAnalysis] is true, it disables effect of this function as well.
518+
* If [enableClinitSectionsAnalysis] is true, it disables effect of this option as well.
519+
* Note that values processed concretely won't be replaced with unbounded symbolic variables.
519520
*/
520521
var processAllClinitSectionsConcretely by getBooleanProperty(false)
521522
}

utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ inline fun <reified T> withoutConcrete(block: () -> T): T {
109109
}
110110
}
111111

112-
inline fun <reified T> withoutProcessingClinitSections(block: () -> T): T {
113-
val prev = UtSettings.disableClinitSectionsAnalysis
114-
UtSettings.disableClinitSectionsAnalysis = true
112+
inline fun <reified T> withProcessingClinitSections(value: Boolean, block: () -> T): T {
113+
val prev = UtSettings.enableClinitSectionsAnalysis
114+
UtSettings.enableClinitSectionsAnalysis = value
115115
try {
116116
return block()
117117
} finally {
118-
UtSettings.disableClinitSectionsAnalysis = prev
118+
UtSettings.enableClinitSectionsAnalysis = prev
119119
}
120120
}
121121

122-
inline fun <reified T> withProcessingAllClinitSectionsConcretely(block: () -> T): T {
122+
inline fun <reified T> withProcessingAllClinitSectionsConcretely(value: Boolean, block: () -> T): T {
123123
val prev = UtSettings.processAllClinitSectionsConcretely
124-
UtSettings.processAllClinitSectionsConcretely = true
124+
UtSettings.processAllClinitSectionsConcretely = value
125125
try {
126126
return block()
127127
} finally {

utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassForTestClinitSectionsTest.kt

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,65 @@ package org.utbot.examples.objects
33
import org.junit.jupiter.api.Test
44
import org.utbot.testcheckers.eq
55
import org.utbot.testcheckers.withProcessingAllClinitSectionsConcretely
6-
import org.utbot.testcheckers.withoutProcessingClinitSections
6+
import org.utbot.testcheckers.withoutConcrete
7+
import org.utbot.testcheckers.withProcessingClinitSections
78
import org.utbot.testing.UtValueTestCaseChecker
89
import org.utbot.testing.atLeast
910

1011
internal class ClassForTestClinitSectionsTest : UtValueTestCaseChecker(testClass = ClassForTestClinitSections::class) {
1112
@Test
1213
fun testClinitWithoutClinitAnalysis() {
13-
withoutProcessingClinitSections {
14-
check(
15-
ClassForTestClinitSections::resultDependingOnStaticSection,
16-
eq(2)
17-
)
14+
withoutConcrete {
15+
withProcessingClinitSections(value = false) {
16+
check(
17+
ClassForTestClinitSections::resultDependingOnStaticSection,
18+
eq(2),
19+
{ r -> r == -1 },
20+
{ r -> r == 1 }
21+
)
22+
}
1823
}
1924
}
2025

2126
@Test
2227
fun testClinitWithClinitAnalysis() {
23-
check(
24-
ClassForTestClinitSections::resultDependingOnStaticSection,
25-
eq(1),
26-
coverage = atLeast(71)
27-
)
28+
withoutConcrete {
29+
check(
30+
ClassForTestClinitSections::resultDependingOnStaticSection,
31+
eq(2),
32+
{ r -> r == -1 },
33+
{ r -> r == 1 }
34+
)
35+
}
2836
}
2937

3038
@Test
3139
fun testProcessConcretelyWithoutClinitAnalysis() {
32-
withoutProcessingClinitSections {
33-
withProcessingAllClinitSectionsConcretely {
34-
check(
35-
ClassForTestClinitSections::resultDependingOnStaticSection,
36-
eq(2)
37-
)
40+
withoutConcrete {
41+
withProcessingClinitSections(value = false) {
42+
withProcessingAllClinitSectionsConcretely(value = true) {
43+
check(
44+
ClassForTestClinitSections::resultDependingOnStaticSection,
45+
eq(2),
46+
{ r -> r == -1 },
47+
{ r -> r == 1 }
48+
)
49+
}
3850
}
3951
}
4052
}
4153

4254
@Test
4355
fun testProcessClinitConcretely() {
44-
withProcessingAllClinitSectionsConcretely {
45-
check(
46-
ClassForTestClinitSections::resultDependingOnStaticSection,
47-
eq(1),
48-
coverage = atLeast(71)
49-
)
56+
withoutConcrete {
57+
withProcessingAllClinitSectionsConcretely(value = true) {
58+
check(
59+
ClassForTestClinitSections::resultDependingOnStaticSection,
60+
eq(1),
61+
{ r -> r == -1 },
62+
coverage = atLeast(71)
63+
)
64+
}
5065
}
5166
}
5267
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,19 @@ class Traverser(
483483
fieldRef: StaticFieldRef,
484484
stmt: Stmt
485485
): Boolean {
486+
// This order of processing options is important.
487+
// First, we should process classes that
488+
// cannot be analyzed without clinit sections, e.g., enums
486489
if (shouldProcessStaticFieldConcretely(fieldRef)) {
487490
return processStaticFieldConcretely(fieldRef, stmt)
488491
}
489492

490-
if (UtSettings.disableClinitSectionsAnalysis) {
493+
// Then we should check if we should analyze clinit sections at all
494+
if (!UtSettings.enableClinitSectionsAnalysis) {
491495
return false
492496
}
493497

498+
// Finally, we decide whether we should analyze clinit sections concretely or not
494499
if (UtSettings.processAllClinitSectionsConcretely) {
495500
return processStaticFieldConcretely(fieldRef, stmt)
496501
}

0 commit comments

Comments
 (0)