Skip to content

Commit e150db0

Browse files
committed
Disable action in editor for the file located in test source root
1 parent 6513586 commit e150db0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@ class GenerateTestsAction : AnAction() {
4545

4646
if (psiElementHandler.isCreateTestActionAvailable(element)) {
4747
val srcClass = psiElementHandler.containingClass(element) ?: return null
48+
val srcSourceRoot = srcClass.getSourceRoot() ?: return null
4849
val srcMethods = TestIntegrationUtils.extractClassMethods(srcClass, false)
4950
val focusedMethod = focusedMethodOrNull(element, srcMethods, psiElementHandler)
51+
52+
val module = ModuleUtil.findModuleForFile(srcSourceRoot, project) ?: return null
53+
val matchingRoot = ModuleRootManager.getInstance(module).contentEntries
54+
.flatMap { entry -> entry.sourceFolders.toList() }
55+
.singleOrNull { folder -> folder.file == srcSourceRoot }
56+
if (matchingRoot == null || matchingRoot.rootType.isForTests) {
57+
return null
58+
}
59+
5060
return Pair(setOf(srcClass), focusedMethod)
5161
}
5262
} else {

0 commit comments

Comments
 (0)