@@ -451,56 +451,69 @@ class UtBotSymbolicEngine(
451
451
EnvironmentModels (values.first().model, emptyList(), mapOf ())
452
452
}
453
453
454
- try {
455
- val concreteExecutionResult =
456
- concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf ())
454
+ val concreteExecutionResult: UtConcreteExecutionResult ? = try {
455
+ concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf ())
456
+ } catch (e: CancellationException ) {
457
+ logger.debug { " Cancelled by timeout" }; null
458
+ } catch (e: ConcreteExecutionFailureException ) {
459
+ emitFailedConcreteExecutionResult(initialEnvironmentModels, e); null
460
+ } catch (e: Throwable ) {
461
+ emit(UtError (" Default concrete execution failed" , e)); null
462
+ }
457
463
458
- workaround(REMOVE_ANONYMOUS_CLASSES ) {
459
- concreteExecutionResult.result.onSuccess {
460
- if (it.classId.isAnonymous) {
461
- logger.debug(" Anonymous class found as a concrete result, symbolic one will be returned" )
462
- return @flow
463
- }
464
+ // in case an exception occurred from the concrete execution
465
+ concreteExecutionResult ? : return @forEach
466
+
467
+ workaround(REMOVE_ANONYMOUS_CLASSES ) {
468
+ concreteExecutionResult.result.onSuccess {
469
+ if (it.classId.isAnonymous) {
470
+ logger.debug(" Anonymous class found as a concrete result, symbolic one will be returned" )
471
+ return @flow
464
472
}
465
473
}
474
+ }
466
475
467
- val count = coveredInstructionTracker.add(concreteExecutionResult.coverage.coveredInstructions)
476
+ val coveredInstructions = concreteExecutionResult.coverage.coveredInstructions
477
+ if (coveredInstructions.isNotEmpty()) {
478
+ val count = coveredInstructionTracker.add(coveredInstructions)
468
479
if (count.count > 1 ) {
469
480
if (-- attempts < 0 ) {
470
481
return @flow
471
482
}
472
483
return @forEach
473
484
}
474
485
coveredInstructionValues[count] = values
475
- val nameSuggester = sequenceOf(ModelBasedNameSuggester (), MethodBasedNameSuggester ())
476
- val testMethodName = try {
477
- nameSuggester.flatMap { it.suggest(methodUnderTestDescription, values, concreteExecutionResult.result) }.firstOrNull()
478
- } catch (t: Throwable ) {
479
- logger.error(t) { " Cannot create suggested test name for ${methodUnderTest.displayName} " }
480
- null
481
- }
482
-
483
- emit(
484
- UtExecution (
485
- stateBefore = initialEnvironmentModels,
486
- stateAfter = concreteExecutionResult.stateAfter,
487
- result = concreteExecutionResult.result,
488
- instrumentation = emptyList(),
489
- path = mutableListOf (),
490
- fullPath = emptyList(),
491
- coverage = concreteExecutionResult.coverage,
492
- createdBy = UtExecutionCreator .FUZZER ,
493
- testMethodName = testMethodName?.testName,
494
- displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName
486
+ } else {
487
+ logger.error { " Coverage is empty for $methodUnderTest with ${values.map { it.model }} " }
488
+ }
489
+ val nameSuggester = sequenceOf(ModelBasedNameSuggester (), MethodBasedNameSuggester ())
490
+ val testMethodName = try {
491
+ nameSuggester.flatMap {
492
+ it.suggest(
493
+ methodUnderTestDescription,
494
+ values,
495
+ concreteExecutionResult.result
495
496
)
496
- )
497
- } catch (e: CancellationException ) {
498
- logger.debug { " Cancelled by timeout" }
499
- } catch (e: ConcreteExecutionFailureException ) {
500
- emitFailedConcreteExecutionResult(initialEnvironmentModels, e)
501
- } catch (e: Throwable ) {
502
- emit(UtError (" Default concrete execution failed" , e))
497
+ }.firstOrNull()
498
+ } catch (t: Throwable ) {
499
+ logger.error(t) { " Cannot create suggested test name for ${methodUnderTest.displayName} " }
500
+ null
503
501
}
502
+
503
+ emit(
504
+ UtExecution (
505
+ stateBefore = initialEnvironmentModels,
506
+ stateAfter = concreteExecutionResult.stateAfter,
507
+ result = concreteExecutionResult.result,
508
+ instrumentation = emptyList(),
509
+ path = mutableListOf (),
510
+ fullPath = emptyList(),
511
+ coverage = concreteExecutionResult.coverage,
512
+ createdBy = UtExecutionCreator .FUZZER ,
513
+ testMethodName = testMethodName?.testName,
514
+ displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName
515
+ )
516
+ )
504
517
}
505
518
}
506
519
0 commit comments