diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 9561b449ae..3b789d25a8 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -162,7 +162,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : chosenClassesToMockAlways, generationTimeout ).map { - if (sourceCodeFile != null) it.summarize(sourceCodeFile.toFile(), searchDirectory) else it + if (sourceCodeFile != null) it.summarize(searchDirectory, sourceCodeFile.toFile()) else it } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt index f91141eef4..616c8a871d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt @@ -60,7 +60,7 @@ class GenerateTestsAndSarifReportFacade( sarifProperties.classesToMockAlways, sarifProperties.generationTimeout ).map { - it.summarize(targetClass.sourceCodeFile, workingDirectory) + it.summarize(workingDirectory, targetClass.sourceCodeFile) } private fun generateTestCode(targetClass: TargetClassWrapper, testSets: List): String = diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt index 74b66be154..01c880caea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt @@ -113,7 +113,7 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch fuzzingValue = params.fuzzingValue }) .apply { logger.info("generation ended, starting summarization, result size: ${this.size}") } - .map { it.summarize(Paths.get(params.searchDirectory)) } + .map { it.summarize(Paths.get(params.searchDirectory), sourceFile = null) } .apply { logger.info("summarization ended") } .filterNot { it.executions.isEmpty() && it.errors.isEmpty() } diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 41cb8aac64..c41a617309 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -403,7 +403,7 @@ fun runGeneration( val testSets = testsByMethod.map { (method, executions) -> UtMethodTestSet(method, minimizeExecutions(executions), jimpleBody(method)) - .summarize(cut.classfileDir.toPath()) + .summarize(cut.classfileDir.toPath(), sourceFile = null) } logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") { diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index b1d6bfb564..5a7ab647e8 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -3,9 +3,11 @@ package examples import org.junit.jupiter.api.* import org.utbot.common.WorkaroundReason import org.utbot.common.workaround +import org.utbot.framework.SummariesGenerationType import org.utbot.framework.UtSettings.checkNpeInNestedMethods import org.utbot.framework.UtSettings.checkNpeInNestedNotPrivateMethods import org.utbot.framework.UtSettings.checkSolverTimeoutMillis +import org.utbot.framework.UtSettings.summaryGenerationType import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId @@ -58,7 +60,7 @@ open class SummaryTestCaseGeneratorTest( checkNpeInNestedNotPrivateMethods = true } val testSet = executionsModel(method.executableId, mockStrategy) - val testSetWithSummarization = testSet.summarize(searchDirectory) + val testSetWithSummarization = testSet.summarize(searchDirectory, sourceFile = null) testSetWithSummarization.executions.checkMatchersWithTextSummary(summaryKeys) testSetWithSummarization.executions.checkMatchersWithMethodNames(methodNames) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index a1f2aafac4..a2b0cc6111 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -15,9 +15,8 @@ import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder import org.utbot.summary.name.SimpleNameBuilder import java.io.File import java.nio.file.Path -import java.nio.file.Paths import mu.KotlinLogging -import org.utbot.framework.SummariesGenerationType +import org.utbot.framework.SummariesGenerationType.* import org.utbot.framework.UtSettings.enableClusterCommentsGeneration import org.utbot.framework.UtSettings.enableJavaDocGeneration import org.utbot.framework.UtSettings.useDisplayNameArrowStyle @@ -37,21 +36,28 @@ import soot.SootMethod private val logger = KotlinLogging.logger {} -fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("")): UtMethodTestSet { - if (summaryGenerationType == SummariesGenerationType.NONE) return this +fun UtMethodTestSet.summarize(searchDirectory: Path, sourceFile: File?): UtMethodTestSet { + if (summaryGenerationType == NONE) return this + + val sourceFileToAnalyze = sourceFile + ?: when (summaryGenerationType) { + FULL -> Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory) + LIGHT, + NONE -> null + } return try { makeDiverseExecutions(this) // HACK: we avoid calling [invokeDescriptions] method to save time, it is useless in Contest val invokeDescriptions = when (summaryGenerationType) { - SummariesGenerationType.FULL -> invokeDescriptions(this, searchDirectory) - SummariesGenerationType.LIGHT, - SummariesGenerationType.NONE -> emptyList() + FULL -> invokeDescriptions(this, searchDirectory) + LIGHT, + NONE -> emptyList() } // every cluster has summary and list of executions - val executionClusters = Summarization(sourceFile, invokeDescriptions).fillSummaries(this) + val executionClusters = Summarization(sourceFileToAnalyze, invokeDescriptions).fillSummaries(this) val updatedExecutions = executionClusters.flatMap { it.executions } var pos = 0 val clustersInfo = executionClusters.map { @@ -70,13 +76,6 @@ fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.g } } -fun UtMethodTestSet.summarize(searchDirectory: Path): UtMethodTestSet = - this.summarize( - Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory), - searchDirectory - ) - - class Summarization(val sourceFile: File?, val invokeDescriptions: List) { private val tagGenerator = TagGenerator() private val jimpleBodyAnalysis = ExecutionStructureAnalysis() @@ -93,16 +92,16 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List() when (summaryGenerationType) { - SummariesGenerationType.FULL -> { + FULL -> { executionClusters += generateSummariesForTestsWithNonEmptyPathsProducedBySymbolicExecutor(testSet) executionClusters += generateFuzzerBasedSummariesForTests(testSet) executionClusters += generateSummariesForTestsWithEmptyPathsProducedBySymbolicExecutor(testSet) } - SummariesGenerationType.LIGHT -> { + LIGHT -> { executionClusters += generateFuzzerBasedSummariesForTests(testSet, MethodDescriptionSource.SYMBOLIC) executionClusters += generateFuzzerBasedSummariesForTests(testSet) } - SummariesGenerationType.NONE -> error("We must not fill summaries if SummariesGenerationType is NONE") + NONE -> error("We must not fill summaries if SummariesGenerationType is NONE") } return if (enableClusterCommentsGeneration && executionClusters.size > 0) diff --git a/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt index fe2e488d6b..50d477a9b5 100644 --- a/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt +++ b/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt @@ -2452,7 +2452,7 @@ abstract class UtValueTestCaseChecker( } else { walk(executableId, mockStrategy, additionalDependenciesClassPath) } - testSet.summarize(searchDirectory) + testSet.summarize(searchDirectory, sourceFile = null) val valueTestCase = testSet.toValueTestCase() assertTrue(testSet.errors.isEmpty()) {