Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8daca8

Browse files
Fix internal UTBot timeout exception rendering in summaries #1832 (#1865)
Fix timeout error rendering in summaries
1 parent 6cfc285 commit d8daca8

File tree

8 files changed

+81
-18
lines changed

8 files changed

+81
-18
lines changed

‎utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ArtificialErrors.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,4 @@ sealed class ArtificialError(message: String): Error(message)
1515
*
1616
* See [TraversalContext.intOverflowCheck] for more details.
1717
*/
18-
class OverflowDetectionError(message: String): ArtificialError(message)
19-
20-
fun ArtificialError.getPrettyName(): String =
21-
when (this) {
22-
is OverflowDetectionError -> "Overflow"
23-
}
18+
class OverflowDetectionError(message: String): ArtificialError(message)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package org.utbot.framework.plugin.api.util
22

3+
import org.utbot.framework.plugin.api.OverflowDetectionError
4+
import org.utbot.framework.plugin.api.TimeoutException
5+
36
val Throwable.description
47
get() = message?.replace('\n', '\t') ?: "<Throwable with empty message>"
58

69
val Throwable.isCheckedException
710
get() = !(this is RuntimeException || this is Error)
811

12+
val Throwable.prettyName
13+
get() = when (this) {
14+
is OverflowDetectionError -> "Overflow"
15+
is TimeoutException -> "Timeout"
16+
else -> this::class.simpleName
17+
}
18+
919
val Class<*>.isCheckedException
1020
get() = !(RuntimeException::class.java.isAssignableFrom(this) || Error::class.java.isAssignableFrom(this))

‎utbot-sample/src/main/java/org/utbot/examples/exceptions/ExceptionExamples.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public IllegalArgumentException createException() {
102102
return new IllegalArgumentException("Here we are: " + Math.sqrt(10));
103103
}
104104

105+
public int hangForSeconds(int seconds) throws InterruptedException {
106+
for (int i = 0; i < seconds; i++) {
107+
Thread.sleep(1000);
108+
}
109+
return seconds;
110+
}
111+
105112
public int dontCatchDeepNestedThrow(int i) {
106113
return callNestedWithThrow(i);
107114
}

‎utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,43 @@ class SummaryExceptionExampleTest : SummaryTestCaseGeneratorTest(
5858

5959
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
6060
}
61+
62+
@Test
63+
fun testHangForSeconds() {
64+
val summary1 = "@utbot.classUnderTest {@link ExceptionExamples}\n" +
65+
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionExamples#hangForSeconds(int)}\n" +
66+
"@utbot.returnsFrom {@code return seconds;}\n"
67+
val summary2 = "@utbot.classUnderTest {@link ExceptionExamples}\n" +
68+
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionExamples#hangForSeconds(int)}\n" +
69+
"@utbot.iterates iterate the loop {@code for(int i = 0; i < seconds; i++)} once\n" +
70+
"@utbot.returnsFrom {@code return seconds;}\n" +
71+
"@utbot.detectsSuspiciousBehavior in: return seconds;\n"
72+
73+
val methodName1 = "testHangForSeconds_ReturnSeconds"
74+
val methodName2 = "testHangForSeconds_ThreadSleep"
75+
76+
val displayName1 = "-> return seconds"
77+
val displayName2 = "return seconds -> TimeoutExceeded"
78+
79+
val summaryKeys = listOf(
80+
summary1,
81+
summary2
82+
)
83+
84+
val displayNames = listOf(
85+
displayName1,
86+
displayName2
87+
)
88+
89+
val methodNames = listOf(
90+
methodName1,
91+
methodName2
92+
)
93+
94+
val method = ExceptionExamples::hangForSeconds
95+
val mockStrategy = MockStrategyApi.NO_MOCKS
96+
val coverage = DoNotCalculate
97+
98+
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
99+
}
61100
}

