Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 677c15c

Browse files
authoredOct 5, 2022
Fix assertions (#1096)
1 parent c34324a commit 677c15c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

‎utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ object UtSettings : AbstractSettings(
240240
*/
241241
var treatOverflowAsError: Boolean by getBooleanProperty(false)
242242

243+
/**
244+
* Generate tests that treat assertions as error suits.
245+
*
246+
* True by default.
247+
*/
248+
var treatAssertAsErrorSuit: Boolean by getBooleanProperty(true)
249+
243250
/**
244251
* Instrument all classes before start
245252
*/

‎utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import org.utbot.tests.infrastructure.UtValueTestCaseChecker
55
import org.utbot.tests.infrastructure.isException
66
import org.utbot.testcheckers.eq
77

8-
class JavaAssertTest : UtValueTestCaseChecker(testClass = JavaAssert::class){
8+
class JavaAssertTest : UtValueTestCaseChecker(
9+
testClass = JavaAssert::class,
10+
testCodeGeneration = false
11+
) {
912
@Test
1013
fun testAssertPositive() {
1114
checkWithException(

‎utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import org.utbot.summary.SummarySentenceConstants.TAB
149149
import java.lang.reflect.InvocationTargetException
150150
import java.security.AccessControlException
151151
import java.lang.reflect.ParameterizedType
152+
import org.utbot.framework.UtSettings
152153

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

@@ -365,6 +366,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
365366
if (exception is AccessControlException) return false
366367
// tests with timeout or crash should be processed differently
367368
if (exception is TimeoutException || exception is ConcreteExecutionFailureException) return false
369+
if (UtSettings.treatAssertAsErrorSuit && exception is AssertionError) return false
368370

369371
val exceptionRequiresAssert = exception !is RuntimeException || runtimeExceptionTestsBehaviour == PASS
370372
val exceptionIsExplicit = execution.result is UtExplicitlyThrownException

0 commit comments

Comments
 (0)
Please sign in to comment.