Skip to content

Test report for multiple classes #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class UtContext(val classLoader: ClassLoader) : ThreadContextElement<UtContext?>
}
}

inline fun <T> withUtContext(context: UtContext, block: () -> T): T = setUtContext(context).use { block() }
inline fun <T> withUtContext(context: UtContext, block: () -> T): T = setUtContext(context).use { block() }
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package org.utbot.engine.util.mockListeners
import org.utbot.engine.EngineController
import org.utbot.engine.MockStrategy
import org.utbot.engine.UtMockInfo
import org.utbot.framework.util.Conflict
import org.utbot.framework.util.ConflictTriggers

/**
* Listener for mocker events in [org.utbot.engine.UtBotSymbolicEngine].
* If forced mock happened, cancels the engine job.
*
* Supposed to be created only if Mockito is not installed.
*/
class ForceMockListener: MockListener {
var forceMockHappened = false
private set

class ForceMockListener(triggers: ConflictTriggers): MockListener(triggers) {
override fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) {
// If force mocking happened -- сancel engine job
controller.job?.cancel(ForceMockCancellationException())
forceMockHappened = true

triggers[Conflict.ForceMockHappened] = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import org.utbot.engine.UtMockInfo
import org.utbot.engine.UtNewInstanceMockInfo
import org.utbot.engine.UtStaticMethodMockInfo
import org.utbot.engine.UtStaticObjectMockInfo
import org.utbot.framework.util.Conflict
import org.utbot.framework.util.ConflictTriggers

/**
* Listener for mocker events in [org.utbot.engine.UtBotSymbolicEngine].
* If forced static mock happened, cancels the engine job.
*
* Supposed to be created only if Mockito inline is not installed.
*/
class ForceStaticMockListener: MockListener {
var forceStaticMockHappened = false
private set

class ForceStaticMockListener(triggers: ConflictTriggers): MockListener(triggers) {
override fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) {
if (mockInfo is UtNewInstanceMockInfo
|| mockInfo is UtStaticMethodMockInfo
|| mockInfo is UtStaticObjectMockInfo) {
// If force static mocking happened -- сancel engine job
controller.job?.cancel(ForceStaticMockCancellationException())
forceStaticMockHappened = true

triggers[Conflict.ForceStaticMockHappened] = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package org.utbot.engine.util.mockListeners
import org.utbot.engine.EngineController
import org.utbot.engine.MockStrategy
import org.utbot.engine.UtMockInfo
import org.utbot.framework.util.ConflictTriggers

/**
* Listener that can be attached using [MockListenerController] to mocker in [org.utbot.engine.UtBotSymbolicEngine].
*/
interface MockListener {
fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo)
abstract class MockListener(
val triggers: ConflictTriggers
) {
abstract fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.io.File
import java.net.URLClassLoader
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.concurrent.TimeUnit

fun List<UtInstrumentation>.singleStaticMethod(methodName: String) =
Expand Down Expand Up @@ -139,4 +140,17 @@ fun compileClassFile(className: String, snippet: Snippet): File {
require(javacFinished) { "Javac can't complete in $timeout sec" }

return File(workdir.toFile(), "${sourceCodeFile.nameWithoutExtension}.class")
}

enum class Conflict {
ForceMockHappened,
ForceStaticMockHappened,
TestFrameworkConflict,
}

class ConflictTriggers(
private val triggers: MutableMap<Conflict, Boolean> = EnumMap<Conflict, Boolean>(Conflict::class.java).withDefault { false }
): MutableMap<Conflict, Boolean> by triggers {
val triggered: Boolean
get() = triggers.values.any { it }
}
Loading