Skip to content

Commit

Permalink
Setting to disable the SARIF reports visualizer (#1184)
Browse files Browse the repository at this point in the history
Add a setting to disable built-in SARIF reports visualizer (#1167)

(cherry picked from commit e5ed167)
  • Loading branch information
mmvpm authored and denis-fokin committed Oct 20, 2022
1 parent b3ec3da commit d7d90d8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object CodeGenerationController {
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Start tests with coverage", 1.0)

invokeLater {
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)
runInspectionsIfNeeded(model, srcClassPathToSarifReport)
}
}
}
Expand All @@ -174,19 +174,22 @@ object CodeGenerationController {
* Runs the UTBot inspection if there are detected errors.
*/
private fun runInspectionsIfNeeded(
project: Project,
model: GenerateTestsModel,
srcClassPathToSarifReport: MutableMap<Path, Sarif>
) {
if (!model.runInspectionAfterTestGeneration) {
return
}
val sarifHasResults = srcClassPathToSarifReport.any { (_, sarif) ->
sarif.getAllResults().isNotEmpty()
}
if (!sarifHasResults) {
return
}
UnitTestBotInspectionManager
.getInstance(project, srcClassPathToSarifReport)
.getInstance(model.project, srcClassPathToSarifReport)
.createNewGlobalContext()
.doInspections(AnalysisScope(project))
.doInspections(AnalysisScope(model.project))
}

private fun proceedTestReport(proc: EngineProcess, model: GenerateTestsModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ data class GenerateTestsModel(
lateinit var parametrizedTestSource: ParametrizedTestSource
lateinit var runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour
lateinit var hangingTestsTimeout: HangingTestsTimeout
var runInspectionAfterTestGeneration: Boolean = false
lateinit var forceStaticMocking: ForceStaticMocking
lateinit var chosenClassesToMockAlways: Set<ClassId>
lateinit var commentStyle: JavaDocCommentStyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
var runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour = RuntimeExceptionTestsBehaviour.defaultItem,
@OptionTag(converter = HangingTestsTimeoutConverter::class)
var hangingTestsTimeout: HangingTestsTimeout = HangingTestsTimeout(),
var runInspectionAfterTestGeneration: Boolean = false,
var forceStaticMocking: ForceStaticMocking = ForceStaticMocking.defaultItem,
var treatOverflowAsError: TreatOverflowAsError = TreatOverflowAsError.defaultItem,
var parametrizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem,
Expand All @@ -66,6 +67,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
staticsMocking = model.staticsMocking,
runtimeExceptionTestsBehaviour = model.runtimeExceptionTestsBehaviour,
hangingTestsTimeout = model.hangingTestsTimeout,
runInspectionAfterTestGeneration = model.runInspectionAfterTestGeneration,
forceStaticMocking = model.forceStaticMocking,
parametrizedTestSource = model.parametrizedTestSource,
classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(),
Expand All @@ -88,6 +90,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
if (staticsMocking != other.staticsMocking) return false
if (runtimeExceptionTestsBehaviour != other.runtimeExceptionTestsBehaviour) return false
if (hangingTestsTimeout != other.hangingTestsTimeout) return false
if (runInspectionAfterTestGeneration != other.runInspectionAfterTestGeneration) return false
if (forceStaticMocking != other.forceStaticMocking) return false
if (treatOverflowAsError != other.treatOverflowAsError) return false
if (parametrizedTestSource != other.parametrizedTestSource) return false
Expand All @@ -107,6 +110,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
result = 31 * result + staticsMocking.hashCode()
result = 31 * result + runtimeExceptionTestsBehaviour.hashCode()
result = 31 * result + hangingTestsTimeout.hashCode()
result = 31 * result + runInspectionAfterTestGeneration.hashCode()
result = 31 * result + forceStaticMocking.hashCode()
result = 31 * result + treatOverflowAsError.hashCode()
result = 31 * result + parametrizedTestSource.hashCode()
Expand Down Expand Up @@ -137,6 +141,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>

val staticsMocking: StaticsMocking get() = state.staticsMocking

val runInspectionAfterTestGeneration: Boolean get() = state.runInspectionAfterTestGeneration

val forceStaticMocking: ForceStaticMocking get() = state.forceStaticMocking

val treatOverflowAsError: TreatOverflowAsError get() = state.treatOverflowAsError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsWindow(val project: Project) {

// TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement
private val excludeTable = MockAlwaysClassesTable(project)
private lateinit var runInspectionAfterTestGenerationCheckBox: JCheckBox
private lateinit var forceMockCheckBox: JCheckBox
private lateinit var enableSummarizationGenerationCheckBox: JCheckBox

Expand Down Expand Up @@ -99,6 +100,23 @@ class SettingsWindow(val project: Project) {
valuesComboBox(loader, values)
}

row {
cell {
runInspectionAfterTestGenerationCheckBox = checkBox("Display detected errors on the Problems tool window")
.onApply {
settings.state.runInspectionAfterTestGeneration = runInspectionAfterTestGenerationCheckBox.isSelected
}
.onReset {
runInspectionAfterTestGenerationCheckBox.isSelected = settings.state.runInspectionAfterTestGeneration
}
.onIsModified {
runInspectionAfterTestGenerationCheckBox.isSelected xor settings.state.runInspectionAfterTestGeneration
}
// .apply { ContextHelpLabel.create("Automatically run code inspection after test generation")() }
.component
}
}

row {
cell {
enableSummarizationGenerationCheckBox = checkBox("Enable Summaries Generation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
with(settings) {
model.runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour
model.hangingTestsTimeout = hangingTestsTimeout
model.runInspectionAfterTestGeneration = runInspectionAfterTestGeneration
model.forceStaticMocking = forceStaticMocking
model.chosenClassesToMockAlways = chosenClassesToMockAlways()
model.fuzzingValue = fuzzingValue
Expand Down

0 comments on commit d7d90d8

Please sign in to comment.