Skip to content

Commit

Permalink
Add sandbox failures to SARIF report (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmvpm committed Nov 14, 2022
1 parent 6d7339f commit 1c9571e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
}
}

0 comments on commit 1c9571e

Please sign in to comment.