Skip to content

Commit

Permalink
Fix assertions (#1096)
Browse files Browse the repository at this point in the history
(cherry picked from commit 677c15c)
  • Loading branch information
SBOne-Kenobi authored and denis-fokin committed Oct 5, 2022
1 parent d5ae1fc commit 775a38b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ object UtSettings : AbstractSettings(
*/
var treatOverflowAsError: Boolean by getBooleanProperty(false)

/**
* Generate tests that treat assertions as error suits.
*
* True by default.
*/
var treatAssertAsErrorSuit: Boolean by getBooleanProperty(true)

/**
* Instrument all classes before start
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.isException
import org.utbot.testcheckers.eq

class JavaAssertTest : UtValueTestCaseChecker(testClass = JavaAssert::class){
class JavaAssertTest : UtValueTestCaseChecker(
testClass = JavaAssert::class,
testCodeGeneration = false
) {
@Test
fun testAssertPositive() {
checkWithException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import org.utbot.summary.SummarySentenceConstants.TAB
import java.lang.reflect.InvocationTargetException
import java.security.AccessControlException
import java.lang.reflect.ParameterizedType
import org.utbot.framework.UtSettings

private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings?

Expand Down Expand Up @@ -361,6 +362,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
if (exception is AccessControlException) return false
// tests with timeout or crash should be processed differently
if (exception is TimeoutException || exception is ConcreteExecutionFailureException) return false
if (UtSettings.treatAssertAsErrorSuit && exception is AssertionError) return false

val exceptionRequiresAssert = exception !is RuntimeException || runtimeExceptionTestsBehaviour == PASS
val exceptionIsExplicit = execution.result is UtExplicitlyThrownException
Expand Down

0 comments on commit 775a38b

Please sign in to comment.