Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc82c702

Browse files
committed
Minimize exceptions in signature
1 parent67cc7d9 commitc82c702

File tree

9 files changed

+50
-23
lines changed

9 files changed

+50
-23
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ data class UtExecutionSuccess(val model: UtModel) : UtExecutionResult() {
1111

1212
sealedclassUtExecutionFailure :UtExecutionResult() {
1313
abstractval exception:Throwable
14-
val isCheckedException get()=!(exceptionisRuntimeException|| exceptionisError)
1514
}
1615

1716
data classUtOverflowFailure(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packageorg.utbot.framework.plugin.api.util
2+
3+
importorg.utbot.framework.plugin.api.ClassId
4+
5+
valThrowable.description
6+
get()= message?.replace('\n','\t')?:"<Throwable with empty message>"
7+
8+
valThrowable.isCheckedException
9+
get()=!(thisisRuntimeException||thisisError)
10+
11+
valClassId.isCheckedException
12+
get()=!(RuntimeException::class.java.isAssignableFrom(this.jClass)||Error::class.java.isAssignableFrom(this.jClass))

‎utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ import org.utbot.framework.plugin.api.util.id
153153
importorg.utbot.framework.plugin.api.util.jClass
154154
importorg.utbot.framework.plugin.api.util.signature
155155
importorg.utbot.framework.plugin.api.util.utContext
156-
importorg.utbot.framework.util.description
156+
importorg.utbot.framework.plugin.api.util.description
157157
importorg.utbot.framework.util.executableId
158158
importorg.utbot.fuzzer.FuzzedMethodDescription
159159
importorg.utbot.fuzzer.ModelProvider

‎utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import org.utbot.framework.plugin.api.UtMethod
4646
importorg.utbot.framework.plugin.api.UtModel
4747
importorg.utbot.framework.plugin.api.UtReferenceModel
4848
importorg.utbot.framework.plugin.api.UtTestCase
49-
importorg.utbot.framework.plugin.api.util.executableId
5049
importjava.util.IdentityHashMap
5150
importkotlinx.collections.immutable.PersistentList
5251
importkotlinx.collections.immutable.PersistentMap
@@ -55,6 +54,11 @@ import kotlinx.collections.immutable.persistentListOf
5554
importkotlinx.collections.immutable.persistentMapOf
5655
importkotlinx.collections.immutable.persistentSetOf
5756
importorg.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
57+
importorg.utbot.framework.plugin.api.util.isSubtypeOf
58+
importorg.utbot.framework.plugin.api.util.isNotSubtypeOf
59+
importorg.utbot.framework.plugin.api.util.isCheckedException
60+
importorg.utbot.framework.plugin.api.util.id
61+
importorg.utbot.framework.plugin.api.util.executableId
5862

5963
/**
6064
* Interface for all code generation context aware entities
@@ -232,7 +236,25 @@ internal interface CgContextOwner {
232236
currentExecutable= method.callable.executableId
233237
}
234238

235-
funaddException(exception:ClassId) {
239+
funaddExceptionIfNeeded(exception:ClassId) {
240+
when (exception) {
241+
isBuiltinClassId-> {}
242+
else-> {
243+
if (exception isNotSubtypeOfThrowable::class.id) {
244+
error("Class$exception which is not a Throwable was passed")
245+
}
246+
247+
val isUnchecked=!exception.isCheckedException
248+
val alreadyAdded=
249+
collectedExceptions.any { existingException-> exception isSubtypeOf existingException }
250+
251+
if (isUnchecked|| alreadyAdded)return
252+
253+
collectedExceptions
254+
.removeIf { existingException-> existingException isSubtypeOf exception }
255+
}
256+
}
257+
236258
if (collectedExceptions.add(exception)) {
237259
importIfNeeded(exception)
238260
}
@@ -416,9 +438,9 @@ internal data class CgContext(
416438
val simpleName= testClassCustomName?:"${createTestClassName(classUnderTest.name)}Test"
417439
val name="$packagePrefix$simpleName"
418440
BuiltinClassId(
419-
name= name,
420-
canonicalName= name,
421-
simpleName= simpleName
441+
name= name,
442+
canonicalName= name,
443+
simpleName= simpleName
422444
)
423445
}
424446

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,12 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
127127
//Builtin methods does not have jClass, so [methodId.method] will crash on it,
128128
//so we need to collect required exceptions manually from source codes
129129
if (methodIdisBuiltinMethodId) {
130-
methodId.findExceptionTypes().forEach {addException(it) }
130+
methodId.findExceptionTypes().forEach {addExceptionIfNeeded(it) }
131131
return
132132
}
133-
//If [InvocationTargetException] is thrown manually in test, we need
134-
// to add "throws Throwable" and other exceptions are not required so on.
133+
135134
if (methodId== getTargetException) {
136-
collectedExceptions.clear()
137-
addException(Throwable::class.id)
138-
return
135+
addExceptionIfNeeded(Throwable::class.id)
139136
}
140137

141138
val methodIsUnderTestAndThrowsExplicitly= methodId== currentExecutable
@@ -148,13 +145,13 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
148145
return
149146
}
150147

151-
methodId.method.exceptionTypes.forEach {addException(it.id) }
148+
methodId.method.exceptionTypes.forEach {addExceptionIfNeeded(it.id) }
152149
}
153150

154151
privatefunnewConstructorCall(constructorId:ConstructorId) {
155152
importIfNeeded(constructorId.classId)
156153
for (exceptionin constructorId.exceptions) {
157-
addException(exception)
154+
addExceptionIfNeeded(exception)
158155
}
159156
}
160157

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
2626
importorg.utbot.framework.plugin.api.MethodId
2727
importorg.utbot.framework.plugin.api.UtMethod
2828
importorg.utbot.framework.plugin.api.UtTestCase
29-
importorg.utbot.framework.util.description
29+
importorg.utbot.framework.plugin.api.util.description
3030
importkotlin.reflect.KClass
3131

3232
internalclassCgTestClassConstructor(valcontext:CgContext) :

‎utbot-framework/src/main/kotlin/org/utbot/framework/util/ThrowableUtils.kt‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import org.utbot.framework.plugin.api.UtMethod
1616
importorg.utbot.framework.plugin.api.UtTestCase
1717
importorg.utbot.framework.plugin.api.util.UtContext
1818
importorg.utbot.framework.plugin.api.util.withUtContext
19-
importorg.utbot.framework.util.description
19+
importorg.utbot.framework.plugin.api.util.description
2020
importkotlin.reflect.KClass
2121
importmu.KotlinLogging
2222
importorg.junit.jupiter.api.Assertions.assertTrue

‎utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.utbot.framework.plugin.api.UtImplicitlyThrownException
1010
importorg.utbot.framework.plugin.api.UtOverflowFailure
1111
importorg.utbot.framework.plugin.api.UtTestCase
1212
importorg.utbot.framework.plugin.api.UtTimeoutException
13+
importorg.utbot.framework.plugin.api.util.isCheckedException
1314
importorg.utbot.summary.UtSummarySettings.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING
1415
importorg.utbot.summary.clustering.MatrixUniqueness
1516
importorg.utbot.summary.clustering.SplitSteps
@@ -147,8 +148,8 @@ enum class ClusterKind {
147148

148149
privatefun UtExecutionResult.clusterKind()=when (this) {
149150
isUtExecutionSuccess->ClusterKind.SUCCESSFUL_EXECUTIONS
150-
isUtImplicitlyThrownException->if (this.isCheckedException)ClusterKind.CHECKED_EXCEPTIONSelseClusterKind.ERROR_SUITE
151-
isUtExplicitlyThrownException->if (this.isCheckedException)ClusterKind.CHECKED_EXCEPTIONSelseClusterKind.EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS
151+
isUtImplicitlyThrownException->if (this.exception.isCheckedException)ClusterKind.CHECKED_EXCEPTIONSelseClusterKind.ERROR_SUITE
152+
isUtExplicitlyThrownException->if (this.exception.isCheckedException)ClusterKind.CHECKED_EXCEPTIONSelseClusterKind.EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS
152153
isUtOverflowFailure->ClusterKind.OVERFLOWS
153154
isUtTimeoutException->ClusterKind.TIMEOUTS
154155
isUtConcreteExecutionFailure->ClusterKind.CRASH_SUITE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp