Skip to content

Commit d7d90d8

Browse files
mmvpmdenis-fokin
authored andcommitted
Setting to disable the SARIF reports visualizer (#1184)
Add a setting to disable built-in SARIF reports visualizer (#1167) (cherry picked from commit e5ed167)
1 parent b3ec3da commit d7d90d8

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object CodeGenerationController {
160160
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Start tests with coverage", 1.0)
161161

162162
invokeLater {
163-
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)
163+
runInspectionsIfNeeded(model, srcClassPathToSarifReport)
164164
}
165165
}
166166
}
@@ -174,19 +174,22 @@ object CodeGenerationController {
174174
* Runs the UTBot inspection if there are detected errors.
175175
*/
176176
private fun runInspectionsIfNeeded(
177-
project: Project,
177+
model: GenerateTestsModel,
178178
srcClassPathToSarifReport: MutableMap<Path, Sarif>
179179
) {
180+
if (!model.runInspectionAfterTestGeneration) {
181+
return
182+
}
180183
val sarifHasResults = srcClassPathToSarifReport.any { (_, sarif) ->
181184
sarif.getAllResults().isNotEmpty()
182185
}
183186
if (!sarifHasResults) {
184187
return
185188
}
186189
UnitTestBotInspectionManager
187-
.getInstance(project, srcClassPathToSarifReport)
190+
.getInstance(model.project, srcClassPathToSarifReport)
188191
.createNewGlobalContext()
189-
.doInspections(AnalysisScope(project))
192+
.doInspections(AnalysisScope(model.project))
190193
}
191194

192195
private fun proceedTestReport(proc: EngineProcess, model: GenerateTestsModel) {

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ data class GenerateTestsModel(
6767
lateinit var parametrizedTestSource: ParametrizedTestSource
6868
lateinit var runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour
6969
lateinit var hangingTestsTimeout: HangingTestsTimeout
70+
var runInspectionAfterTestGeneration: Boolean = false
7071
lateinit var forceStaticMocking: ForceStaticMocking
7172
lateinit var chosenClassesToMockAlways: Set<ClassId>
7273
lateinit var commentStyle: JavaDocCommentStyle

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
4949
var runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour = RuntimeExceptionTestsBehaviour.defaultItem,
5050
@OptionTag(converter = HangingTestsTimeoutConverter::class)
5151
var hangingTestsTimeout: HangingTestsTimeout = HangingTestsTimeout(),
52+
var runInspectionAfterTestGeneration: Boolean = false,
5253
var forceStaticMocking: ForceStaticMocking = ForceStaticMocking.defaultItem,
5354
var treatOverflowAsError: TreatOverflowAsError = TreatOverflowAsError.defaultItem,
5455
var parametrizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem,
@@ -66,6 +67,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
6667
staticsMocking = model.staticsMocking,
6768
runtimeExceptionTestsBehaviour = model.runtimeExceptionTestsBehaviour,
6869
hangingTestsTimeout = model.hangingTestsTimeout,
70+
runInspectionAfterTestGeneration = model.runInspectionAfterTestGeneration,
6971
forceStaticMocking = model.forceStaticMocking,
7072
parametrizedTestSource = model.parametrizedTestSource,
7173
classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(),
@@ -88,6 +90,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
8890
if (staticsMocking != other.staticsMocking) return false
8991
if (runtimeExceptionTestsBehaviour != other.runtimeExceptionTestsBehaviour) return false
9092
if (hangingTestsTimeout != other.hangingTestsTimeout) return false
93+
if (runInspectionAfterTestGeneration != other.runInspectionAfterTestGeneration) return false
9194
if (forceStaticMocking != other.forceStaticMocking) return false
9295
if (treatOverflowAsError != other.treatOverflowAsError) return false
9396
if (parametrizedTestSource != other.parametrizedTestSource) return false
@@ -107,6 +110,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
107110
result = 31 * result + staticsMocking.hashCode()
108111
result = 31 * result + runtimeExceptionTestsBehaviour.hashCode()
109112
result = 31 * result + hangingTestsTimeout.hashCode()
113+
result = 31 * result + runInspectionAfterTestGeneration.hashCode()
110114
result = 31 * result + forceStaticMocking.hashCode()
111115
result = 31 * result + treatOverflowAsError.hashCode()
112116
result = 31 * result + parametrizedTestSource.hashCode()
@@ -137,6 +141,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
137141

138142
val staticsMocking: StaticsMocking get() = state.staticsMocking
139143

144+
val runInspectionAfterTestGeneration: Boolean get() = state.runInspectionAfterTestGeneration
145+
140146
val forceStaticMocking: ForceStaticMocking get() = state.forceStaticMocking
141147

142148
val treatOverflowAsError: TreatOverflowAsError get() = state.treatOverflowAsError

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SettingsWindow(val project: Project) {
3535

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

@@ -99,6 +100,23 @@ class SettingsWindow(val project: Project) {
99100
valuesComboBox(loader, values)
100101
}
101102

103+
row {
104+
cell {
105+
runInspectionAfterTestGenerationCheckBox = checkBox("Display detected errors on the Problems tool window")
106+
.onApply {
107+
settings.state.runInspectionAfterTestGeneration = runInspectionAfterTestGenerationCheckBox.isSelected
108+
}
109+
.onReset {
110+
runInspectionAfterTestGenerationCheckBox.isSelected = settings.state.runInspectionAfterTestGeneration
111+
}
112+
.onIsModified {
113+
runInspectionAfterTestGenerationCheckBox.isSelected xor settings.state.runInspectionAfterTestGeneration
114+
}
115+
// .apply { ContextHelpLabel.create("Automatically run code inspection after test generation")() }
116+
.component
117+
}
118+
}
119+
102120
row {
103121
cell {
104122
enableSummarizationGenerationCheckBox = checkBox("Enable Summaries Generation")

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

+1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
510510
with(settings) {
511511
model.runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour
512512
model.hangingTestsTimeout = hangingTestsTimeout
513+
model.runInspectionAfterTestGeneration = runInspectionAfterTestGeneration
513514
model.forceStaticMocking = forceStaticMocking
514515
model.chosenClassesToMockAlways = chosenClassesToMockAlways()
515516
model.fuzzingValue = fuzzingValue

0 commit comments

Comments
 (0)