Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename UtValueTestCase to UtMethodValueTestSet and remove relevan…
…t parts
  • Loading branch information
sergeypospelov committed Jul 13, 2022
commit ba1ac51f86caa37b377744f901a0ca0ac0ec2e4e
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

package org.utbot.framework.plugin.api

import kotlin.reflect.KClass
import org.apache.commons.lang3.builder.RecursiveToStringStyle
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
import soot.jimple.JimpleBody

data class UtValueTestCase<R>(
data class UtMethodValueTestSet<R>(
val method: UtMethod<out R>,
val executions: List<UtValueExecution<out R>> = emptyList(),
val jimpleBody: JimpleBody? = null,
val errors: Map<String, Int> = emptyMap(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.framework.coverage

import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtValueExecution
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.UtMethodValueTestSet
import org.utbot.framework.plugin.api.util.signature
import org.utbot.framework.util.anyInstance
import org.utbot.instrumentation.ConcreteExecutor
Expand Down Expand Up @@ -140,7 +140,7 @@ class MemoryClassLoader : ClassLoader() {
}
}

fun classCoverage(testCases: List<UtValueTestCase<*>>): Coverage =
fun classCoverage(testCases: List<UtMethodValueTestSet<*>>): Coverage =
testCases.map { methodCoverageWithJaCoCo(it.method, it.executions) }.toClassCoverage()

fun methodCoverageWithJaCoCo(utMethod: UtMethod<*>, executions: List<UtValueExecution<*>>): Coverage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.utbot.framework.plugin.api.MissingState
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.UtMethodValueTestSet
import org.utbot.framework.plugin.api.UtVoidModel
import org.utbot.framework.plugin.api.classId
import org.utbot.framework.plugin.api.id
Expand All @@ -17,7 +17,6 @@ import org.utbot.framework.plugin.api.util.methodId
import org.utbot.framework.plugin.api.util.objectClassId
import java.util.concurrent.atomic.AtomicInteger
import soot.SootMethod
import soot.jimple.JimpleBody


@Suppress("DEPRECATION")
Expand Down Expand Up @@ -74,9 +73,9 @@ val instanceCounter = AtomicInteger(0)

fun nextModelName(base: String): String = "$base${instanceCounter.incrementAndGet()}"

fun UtMethodTestSet.toValueTestCase(jimpleBody: JimpleBody? = null): UtValueTestCase<*> {
fun UtMethodTestSet.toValueTestCase(): UtMethodValueTestSet<*> {
val valueExecutions = executions.map { ValueConstructor().construct(it) }
return UtValueTestCase(method, valueExecutions, jimpleBody, errors)
return UtMethodValueTestSet(method, valueExecutions, errors)
}

fun UtModel.isUnit(): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import org.utbot.framework.plugin.api.UtValueExecution
import org.utbot.framework.plugin.api.util.UtContext
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.withUtContext
import org.utbot.framework.util.jimpleBody
import org.utbot.framework.util.toValueTestCase
import org.utbot.summary.summarize
import java.io.File
Expand Down Expand Up @@ -2343,7 +2342,7 @@ abstract class UtValueTestCaseChecker(
walk(utMethod, mockStrategy, additionalDependenciesClassPath)
}
testCase.summarize(searchDirectory)
val valueTestCase = testCase.toValueTestCase(jimpleBody(utMethod))
val valueTestCase = testCase.toValueTestCase()

assertTrue(testCase.errors.isEmpty()) {
"We have errors: ${
Expand Down Expand Up @@ -2478,10 +2477,9 @@ abstract class UtValueTestCaseChecker(
additionalDependenciesClassPath: String = ""
): MethodResult {
val testCase = executions(method, mockStrategy, additionalDependenciesClassPath)
val jimpleBody = jimpleBody(method)
val methodCoverage = methodCoverage(
method,
testCase.toValueTestCase(jimpleBody).executions,
testCase.toValueTestCase().executions,
buildDir.toString() + File.pathSeparator + additionalDependenciesClassPath
)
return MethodResult(testCase, methodCoverage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.utbot.framework.plugin.api.UtMethod;
import org.utbot.framework.plugin.api.UtValueExecution;
import org.utbot.framework.plugin.api.UtValueTestCase;
import org.utbot.framework.plugin.api.UtMethodValueTestSet;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
Expand Down Expand Up @@ -38,11 +38,11 @@ private static boolean isSameMethod(UtMethod<?> utMethod, Method method) {
return utJavaMethod.equals(method);
}

public static UtValueTestCase<?> generateTests(UtMethod<?> method) throws IllegalAccessException, InstantiationException {
public static UtMethodValueTestSet<?> generateTests(UtMethod<?> method) throws IllegalAccessException, InstantiationException {
KClass<?> kClass = method.getClazz();
Class<?> clazz = JvmClassMappingKt.getJavaClass(kClass);
// TODO: newInstance() is deprecated, need to create an instance in another way
Object object = clazz.newInstance();
return new UtValueTestCase<>(method, executions(method, clazz, object), null, emptyMap());
return new UtMethodValueTestSet<>(method, executions(method, clazz, object), emptyMap());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.utbot.fuzzer

import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.UtMethodValueTestSet

interface ObsoleteTestCaseGenerator {
fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*>
fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.UtConcreteValue
import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtValueExecution
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.UtMethodValueTestSet
import org.utbot.fuzzer.ObsoleteTestCaseGenerator
import org.utbot.fuzzer.baseline.generator.Generator
import kotlin.Result.Companion.failure
import kotlin.Result.Companion.success

object BaselineFuzzer : ObsoleteTestCaseGenerator {
override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*> =
override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*> =
Generator.generateTests(method)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.UtConcreteValue
import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtValueExecution
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.UtMethodValueTestSet
import org.utbot.fuzzer.ObsoleteTestCaseGenerator
import kotlin.Result.Companion.success
import kotlin.reflect.KCallable
Expand All @@ -13,8 +13,8 @@ import kotlin.reflect.KParameter.Kind
import kotlin.reflect.KType

object PrimitiveFuzzer : ObsoleteTestCaseGenerator {
override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*> =
UtValueTestCase(method, executions(method.callable))
override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*> =
UtMethodValueTestSet(method, executions(method.callable))
}

private fun executions(method: KCallable<Any?>) = listOf(execution(method))
Expand Down
19 changes: 0 additions & 19 deletions utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.utbot.framework.plugin.api.UtError
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.framework.plugin.api.UtValueTestCase
import org.utbot.framework.plugin.api.util.UtContext
import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.jClass
Expand All @@ -43,9 +42,6 @@ import org.utbot.framework.plugin.api.util.withUtContext
import org.utbot.instrumentation.ConcreteExecutor
import org.utbot.instrumentation.ConcreteExecutorPool
import org.utbot.instrumentation.Settings
import org.utbot.instrumentation.execute
import org.utbot.instrumentation.instrumentation.coverage.CoverageInstrumentation
import org.utbot.instrumentation.util.StaticEnvironment
import org.utbot.instrumentation.warmup.Warmup
import java.io.File
import java.lang.reflect.Method
Expand Down Expand Up @@ -423,21 +419,6 @@ fun runGeneration(
statsForClass
}

private fun ConcreteExecutor<Result<*>, CoverageInstrumentation>.executeTestCase(testCase: UtValueTestCase<*>) {
testCase.executions.forEach {
val method = testCase.method.callable
for (execution in testCase.executions) {
val args = (listOfNotNull(execution.stateBefore.caller) + execution.stateBefore.params)
.map { it.value }.toMutableList()
val staticEnvironment = StaticEnvironment(
execution.stateBefore.statics.map { it.key to it.value.value }
)
this.execute(method, args.toTypedArray(), parameters = staticEnvironment)
}
}

}

private fun prepareClass(kotlinClass: KClass<*>, methodNameFilter: String?): List<UtMethod<*>> {
//1. all methods and properties from cut
val kotlin2java = kotlinClass.declaredMembers
Expand Down