Skip to content

Commit a8ff3af

Browse files
committed
Merge branch 'main' into kononov-engine-process-idea
2 parents ef7a1ab + eed1557 commit a8ff3af

File tree

27 files changed

+357
-345
lines changed

27 files changed

+357
-345
lines changed

.github/workflows/build-and-run-tests.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: "UTBot Java: build and run tests"
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- 'main'
7+
- 'unit-test-bot/r**'
68
pull_request:
7-
branches: [main]
9+
branches:
10+
- 'main'
11+
- 'unit-test-bot/r**'
812

913
env:
1014
REGISTRY: ghcr.io

.github/workflows/publish-plugin-and-cli-from-branch.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
default: no-postfix
1919
options:
2020
- no-postfix
21+
- no-postfix-prod
2122
- alpha
2223
- beta
2324

@@ -42,7 +43,12 @@ jobs:
4243
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
4344
echo "VERSION="$(date +%Y).$(date +%-m).${GITHUB_RUN_NUMBER}"" >> $GITHUB_ENV
4445
echo "POSTFIX=${{ github.event.inputs.version-postfix }}" >> $GITHUB_ENV
45-
46+
47+
- name: Set production version
48+
if: ${{ github.event.inputs.version-postfix == 'no-postfix-prod' || github.event.inputs.version-postfix == 'alpha' || github.event.inputs.version-postfix == 'beta' }}
49+
run: |
50+
echo "VERSION="$(date +%Y).$(date +%-m)"" >> $GITHUB_ENV
51+
4652
- name: Create version with postfix
4753
if: ${{ (env.POSTFIX == 'alpha') || (env.POSTFIX == 'beta') }}
4854
run:

.github/workflows/publish-plugin-and-cli.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: "Plugin and CLI: publish as archives"
22
on:
33
push:
4-
branches: [main]
4+
branches:
5+
- 'main'
6+
- 'unit-test-bot/r**'
57

68
jobs:
79
publish_plugin_and_cli:

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
197197
UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR
198198