‎utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.utbot.framework.plugin.api.DocPreTagStatement
1313
import org.utbot.framework.plugin.api.DocRegularStmt
1414
import org.utbot.framework.plugin.api.DocStatement
1515
import org.utbot.framework.plugin.api.Step
16+
import org.utbot.framework.plugin.api.TimeoutException
1617
import org.utbot.framework.plugin.api.exceptionOrNull
1718
import org.utbot.summary.AbstractTextBuilder
1819
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
@@ -70,6 +71,7 @@ open class SimpleCommentBuilder(
7071
val reason = findExceptionReason(currentMethod, it)
7172

7273
when (it) {
74+
is TimeoutException,
7375
is ArtificialError -> root.detectedError = reason
7476
else -> root.exceptionThrow = "$exceptionName $reason"
7577
}

‎utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.summary.comment.customtags.symbolic
33
import org.utbot.framework.plugin.api.ArtificialError
44
import org.utbot.framework.plugin.api.DocCustomTagStatement
55
import org.utbot.framework.plugin.api.DocStatement
6+
import org.utbot.framework.plugin.api.TimeoutException
67
import org.utbot.framework.plugin.api.exceptionOrNull
78
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
89
import org.utbot.summary.ast.JimpleToASTMap
@@ -58,6 +59,7 @@ class CustomJavaDocCommentBuilder(
5859
.replace(CARRIAGE_RETURN, "")
5960

6061
when (thrownException) {
62+
is TimeoutException,
6163
is ArtificialError -> comment.detectsSuspiciousBehavior = reason
6264
else -> comment.throwsException = "{@link $exceptionName} $reason"
6365
}

‎utbot-summary/src/main/kotlin/org/utbot/summary/name/NameUtil.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package org.utbot.summary.name
22

33
import org.utbot.framework.plugin.api.ArtificialError
44
import org.utbot.framework.plugin.api.Step
5-
import org.utbot.framework.plugin.api.getPrettyName
5+
import org.utbot.framework.plugin.api.TimeoutException
6+
import org.utbot.framework.plugin.api.util.prettyName
67
import org.utbot.summary.tag.UniquenessTag
78
import soot.SootMethod
89

@@ -51,7 +52,16 @@ data class TestNameDescription(
5152
}
5253

5354
enum class NameType {
54-
Condition, Return, Invoke, SwitchCase, CaughtException, NoIteration, ThrowsException, StartIteration, ArtificialError
55+
Condition,
56+
Return,
57+
Invoke,
58+
SwitchCase,
59+
CaughtException,
60+
NoIteration,
61+
ThrowsException,
62+
StartIteration,
63+
ArtificialError,
64+
TimeoutError
5565
}
5666

5767
data class DisplayNameCandidate(val name: String, val uniquenessTag: UniquenessTag, val index: Int)
@@ -66,18 +76,20 @@ fun List<TestNameDescription>.returnsToUnique() = this.map {
6676
}
6777

6878
fun buildNameFromThrowable(exception: Throwable): String? {
69-
val exceptionName = exception::class.simpleName
79+
val exceptionName = exception.prettyName
7080

7181
if (exceptionName.isNullOrEmpty()) return null
7282
return when (exception) {
73-
is ArtificialError -> "Detect${exception.getPrettyName()}"
83+
is TimeoutException -> "${exception.prettyName}Exceeded"
84+
is ArtificialError -> "Detect${exception.prettyName}"
7485
else -> "Throw$exceptionName"
7586
}
7687
}
7788

7889
fun getThrowableNameType(exception: Throwable): NameType {
7990
return when (exception) {
8091
is ArtificialError -> NameType.ArtificialError
92+
is TimeoutException -> NameType.TimeoutError
8193
else -> NameType.ThrowsException
8294
}
8395
}

‎utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,10 @@ class SimpleNameBuilder(
146146
}
147147

148148
private fun fromNameDescriptionToCandidateSimpleName(nameDescription: TestNameDescription): DisplayNameCandidate? {
149-
if (nameDescription.nameType == NameType.ArtificialError) {
150-
return DisplayNameCandidate(
151-
nameDescription.name,
152-
nameDescription.uniquenessTag,
153-
traceTag.path.size + 1
154-
)
155-
}
156-
if (nameDescription.nameType == NameType.ThrowsException) {
149+
if (nameDescription.nameType == NameType.ArtificialError ||
150+
nameDescription.nameType == NameType.TimeoutError ||
151+
nameDescription.nameType == NameType.ThrowsException
152+
) {
157153
return DisplayNameCandidate(
158154
nameDescription.name,
159155
nameDescription.uniquenessTag,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /