GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support AssertionError in SARIF report by mmvpm · Pull Request #1032 · UnitTestBot/UTBotJava

Support AssertionError in SARIF report #1032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
mmvpm merged 1 commit into main from ideaseeker/support_assertion_error
Oct 3, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

Support AssertionError in SARIF report #1032

Changes from all commits
Commits
Show all changes
1 commit
Select commit
56dd6c4
Support AssertionError in SARIF report
mmvpm Sep 29, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

35 changes: 14 additions & 21 deletions 35 utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
import org.utbot.common.PathUtil.fileExtension
import org.utbot.common.PathUtil.toPath
import org.utbot.framework.UtSettings
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtExecutionFailure
import org.utbot.framework.plugin.api.UtExecutionResult
import org.utbot.framework.plugin.api.UtImplicitlyThrownException
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtOverflowFailure
import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.framework.plugin.api.*

/**
* Used for the SARIF report creation by given test cases and generated tests code.
Expand Down Expand Up @@ -74,10 +66,10 @@ class SarifReport(
for (testSet in testSets) {
for (execution in testSet.executions) {
if (shouldProcessExecutionResult(execution.result)) {
val (sarifResult, sarifRule) = processUncheckedException(
val (sarifResult, sarifRule) = processExecutionFailure(
method = testSet.method,
utExecution = execution,
uncheckedException = execution.result as UtExecutionFailure
executionFailure = execution.result as UtExecutionFailure
)
sarifResults += sarifResult
sarifRules += sarifRule
Expand Down Expand Up @@ -127,14 +119,14 @@ class SarifReport(
return minimizedResults
}

private fun processUncheckedException(
private fun processExecutionFailure(
method: ExecutableId,
utExecution: UtExecution,
uncheckedException: UtExecutionFailure
executionFailure: UtExecutionFailure
): Pair<SarifResult, SarifRule> {

val exceptionName = uncheckedException.exception::class.java.simpleName
val ruleId = "utbot.unchecked.$exceptionName"
val exceptionName = executionFailure.exception::class.java.simpleName
val ruleId = "utbot.exception.$exceptionName"

val methodName = method.name
val classFqn = method.classId.name
Expand All @@ -146,20 +138,20 @@ class SarifReport(
Level.Error,
Message(
text = """
Unchecked exception: ${uncheckedException.exception}.
Unexpected exception: ${executionFailure.exception}.
Test case: `$methodName($methodArguments)`
[Generated test for this case]($relatedLocationId)
""".trimIndent()
),
getLocations(utExecution, classFqn),
getRelatedLocations(utExecution),
getCodeFlows(method, utExecution, uncheckedException)
getCodeFlows(method, utExecution, executionFailure)
)
val sarifRule = SarifRule(
ruleId,
exceptionName,
SarifRule.Description(
text = "Unchecked $exceptionName detected."
text = "Unexpected $exceptionName detected."
),
SarifRule.Description(
text = "Seems like an exception $exceptionName might be thrown."
Expand Down Expand Up @@ -205,7 +197,7 @@ class SarifReport(
private fun getCodeFlows(
method: ExecutableId,
utExecution: UtExecution,
uncheckedException: UtExecutionFailure
executionFailure: UtExecutionFailure
): List<SarifCodeFlow> {
/* Example of a typical stack trace:
- java.lang.Math.multiplyExact(Math.java:867)
Expand All @@ -215,7 +207,7 @@ class SarifReport(
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- ...
*/
val stackTrace = uncheckedException.exception.stackTrace
val stackTrace = executionFailure.exception.stackTrace

val lastMethodCallIndex = stackTrace.indexOfLast {
it.className == method.classId.name && it.methodName == method.name
Expand Down Expand Up @@ -362,6 +354,7 @@ class SarifReport(
private fun shouldProcessExecutionResult(result: UtExecutionResult): Boolean {
val implicitlyThrown = result is UtImplicitlyThrownException
val overflowFailure = result is UtOverflowFailure && UtSettings.treatOverflowAsError
return implicitlyThrown || overflowFailure
val assertionError = result is UtExplicitlyThrownException && result.exception is AssertionError
return implicitlyThrown || overflowFailure || assertionError
}
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.