199199
return TestCaseGenerator(
200-
workingDirectory,
200+
listOf(workingDirectory),
201201
classPathNormalized,
202202
System.getProperty("java.class.path"),
203203
JdkInfoDefaultProvider().info

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object UtBotJavaApi {
114114

115115
testSets.addAll(withUtContext(utContext) {
116116
val buildPath = FileUtil.isolateClassFiles(classUnderTest).toPath()
117-
TestCaseGenerator(buildPath, classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info)
117+
TestCaseGenerator(listOf(buildPath), classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info)
118118
.generate(
119119
methodsForAutomaticGeneration.map {
120120
it.methodToBeTestedFromUserInput.executableId
@@ -174,7 +174,7 @@ object UtBotJavaApi {
174174

175175
return withUtContext(UtContext(classUnderTest.classLoader)) {
176176
val buildPath = FileUtil.isolateClassFiles(classUnderTest).toPath()
177-
TestCaseGenerator(buildPath, classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info)
177+
TestCaseGenerator(listOf(buildPath), classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info)
178178
.generate(
179179
methodsForAutomaticGeneration.map {
180180
it.methodToBeTestedFromUserInput.executableId

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ internal abstract class CgAbstractRenderer(
834834
}
835835

836836
protected open fun isAccessibleBySimpleNameImpl(classId: ClassId): Boolean =
837-
classId in context.importedClasses || classId.packageName == context.classPackageName
837+
classId in context.importedClasses ||
838+
classId.simpleName !in context.importedClasses.map { it.simpleName } && classId.packageName == context.classPackageName
838839

839840
protected abstract fun escapeNamePossibleKeywordImpl(s: String): String
840841

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ import kotlin.reflect.KCallable
5252
* Generates test cases: one by one or a whole set for the method under test.
5353
*
5454
* Note: the instantiating of [TestCaseGenerator] may take some time,
55-
* because it requires initializing Soot for the current [buildDir] and [classpath].
55+
* because it requires initializing Soot for the current [buildDirs] and [classpath].
5656
*
5757
* @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's code.
58-
* @param forceSootReload forces to reinitialize Soot even if the previous buildDir equals to [buildDir] and previous
58+
* @param forceSootReload forces to reinitialize Soot even if the previous buildDirs equals to [buildDirs] and previous
5959
* classpath equals to [classpath]. This is the case for plugin scenario, as the source code may be modified.
6060
*/
6161
open class TestCaseGenerator(
62-
private val buildDir: Path,
62+
private val buildDirs: List<Path>,
6363
private val classpath: String?,
6464
private val dependencyPaths: String,
6565
private val jdkInfo: JdkInfo,
@@ -71,21 +71,21 @@ open class TestCaseGenerator(
7171
private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout")
7272

7373
private val classpathForEngine: String
74-
get() = buildDir.toString() + (classpath?.let { File.pathSeparator + it } ?: "")
74+
get() = (buildDirs + listOfNotNull(classpath)).joinToString(File.pathSeparator)
7575

7676
init {
7777
if (!isCanceled()) {
7878
checkFrameworkDependencies(dependencyPaths)
7979

80-
logger.trace("Initializing ${this.javaClass.name} with buildDir = $buildDir, classpath = $classpath")
80+
logger.trace("Initializing ${this.javaClass.name} with buildDirs = ${buildDirs.joinToString(File.pathSeparator)}, classpath = $classpath")
8181

8282

8383
if (disableCoroutinesDebug) {
8484
System.setProperty(kotlinx.coroutines.DEBUG_PROPERTY_NAME, kotlinx.coroutines.DEBUG_PROPERTY_VALUE_OFF)
8585
}
8686

8787
timeoutLogger.trace().bracket("Soot initialization") {
88-
SootUtils.runSoot(buildDir, classpath, forceSootReload, jdkInfo)
88+
SootUtils.runSoot(buildDirs, classpath, forceSootReload, jdkInfo)
8989
}
9090

9191
//warmup
Lines changed: 70 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,7 @@
11
package org.utbot.framework.util
22

3-
import org.utbot.api.mock.UtMock
43
import org.utbot.common.FileUtil
5-
import org.utbot.engine.UtNativeStringWrapper
64
import org.utbot.engine.jimpleBody
7-
import org.utbot.engine.overrides.Boolean
8-
import org.utbot.engine.overrides.Byte
9-
import org.utbot.engine.overrides.Character
10-
import org.utbot.engine.overrides.Class
11-
import org.utbot.engine.overrides.Integer
12-
import org.utbot.engine.overrides.Long
13-
import org.utbot.engine.overrides.PrintStream
14-
import org.utbot.engine.overrides.Short
15-
import org.utbot.engine.overrides.System
16-
import org.utbot.engine.overrides.UtArrayMock
17-
import org.utbot.engine.overrides.UtLogicMock
18-
import org.utbot.engine.overrides.UtOverrideMock
19-
import org.utbot.engine.overrides.collections.AbstractCollection
20-
import org.utbot.engine.overrides.collections.AssociativeArray
21-
import org.utbot.engine.overrides.collections.Collection
22-
import org.utbot.engine.overrides.collections.List
23-
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray
24-
import org.utbot.engine.overrides.collections.UtArrayList
25-
import org.utbot.engine.overrides.collections.UtGenericAssociative
26-
import org.utbot.engine.overrides.collections.UtGenericStorage
27-
import org.utbot.engine.overrides.collections.UtHashMap
28-
import org.utbot.engine.overrides.collections.UtHashSet
29-
import org.utbot.engine.overrides.collections.UtLinkedList
30-
import org.utbot.engine.overrides.collections.UtLinkedListWithNullableCheck
31-
import org.utbot.engine.overrides.collections.UtOptional
32-
import org.utbot.engine.overrides.collections.UtOptionalDouble
33-
import org.utbot.engine.overrides.collections.UtOptionalInt
34-
import org.utbot.engine.overrides.collections.UtOptionalLong
35-
import org.utbot.engine.overrides.stream.*
36-
import org.utbot.engine.overrides.strings.UtString
37-
import org.utbot.engine.overrides.strings.UtStringBuffer
38-
import org.utbot.engine.overrides.strings.UtStringBuilder
395
import org.utbot.engine.pureJavaSignature
406
import org.utbot.framework.plugin.api.ExecutableId
417
import org.utbot.framework.plugin.services.JdkInfo
@@ -56,40 +22,40 @@ object SootUtils {
5622
*
5723
* @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's
5824
* code.
59-
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to the class buildDir.
25+
* @param forceReload forces to reinitialize Soot even if the [previousBuildDirs] equals to the class buildDir.
6026
*/
61-
fun runSoot(clazz: java.lang.Class<*>, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) {
27+
fun runSoot(clazz: Class<*>, forceReload: Boolean, jdkInfo: JdkInfo) {
6228
val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz)
6329
val buildDirPath = buildDir.toPath()
6430

65-
runSoot(buildDirPath, null, forceReload, jdkInfo)
31+
runSoot(listOf(buildDirPath), null, forceReload, jdkInfo)
6632
}
6733

6834

6935
/**
7036
* @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's
7137
* code.
72-
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to [buildDirPath] and
38+
* @param forceReload forces to reinitialize Soot even if the [previousBuildDirs] equals to [buildDirPaths] and
7339
* [previousClassPath] equals to [classPath].
7440
*/
75-
fun runSoot(buildDirPath: Path, classPath: String?, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) {
41+
fun runSoot(buildDirPaths: List<Path>, classPath: String?, forceReload: Boolean, jdkInfo: JdkInfo) {
7642
synchronized(this) {
77-
if (buildDirPath != previousBuildDir || classPath != previousClassPath || forceReload) {
78-
initSoot(buildDirPath, classPath, jdkInfo)
79-
previousBuildDir = buildDirPath
43+
if (buildDirPaths != previousBuildDirs || classPath != previousClassPath || forceReload) {
44+
initSoot(buildDirPaths, classPath, jdkInfo)
45+
previousBuildDirs = buildDirPaths
8046
previousClassPath = classPath
8147
}
8248
}
8349
}
8450

85-
private var previousBuildDir: Path? = null
51+
private var previousBuildDirs: List<Path>? = null
8652
private var previousClassPath: String? = null
8753
}
8854

8955
/**
9056
* Convert code to Jimple
9157
*/
92-
private fun initSoot(buildDir: Path, classpath: String?, jdkInfo: JdkInfo) {
58+
private fun initSoot(buildDirs: List<Path>, classpath: String?, jdkInfo: JdkInfo) {
9359
G.reset()
9460
val options = Options.v()
9561

@@ -105,7 +71,7 @@ private fun initSoot(buildDir: Path, classpath: String?, jdkInfo: JdkInfo) {
10571
+ if (!classpath.isNullOrEmpty()) File.pathSeparator + "$classpath" else ""
10672
)
10773
set_src_prec(Options.src_prec_only_class)
108-
set_process_dir(listOf("$buildDir"))
74+
set_process_dir(buildDirs.map { it.toString() })
10975
set_keep_line_number(true)
11076
set_ignore_classpath_errors(true) // gradle/build/resources/main does not exists, but it's not a problem
11177
set_output_format(Options.output_format_jimple)
@@ -141,69 +107,69 @@ fun jimpleBody(method: ExecutableId): JimpleBody =
141107
method.sootMethod.jimpleBody()
142108

143109

144-
private fun addBasicClasses(vararg classes: java.lang.Class<*>) {
110+
private fun addBasicClasses(vararg classes: Class<*>) {
145111
classes.forEach {
146112
Scene.v().addBasicClass(it.name, SootClass.BODIES)
147113
}
148114
}
149115

150116
private val classesToLoad = arrayOf(
151-
AbstractCollection::class,
152-
UtMock::class,
153-
UtOverrideMock::class,
154-
UtLogicMock::class,
155-
UtArrayMock::class,
156-
Boolean::class,
157-
Byte::class,
158-
Character::class,
159-
Class::class,
160-
Integer::class,
161-
Long::class,
162-
Short::class,
163-
System::class,
164-
UtOptional::class,
165-
UtOptionalInt::class,
166-
UtOptionalLong::class,
167-
UtOptionalDouble::class,
168-
UtArrayList::class,
169-
UtArrayList.UtArrayListIterator::class,
170-
UtLinkedList::class,
171-
UtLinkedListWithNullableCheck::class,
172-
UtLinkedList.UtLinkedListIterator::class,
173-
UtLinkedList.ReverseIteratorWrapper::class,
174-
UtHashSet::class,
175-
UtHashSet.UtHashSetIterator::class,
176-
UtHashMap::class,
177-
UtHashMap.Entry::class,
178-
UtHashMap.LinkedEntryIterator::class,
179-
UtHashMap.LinkedEntrySet::class,
180-
UtHashMap.LinkedHashIterator::class,
181-
UtHashMap.LinkedKeyIterator::class,
182-
UtHashMap.LinkedKeySet::class,
183-
UtHashMap.LinkedValueIterator::class,
184-
UtHashMap.LinkedValues::class,
185-
RangeModifiableUnlimitedArray::class,
186-
AssociativeArray::class,
187-
UtGenericStorage::class,
188-
UtGenericAssociative::class,
189-
PrintStream::class,
190-
UtNativeStringWrapper::class,
191-
UtString::class,
192-
UtStringBuilder::class,
193-
UtStringBuffer::class,
194-
Stream::class,
195-
Arrays::class,
196-
Collection::class,
197-
List::class,
198-
UtStream::class,
199-
UtIntStream::class,
200-
UtLongStream::class,
201-
UtDoubleStream::class,
202-
UtStream.UtStreamIterator::class,
203-
UtIntStream.UtIntStreamIterator::class,
204-
UtLongStream.UtLongStreamIterator::class,
205-
UtDoubleStream.UtDoubleStreamIterator::class,
206-
IntStream::class,
207-
LongStream::class,
208-
DoubleStream::class,
117+
org.utbot.engine.overrides.collections.AbstractCollection::class,
118+
org.utbot.api.mock.UtMock::class,
119+
org.utbot.engine.overrides.UtOverrideMock::class,
120+
org.utbot.engine.overrides.UtLogicMock::class,
121+
org.utbot.engine.overrides.UtArrayMock::class,
122+
org.utbot.engine.overrides.Boolean::class,
123+
org.utbot.engine.overrides.Byte::class,
124+
org.utbot.engine.overrides.Character::class,
125+
org.utbot.engine.overrides.Class::class,
126+
org.utbot.engine.overrides.Integer::class,
127+
org.utbot.engine.overrides.Long::class,
128+
org.utbot.engine.overrides.Short::class,
129+
org.utbot.engine.overrides.System::class,
130+
org.utbot.engine.overrides.collections.UtOptional::class,
131+
org.utbot.engine.overrides.collections.UtOptionalInt::class,
132+
org.utbot.engine.overrides.collections.UtOptionalLong::class,
133+
org.utbot.engine.overrides.collections.UtOptionalDouble::class,
134+
org.utbot.engine.overrides.collections.UtArrayList::class,
135+
org.utbot.engine.overrides.collections.UtArrayList.UtArrayListIterator::class,
136+
org.utbot.engine.overrides.collections.UtLinkedList::class,
137+
org.utbot.engine.overrides.collections.UtLinkedListWithNullableCheck::class,
138+
org.utbot.engine.overrides.collections.UtLinkedList.UtLinkedListIterator::class,
139+
org.utbot.engine.overrides.collections.UtLinkedList.ReverseIteratorWrapper::class,
140+
org.utbot.engine.overrides.collections.UtHashSet::class,
141+
org.utbot.engine.overrides.collections.UtHashSet.UtHashSetIterator::class,
142+
org.utbot.engine.overrides.collections.UtHashMap::class,
143+
org.utbot.engine.overrides.collections.UtHashMap.Entry::class,
144+
org.utbot.engine.overrides.collections.UtHashMap.LinkedEntryIterator::class,
145+
org.utbot.engine.overrides.collections.UtHashMap.LinkedEntrySet::class,
146+
org.utbot.engine.overrides.collections.UtHashMap.LinkedHashIterator::class,
147+
org.utbot.engine.overrides.collections.UtHashMap.LinkedKeyIterator::class,
148+
org.utbot.engine.overrides.collections.UtHashMap.LinkedKeySet::class,
149+
org.utbot.engine.overrides.collections.UtHashMap.LinkedValueIterator::class,
150+
org.utbot.engine.overrides.collections.UtHashMap.LinkedValues::class,
151+
org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray::class,
152+
org.utbot.engine.overrides.collections.AssociativeArray::class,
153+
org.utbot.engine.overrides.collections.UtGenericStorage::class,
154+
org.utbot.engine.overrides.collections.UtGenericAssociative::class,
155+
org.utbot.engine.overrides.PrintStream::class,
156+
org.utbot.engine.UtNativeStringWrapper::class,
157+
org.utbot.engine.overrides.strings.UtString::class,
158+
org.utbot.engine.overrides.strings.UtStringBuilder::class,
159+
org.utbot.engine.overrides.strings.UtStringBuffer::class,
160+
org.utbot.engine.overrides.stream.Stream::class,
161+
org.utbot.engine.overrides.stream.Arrays::class,
162+
org.utbot.engine.overrides.collections.Collection::class,
163+
org.utbot.engine.overrides.collections.List::class,
164+
org.utbot.engine.overrides.stream.UtStream::class,
165+
org.utbot.engine.overrides.stream.UtIntStream::class,
166+
org.utbot.engine.overrides.stream.UtLongStream::class,
167+
org.utbot.engine.overrides.stream.UtDoubleStream::class,
168+
org.utbot.engine.overrides.stream.UtStream.UtStreamIterator::class,
169+
org.utbot.engine.overrides.stream.UtIntStream.UtIntStreamIterator::class,
170+
org.utbot.engine.overrides.stream.UtLongStream.UtLongStreamIterator::class,
171+
org.utbot.engine.overrides.stream.UtDoubleStream.UtDoubleStreamIterator::class,
172+
org.utbot.engine.overrides.stream.IntStream::class,
173+
org.utbot.engine.overrides.stream.LongStream::class,
174+
org.utbot.engine.overrides.stream.DoubleStream::class,
209175
).map { it.java }.toTypedArray()

0 commit comments

Comments
 (0)