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

Commitb9fc3da

Browse files
Remember Test Sources root choice and suggest as default#1010 (#1519)
1 parent2ae6fb7 commitb9fc3da

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

‎utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GenerateTestsModel(
3737
potentialTestModules,
3838
srcClasses
3939
) {
40-
40+
overridevar sourceRootHistory= project.service<Settings>().sourceRootHistory
4141
overridevar codegenLanguage= project.service<Settings>().codegenLanguage
4242

4343
lateinitvar testFramework:TestFramework

‎utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.utbot.framework.plugin.api.isSummarizationCompatible
4444
)
4545
classSettings(valproject:Project) : PersistentStateComponent<Settings.State> {
4646
data classState(
47+
varsourceRootHistory:MutableList<String> = mutableListOf(),
4748
varcodegenLanguage:CodegenLanguage =CodegenLanguage.defaultItem,
4849
@OptionTag(converter=TestFrameworkConverter::class)
4950
vartestFramework:TestFramework =TestFramework.defaultItem,
@@ -65,6 +66,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
6566
varenableSummariesGeneration:Boolean =UtSettings.enableSummariesGeneration
6667
) {
6768
constructor(model:GenerateTestsModel):this(
69+
sourceRootHistory= model.sourceRootHistory,
6870
codegenLanguage= model.codegenLanguage,
6971
testFramework= model.testFramework,
7072
mockStrategy= model.mockStrategy,
@@ -88,6 +90,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
8890

8991
otherasState
9092

93+
if (sourceRootHistory!= other.sourceRootHistory)returnfalse
9194
if (codegenLanguage!= other.codegenLanguage)returnfalse
9295
if (testFramework!= other.testFramework)returnfalse
9396
if (mockStrategy!= other.mockStrategy)returnfalse
@@ -108,7 +111,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
108111
returntrue
109112
}
110113
overridefunhashCode():Int {
111-
var result= codegenLanguage.hashCode()
114+
var result= sourceRootHistory.hashCode()
115+
result=31* result+ codegenLanguage.hashCode()
112116
result=31* result+ testFramework.hashCode()
113117
result=31* result+ mockStrategy.hashCode()
114118
result=31* result+ mockFramework.hashCode()
@@ -129,6 +133,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
129133
}
130134

131135
privatevar state=State()
136+
val sourceRootHistory:MutableList<String> get()= state.sourceRootHistory
132137

133138
val codegenLanguage:CodegenLanguage get()= state.codegenLanguage
134139

‎utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
519519
}catch (ignored:ParseException) {
520520
}
521521
model.timeout=TimeUnit.SECONDS.toMillis(timeoutSpinner.number.toLong())
522+
model.testSourceRoot?.apply { model.updateSourceRootHistory(this.toNioPath().toString()) }
522523

523524
val settings= model.project.service<Settings>()
524525
with(settings) {

‎utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/models/BaseTestModel.kt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.utbot.intellij.plugin.ui.utils.isBuildWithGradle
1414
importorg.utbot.intellij.plugin.ui.utils.suitableTestSourceRoots
1515

1616
valPsiClass.packageName:String get()=this.containingFile.containingDirectory.getPackage()?.qualifiedName?:""
17+
constvalHISTORY_LIMIT=10
1718

1819
openclassBaseTestsModel(
1920
valproject:Project,
@@ -27,6 +28,7 @@ open class BaseTestsModel(
2728

2829
var testSourceRoot:VirtualFile?=null
2930
var testPackageName:String?=null
31+
openvar sourceRootHistory:MutableList<String>=mutableListOf()
3032
openlateinitvar codegenLanguage:CodegenLanguage
3133

3234
funsetSourceRootAndFindTestModule(newTestSourceRoot:VirtualFile?) {
@@ -50,8 +52,15 @@ open class BaseTestsModel(
5052

5153
fungetAllTestSourceRoots() :MutableList<outITestSourceRoot> {
5254
with(if (project.isBuildWithGradle) project.allModules()else potentialTestModules) {
53-
returnthis.flatMap { it.suitableTestSourceRoots().toList() }.toMutableList()
55+
returnthis.flatMap { it.suitableTestSourceRoots().toList() }.toMutableList().distinct().toMutableList()
5456
}
5557
}
5658

59+
funupdateSourceRootHistory(path:String) {
60+
sourceRootHistory.apply {
61+
remove(path)//Remove existing entry if any
62+
add(path)//Add the most recent entry to the end to be brought first at sorting, see org.utbot.intellij.plugin.ui.utils.RootUtilsKt.getSortedTestRoots
63+
while (size>HISTORY_LIMIT) removeFirst()
64+
}
65+
}
5766
}

‎utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class TestFolderComboWithBrowseButton(private val model: BaseTestsModel) :
6060

6161
val testRoots= getSortedTestRoots(
6262
model.getAllTestSourceRoots(),
63+
model.sourceRootHistory,
6364
model.srcModule.rootManager.sourceRoots.map { file:VirtualFile-> file.toNioPath().toString() },
6465
model.codegenLanguage
6566
)

‎utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/RootUtils.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const val SRC_MAIN = "src/main/"
7171
*/
7272
fungetSortedTestRoots(
7373
allTestRoots:MutableList<outITestSourceRoot>,
74+
sourceRootHistory:List<String>,
7475
moduleSourcePaths:List<String>,
7576
codegenLanguage:CodegenLanguage
7677
):MutableList<ITestSourceRoot> {
@@ -88,6 +89,9 @@ fun getSortedTestRoots(
8889
}.thenByDescending {
8990
// Heuristics: dedicated test source root named 'utbot_tests' should go first
9091
it.dirName== dedicatedTestSourceRootName
92+
}.thenByDescending {
93+
// Recent used root should be handy too
94+
sourceRootHistory.indexOf(it.dirPath)
9195
}.thenBy {
9296
// ABC-sorting
9397
it.dirPath

‎utbot-ui-commons/src/test/kotlin/org/utbot/intellij/plugin/ui/utils/RootUtilsTest.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ internal class RootUtilsTest {
5656
"/UTBotJavaTest/utbot-framework/src/main/kotlin",
5757
"/UTBotJavaTest/utbot-framework/src/main/resources",
5858
)
59-
val sortedTestRoots= getSortedTestRoots(allTestRoots, moduleSourcePaths,CodegenLanguage.JAVA)
59+
val sortedTestRoots= getSortedTestRoots(
60+
allTestRoots,
61+
listOf("/UTBotJavaTest/utbot-core/src/test/java"),
62+
moduleSourcePaths,
63+
CodegenLanguage.JAVA
64+
)
6065
Assertions.assertEquals("/UTBotJavaTest/utbot-framework/src/test/java", sortedTestRoots.first().toString())
66+
Assertions.assertEquals("/UTBotJavaTest/utbot-core/src/test/java", sortedTestRoots[1].toString())
6167
}
6268
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp