Skip to content

Commit d56aa84

Browse files
committed
Move test-specific implementation
1 parent 304b3ba commit d56aa84

File tree

12 files changed

+42
-30
lines changed

12 files changed

+42
-30
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit):
102102
return this
103103
}
104104

105-
fun UtExecutionResult.getOrThrow(): UtModel = when (this) {
106-
is UtExecutionSuccess -> model
107-
is UtExecutionFailure -> throw exception
108-
}
109-
110105
fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) {
111106
is UtExecutionFailure -> rootCauseException
112107
is UtExecutionSuccess -> null

utbot-framework-test/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ dependencies {
4848

4949
// To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section
5050
// testImplementation group: 'junit', name: 'junit', version: '4.13.1'
51-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1'
52-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1'
51+
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1'
52+
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1'
5353

5454
// used for testing code generation
5555
testImplementation group: 'commons-io', name: 'commons-io', version: commonsIoVersion

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt renamed to utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.tests.infrastructure
1+
package org.utbot.testing
22

33
import org.utbot.framework.codegen.ForceStaticMocking
44
import org.utbot.framework.codegen.Junit4
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.tests.infrastructure
1+
package org.utbot.testing
22

33
import org.utbot.common.FileUtil
44
import org.utbot.common.withAccessibility
@@ -135,7 +135,8 @@ abstract class CodeGenerationIntegrationTest(
135135
)
136136
}
137137

138-
val config = TestCodeGeneratorPipeline.defaultTestFrameworkConfiguration(language, parameterizationMode)
138+
val config =
139+
TestCodeGeneratorPipeline.defaultTestFrameworkConfiguration(language, parameterizationMode)
139140
TestCodeGeneratorPipeline(config).runClassesCodeGenerationTests(classStages)
140141
} catch (e: RuntimeException) {
141142
pipelineErrors.add(e.message)

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CompilationAndRunUtils.kt renamed to utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.tests.infrastructure
1+
package org.utbot.testing
22

33
import org.utbot.framework.plugin.api.CodegenLanguage
44
import java.io.File
@@ -33,7 +33,7 @@ fun writeTest(
3333
File(buildDirectory.toFile(), "${testClassName.substringAfterLast(".")}${generatedLanguage.extension}")
3434
)
3535

36-
logger.info {
36+
org.utbot.testing.logger.info {
3737
"File size for ${classUnderTest.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(testContents.length.toLong())}"
3838
}
3939
return writeFile(testContents, classUnderTest.generatedTestFile)
@@ -47,9 +47,9 @@ fun compileTests(
4747
val classpath = System.getProperty("java.class.path")
4848
val command = generatedLanguage.getCompilationCommand(buildDirectory, classpath, sourcesFiles)
4949

50-
logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" }
50+
org.utbot.testing.logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" }
5151
val exitCode = execCommandLine(command, "Tests compilation")
52-
logger.info { "Compilation exit code: $exitCode" }
52+
org.utbot.testing.logger.info { "Compilation exit code: $exitCode" }
5353
}
5454

5555
fun runTests(
@@ -74,7 +74,7 @@ fun runTests(
7474
additionalArguments
7575
)
7676

77-
logger.trace { "Command to run test: [${command.joinToString(" ")}]" }
77+
org.utbot.testing.logger.trace { "Command to run test: [${command.joinToString(" ")}]" }
7878

7979
// We use argument file to pass classpath, so we should just call execCommand.
8080
// Because of some reason, it is impossible to use the same approach with Junit4 and TestNg, therefore,
@@ -85,7 +85,7 @@ fun runTests(
8585
setClassPathAndExecCommandLine(command, "Tests execution", classpath)
8686
}
8787

88-
logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" }
88+
org.utbot.testing.logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" }
8989
}
9090

9191
/**
@@ -105,13 +105,13 @@ private fun constructProcess(command: List<String>, classpath: String? = null):
105105
private fun generateReportByProcess(process: Process, executionName: String, command: List<String>): Int {
106106
val report = process.inputStream.reader().readText()
107107

108-
logger.info { "$executionName report: [$report]" }
108+
org.utbot.testing.logger.info { "$executionName report: [$report]" }
109109

110110
val exitCode = process.waitFor()
111111

112112
if (exitCode != 0) {
113-
logger.warn { "Exit code for process run: $exitCode" }
114-
logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" }
113+
org.utbot.testing.logger.warn { "Exit code for process run: $exitCode" }
114+
org.utbot.testing.logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" }
115115
throw RuntimeException("$executionName failed with non-zero exit code = $exitCode")
116116
}
117117

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestCodeGeneratorPipeline.kt renamed to utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.tests.infrastructure
1+
package org.utbot.testing
22

33
import mu.KotlinLogging
44
import org.junit.jupiter.api.Assertions.assertTrue
@@ -22,6 +22,7 @@ import org.utbot.framework.plugin.api.util.UtContext
2222
import org.utbot.framework.plugin.api.util.description
2323
import org.utbot.framework.plugin.api.util.id
2424
import org.utbot.framework.plugin.api.util.withUtContext
25+
import org.utbot.testing.TestFrameworkConfiguration
2526
import java.io.File
2627
import java.nio.file.Path
2728
import kotlin.reflect.KClass
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.tests.infrastructure
1+
package org.utbot.testing
22

33
import kotlinx.coroutines.launch
44
import kotlinx.coroutines.runBlocking
@@ -20,6 +20,7 @@ import org.utbot.framework.plugin.api.util.id
2020
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
2121
import org.utbot.framework.util.Conflict
2222
import org.utbot.framework.util.jimpleBody
23+
import org.utbot.testing.conflictTriggers
2324
import java.nio.file.Path
2425

2526
/**

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtModelTestCaseChecker.kt renamed to utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@file:Suppress("NestedLambdaShadowedImplicitParameter")
22

3-
package org.utbot.tests.infrastructure
3+
package org.utbot.testing
44

55
import org.junit.jupiter.api.Assertions.assertTrue
66
import org.utbot.common.ClassLocation
@@ -25,7 +25,6 @@ import org.utbot.framework.plugin.api.UtExecutionResult
2525
import org.utbot.framework.plugin.api.UtMethodTestSet
2626
import org.utbot.framework.plugin.api.UtModel
2727
import org.utbot.framework.plugin.api.exceptionOrNull
28-
import org.utbot.framework.plugin.api.getOrThrow
2928
import org.utbot.framework.plugin.api.util.UtContext
3029
import org.utbot.framework.plugin.api.util.declaringClazz
3130
import org.utbot.framework.plugin.api.util.defaultValueModel
@@ -34,6 +33,7 @@ import org.utbot.framework.plugin.api.util.jClass
3433
import org.utbot.framework.plugin.api.util.withUtContext
3534
import org.utbot.framework.util.Conflict
3635
import org.utbot.testcheckers.ExecutionsNumberMatcher
36+
import org.utbot.testing.conflictTriggers
3737
import java.nio.file.Path
3838
import kotlin.reflect.KClass
3939
import kotlin.reflect.KFunction

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt renamed to utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@file:Suppress("NestedLambdaShadowedImplicitParameter")
22

3-
package org.utbot.tests.infrastructure
3+
package org.utbot.testing
44

55
import org.junit.jupiter.api.Assertions.assertTrue
66
import org.utbot.common.ClassLocation
@@ -54,6 +54,9 @@ import org.utbot.framework.util.Conflict
5454
import org.utbot.framework.util.toValueTestCase
5555
import org.utbot.summary.summarize
5656
import org.utbot.testcheckers.ExecutionsNumberMatcher
57+
import org.utbot.testing.TestFrameworkConfiguration
58+
import org.utbot.testing.allTestFrameworkConfigurations
59+
import org.utbot.testing.conflictTriggers
5760
import java.io.File
5861
import java.nio.file.Path
5962
import java.nio.file.Paths
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.utbot.testing
2+
3+
import org.utbot.framework.plugin.api.UtExecutionFailure
4+
import org.utbot.framework.plugin.api.UtExecutionResult
5+
import org.utbot.framework.plugin.api.UtExecutionSuccess
6+
import org.utbot.framework.plugin.api.UtModel
7+
8+
fun UtExecutionResult.getOrThrow(): UtModel = when (this) {
9+
is UtExecutionSuccess -> model
10+
is UtExecutionFailure -> throw exception
11+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.utbot.examples.mock
22

3-
import org.utbot.tests.infrastructure.UtModelTestCaseChecker
4-
import org.utbot.tests.infrastructure.primitiveValue
53
import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES
64
import org.utbot.framework.plugin.api.UtModel
7-
import org.utbot.framework.plugin.api.getOrThrow
85
import org.utbot.framework.plugin.api.isMockModel
96
import org.utbot.framework.plugin.api.isNotNull
107
import org.utbot.framework.plugin.api.isNull
118
import org.junit.jupiter.api.Test
129
import org.utbot.testcheckers.eq
10+
import org.utbot.testing.UtModelTestCaseChecker
11+
import org.utbot.testing.getOrThrow
12+
import org.utbot.testing.primitiveValue
1313

1414
internal class InnerMockWithFieldChecker : UtModelTestCaseChecker(testClass = InnerMockWithFieldExample::class) {
1515
@Test

utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.utbot.examples.mock
22

3-
import org.utbot.tests.infrastructure.UtModelTestCaseChecker
4-
import org.utbot.tests.infrastructure.primitiveValue
53
import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES
64
import org.utbot.framework.plugin.api.UtModel
7-
import org.utbot.framework.plugin.api.getOrThrow
85
import org.utbot.framework.plugin.api.isMockModel
96
import org.utbot.framework.plugin.api.isNull
107
import org.junit.jupiter.api.Test
118
import org.utbot.testcheckers.eq
9+
import org.utbot.testing.UtModelTestCaseChecker
10+
import org.utbot.testing.getOrThrow
11+
import org.utbot.testing.primitiveValue
1212

1313
internal class MockWithFieldChecker : UtModelTestCaseChecker(testClass = MockWithFieldExample::class) {
1414
@Test

0 commit comments

Comments
 (0)