@@ -5,6 +5,7 @@ import org.utbot.framework.UtSettings
5
5
import org.utbot.framework.plugin.api.UtClusterInfo
6
6
import org.utbot.framework.plugin.api.UtExecution
7
7
import org.utbot.framework.plugin.api.UtExecutionCluster
8
+ import org.utbot.framework.plugin.api.UtExecutionCreator
8
9
import org.utbot.framework.plugin.api.UtMethodTestSet
9
10
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
10
11
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
@@ -75,29 +76,50 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
75
76
val updatedExecutions = mutableListOf<UtExecution >()
76
77
val clustersToReturn = mutableListOf<UtExecutionCluster >()
77
78
78
- // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428
79
- val executionsProducedByFuzzer = getExecutionsWithEmptyPath( testSet)
79
+ // handles tests produced by fuzzing
80
+ val executionsProducedByFuzzer = testSet.executions.filter { it.createdBy == UtExecutionCreator . FUZZER }
80
81
81
82
if (executionsProducedByFuzzer.isNotEmpty()) {
82
83
executionsProducedByFuzzer.forEach {
83
84
logger.info {
84
- " The path for test ${it.testMethodName} " +
85
+ " Test is created by Fuzzing. The path for test ${it.testMethodName} " +
85
86
" for method ${testSet.method.clazz.qualifiedName} is empty and summaries could not be generated."
86
87
}
87
88
}
88
89
89
90
clustersToReturn.add(
90
91
UtExecutionCluster (
91
- UtClusterInfo (),
92
+ UtClusterInfo (), // TODO: add something https://github.com/UnitTestBot/UTBotJava/issues/430
92
93
executionsProducedByFuzzer
93
94
)
94
95
)
95
96
}
96
97
98
+ // handles tests produced by symbolic engine, but with empty paths
99
+ val executionsWithEmptyPaths = getExecutionsCreatedBySymbolicEngineWithEmptyPath(testSet)
100
+
101
+ if (executionsWithEmptyPaths.isNotEmpty()) {
102
+ executionsWithEmptyPaths.forEach {
103
+ logger.info {
104
+ " Test is created by Symbolic Engine. The path for test ${it.testMethodName} " +
105
+ " for method ${testSet.method.clazz.qualifiedName} is empty and summaries could not be generated."
106
+ }
107
+ }
108
+
109
+ clustersToReturn.add(
110
+ UtExecutionCluster (
111
+ UtClusterInfo (), // TODO: https://github.com/UnitTestBot/UTBotJava/issues/430
112
+ executionsWithEmptyPaths
113
+ )
114
+ )
115
+ }
116
+
117
+ val testSetForAnalysis = prepareTestSetForByteCodeAnalysis(testSet)
118
+
97
119
// analyze
98
120
if (jimpleBody != null && sootToAST != null ) {
99
121
val methodUnderTest = jimpleBody.method
100
- val clusteredTags = tagGenerator.testSetToTags(testSet )
122
+ val clusteredTags = tagGenerator.testSetToTags(testSetForAnalysis )
101
123
jimpleBodyAnalysis.traceStructuralAnalysis(jimpleBody, clusteredTags, methodUnderTest, invokeDescriptions)
102
124
val numberOfSuccessfulClusters = clusteredTags.filter { it.isSuccessful }.size
103
125
for (clusterTraceTags in clusteredTags) {
@@ -108,21 +130,22 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
108
130
&& clusterTraceTags.traceTags.size > 1 // add if there is more than 1 execution
109
131
) {
110
132
SimpleClusterCommentBuilder (clusterTraceTags.commonStepsTraceTag, sootToAST)
111
- .buildString(methodUnderTest)
112
- .takeIf { it.isNotBlank() }
113
- ?.let {
114
- buildString {
115
- append(" ${NEW_LINE } Common steps:" )
116
- append(" $NEW_LINE$it " )
117
- }
133
+ .buildString(methodUnderTest)
134
+ .takeIf { it.isNotBlank() }
135
+ ?.let {
136
+ buildString {
137
+ append(" ${NEW_LINE } Common steps:" )
138
+ append(" $NEW_LINE$it " )
118
139
}
140
+ }
119
141
} else {
120
142
null
121
143
}
122
144
123
145
for (traceTags in clusterTraceTags.traceTags) {
124
146
if (GENERATE_COMMENTS ) {
125
- traceTags.execution.summary = SimpleCommentBuilder (traceTags, sootToAST).buildDocStmts(methodUnderTest)
147
+ traceTags.execution.summary =
148
+ SimpleCommentBuilder (traceTags, sootToAST).buildDocStmts(methodUnderTest)
126
149
}
127
150
128
151
if (GENERATE_DISPLAY_NAMES || GENERATE_NAMES ) {
@@ -164,8 +187,21 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
164
187
return listOf (UtExecutionCluster (UtClusterInfo (), testSet.executions))
165
188
}
166
189
167
- private fun getExecutionsWithEmptyPath (testSet : UtMethodTestSet ) =
168
- testSet.executions.filter { it.path.isEmpty() }
190
+ private fun prepareTestSetForByteCodeAnalysis (testSet : UtMethodTestSet ): UtMethodTestSet {
191
+ val executions =
192
+ testSet.executions.filterNot { it.createdBy == UtExecutionCreator .FUZZER || (it.createdBy == UtExecutionCreator .SYMBOLIC_ENGINE && it.path.isEmpty()) }
193
+
194
+ return UtMethodTestSet (
195
+ method = testSet.method,
196
+ executions = executions,
197
+ jimpleBody = testSet.jimpleBody,
198
+ errors = testSet.errors,
199
+ clustersInfo = testSet.clustersInfo
200
+ )
201
+ }
202
+
203
+ private fun getExecutionsCreatedBySymbolicEngineWithEmptyPath (testSet : UtMethodTestSet ) =
204
+ testSet.executions.filter { it.createdBy == UtExecutionCreator .SYMBOLIC_ENGINE && it.path.isEmpty() }
169
205
170
206
/*
171
207
* asts of invokes also included
0 commit comments