@@ -6,15 +6,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
6
6
import org.utbot.common.PathUtil.fileExtension
7
7
import org.utbot.common.PathUtil.toPath
8
8
import org.utbot.framework.UtSettings
9
- import org.utbot.framework.plugin.api.ExecutableId
10
- import org.utbot.framework.plugin.api.UtExecution
11
- import org.utbot.framework.plugin.api.UtExecutionFailure
12
- import org.utbot.framework.plugin.api.UtExecutionResult
13
- import org.utbot.framework.plugin.api.UtImplicitlyThrownException
14
- import org.utbot.framework.plugin.api.UtMethodTestSet
15
- import org.utbot.framework.plugin.api.UtModel
16
- import org.utbot.framework.plugin.api.UtOverflowFailure
17
- import org.utbot.framework.plugin.api.UtSymbolicExecution
9
+ import org.utbot.framework.plugin.api.*
18
10
19
11
/* *
20
12
* Used for the SARIF report creation by given test cases and generated tests code.
@@ -74,10 +66,10 @@ class SarifReport(
74
66
for (testSet in testSets) {
75
67
for (execution in testSet.executions) {
76
68
if (shouldProcessExecutionResult(execution.result)) {
77
- val (sarifResult, sarifRule) = processUncheckedException (
69
+ val (sarifResult, sarifRule) = processExecutionFailure (
78
70
method = testSet.method,
79
71
utExecution = execution,
80
- uncheckedException = execution.result as UtExecutionFailure
72
+ executionFailure = execution.result as UtExecutionFailure
81
73
)
82
74
sarifResults + = sarifResult
83
75
sarifRules + = sarifRule
@@ -127,14 +119,14 @@ class SarifReport(
127
119
return minimizedResults
128
120
}
129
121
130
- private fun processUncheckedException (
122
+ private fun processExecutionFailure (
131
123
method : ExecutableId ,
132
124
utExecution : UtExecution ,
133
- uncheckedException : UtExecutionFailure
125
+ executionFailure : UtExecutionFailure
134
126
): Pair <SarifResult , SarifRule > {
135
127
136
- val exceptionName = uncheckedException .exception::class .java.simpleName
137
- val ruleId = " utbot.unchecked .$exceptionName "
128
+ val exceptionName = executionFailure .exception::class .java.simpleName
129
+ val ruleId = " utbot.exception .$exceptionName "
138
130
139
131
val methodName = method.name
140
132
val classFqn = method.classId.name
@@ -146,20 +138,20 @@ class SarifReport(
146
138
Level .Error ,
147
139
Message (
148
140
text = """
149
- Unchecked exception: ${uncheckedException .exception} .
141
+ Unexpected exception: ${executionFailure .exception} .
150
142
Test case: `$methodName ($methodArguments )`
151
143
[Generated test for this case]($relatedLocationId )
152
144
""" .trimIndent()
153
145
),
154
146
getLocations(utExecution, classFqn),
155
147
getRelatedLocations(utExecution),
156
- getCodeFlows(method, utExecution, uncheckedException )
148
+ getCodeFlows(method, utExecution, executionFailure )
157
149
)
158
150
val sarifRule = SarifRule (
159
151
ruleId,
160
152
exceptionName,
161
153
SarifRule .Description (
162
- text = " Unchecked $exceptionName detected."
154
+ text = " Unexpected $exceptionName detected."
163
155
),
164
156
SarifRule .Description (
165
157
text = " Seems like an exception $exceptionName might be thrown."
@@ -205,7 +197,7 @@ class SarifReport(
205
197
private fun getCodeFlows (
206
198
method : ExecutableId ,
207
199
utExecution : UtExecution ,
208
- uncheckedException : UtExecutionFailure
200
+ executionFailure : UtExecutionFailure
209
201
): List <SarifCodeFlow > {
210
202
/* Example of a typical stack trace:
211
203
- java.lang.Math.multiplyExact(Math.java:867)
@@ -215,7 +207,7 @@ class SarifReport(
215
207
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
216
208
- ...
217
209
*/
218
- val stackTrace = uncheckedException .exception.stackTrace
210
+ val stackTrace = executionFailure .exception.stackTrace
219
211
220
212
val lastMethodCallIndex = stackTrace.indexOfLast {
221
213
it.className == method.classId.name && it.methodName == method.name
@@ -362,6 +354,7 @@ class SarifReport(
362
354
private fun shouldProcessExecutionResult (result : UtExecutionResult ): Boolean {
363
355
val implicitlyThrown = result is UtImplicitlyThrownException
364
356
val overflowFailure = result is UtOverflowFailure && UtSettings .treatOverflowAsError
365
- return implicitlyThrown || overflowFailure
357
+ val assertionError = result is UtExplicitlyThrownException && result.exception is AssertionError
358
+ return implicitlyThrown || overflowFailure || assertionError
366
359
}
367
360
}
0 commit comments