Skip to content

Commit 74ff9aa

Browse files
authoredJul 12, 2022
Show exception stack trace if it happened in user code #368 (#477)
1 parent 91b98d6 commit 74ff9aa

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed
 

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import org.utbot.framework.plugin.api.ClassId
9494
import org.utbot.framework.plugin.api.CodegenLanguage
9595
import org.utbot.framework.plugin.api.ConcreteExecutionFailureException
9696
import org.utbot.framework.plugin.api.ConstructorId
97+
import org.utbot.framework.plugin.api.ExecutableId
9798
import org.utbot.framework.plugin.api.FieldId
9899
import org.utbot.framework.plugin.api.MethodId
99100
import org.utbot.framework.plugin.api.TimeoutException
@@ -155,6 +156,7 @@ import org.utbot.framework.plugin.api.util.shortWrapperClassId
155156
import org.utbot.framework.plugin.api.util.stringClassId
156157
import org.utbot.framework.plugin.api.util.voidClassId
157158
import org.utbot.framework.util.isUnit
159+
import org.utbot.summary.SummarySentenceConstants.TAB
158160
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
159161
import java.lang.reflect.InvocationTargetException
160162
import kotlin.reflect.jvm.javaType
@@ -396,13 +398,26 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
396398
}
397399

398400
private fun writeWarningAboutFailureTest(exception: Throwable) {
399-
+CgMultilineComment(
400-
listOf(
401-
"This test fails because executable under testing $currentExecutable",
402-
"produces Runtime exception $exception",
403-
)
404-
// TODO add stacktrace JIRA:1644
401+
require(currentExecutable is ExecutableId)
402+
val executableName = "${currentExecutable!!.classId.name}.${currentExecutable!!.name}"
403+
404+
val warningLine = mutableListOf(
405+
"This test fails because method [$executableName] produces [$exception]"
405406
)
407+
408+
val neededStackTraceLines = mutableListOf<String>()
409+
var executableCallFound = false
410+
exception.stackTrace.reversed().forEach { stackTraceElement ->
411+
val line = stackTraceElement.toString()
412+
if (line.startsWith(executableName)) {
413+
executableCallFound = true
414+
}
415+
if (executableCallFound) {
416+
neededStackTraceLines += TAB + line
417+
}
418+
}
419+
420+
+CgMultilineComment(warningLine + neededStackTraceLines.reversed())
406421
}
407422

408423
private fun writeWarningAboutCrash() {

0 commit comments

Comments
 (0)