diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt index 44aa51e5f3..5ec1f5172e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt @@ -2,12 +2,7 @@ package org.utbot.sarif import org.junit.Test import org.mockito.Mockito -import org.utbot.framework.plugin.api.ExecutableId -import org.utbot.framework.plugin.api.UtExecution -import org.utbot.framework.plugin.api.UtImplicitlyThrownException -import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.UtMethodTestSet -import org.utbot.framework.plugin.api.UtSymbolicExecution +import org.utbot.framework.plugin.api.* class SarifReportTest { @@ -137,6 +132,19 @@ class SarifReportTest { } } + @Test + fun testProcessSandboxFailure() { + mockUtMethodNames() + + val uncheckedException = Mockito.mock(java.security.AccessControlException::class.java) + Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf()) + Mockito.`when`(mockUtExecution.result).thenReturn(UtSandboxFailure(uncheckedException)) + + val report = sarifReportMain.createReport() + val result = report.runs.first().results.first() + assert(result.message.text.contains("AccessControlException")) + } + @Test fun testCodeFlowsStartsWithMethodCall() { mockUtMethodNames() diff --git a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt index 670e76e4f9..78a0485bc8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt @@ -207,7 +207,7 @@ class SarifReport( // prepending stack trace by `method` call in generated tests val methodCallLocation: SarifPhysicalLocation? = - findMethodCallInTestBody(utExecution.testMethodName, method.name) + findMethodCallInTestBody(utExecution.testMethodName, method.name, utExecution) if (methodCallLocation != null) { val testFileName = sourceFinding.testsRelativePath.toPath().fileName val testClassName = testFileName.nameWithoutExtension @@ -255,9 +255,15 @@ class SarifReport( generatedTestsCode.split('\n') } - private fun findMethodCallInTestBody(testMethodName: String?, methodName: String): SarifPhysicalLocation? { + private fun findMethodCallInTestBody( + testMethodName: String?, + methodName: String, + utExecution: UtExecution, + ): SarifPhysicalLocation? { if (testMethodName == null) return null + if (utExecution.result is UtSandboxFailure) // if there is no method call in test + return getRelatedLocations(utExecution).firstOrNull()?.physicalLocation // searching needed test val testMethodStartsAt = testsBodyLines.indexOfFirst { line -> @@ -343,6 +349,7 @@ class SarifReport( val implicitlyThrown = result is UtImplicitlyThrownException val overflowFailure = result is UtOverflowFailure && UtSettings.treatOverflowAsError val assertionError = result is UtExplicitlyThrownException && result.exception is AssertionError - return implicitlyThrown || overflowFailure || assertionError + val sandboxFailure = result is UtSandboxFailure + return implicitlyThrown || overflowFailure || assertionError || sandboxFailure } } \ No newline at end of file