diff --git a/annotations/com/intellij/execution/configurations/annotations.xml b/annotations/com/intellij/execution/configurations/annotations.xml
new file mode 100644
index 00000000000..5486b733b27
--- /dev/null
+++ b/annotations/com/intellij/execution/configurations/annotations.xml
@@ -0,0 +1,5 @@
+
+ -
+
+
+
\ No newline at end of file
diff --git a/annotations/com/intellij/openapi/vfs/annotations.xml b/annotations/com/intellij/openapi/vfs/annotations.xml
new file mode 100644
index 00000000000..aa78e82ae9b
--- /dev/null
+++ b/annotations/com/intellij/openapi/vfs/annotations.xml
@@ -0,0 +1,6 @@
+
+ -
+
+
+
\ No newline at end of file
diff --git a/annotations/com/intellij/psi/stubs/annotations.xml b/annotations/com/intellij/psi/stubs/annotations.xml
new file mode 100644
index 00000000000..77d8576d860
--- /dev/null
+++ b/annotations/com/intellij/psi/stubs/annotations.xml
@@ -0,0 +1,10 @@
+
+ -
+
+
+ -
+
+
+
\ No newline at end of file
diff --git a/annotations/com/intellij/testFramework/annotations.xml b/annotations/com/intellij/testFramework/annotations.xml
index 902f6d4f9df..79fbb9a115b 100644
--- a/annotations/com/intellij/testFramework/annotations.xml
+++ b/annotations/com/intellij/testFramework/annotations.xml
@@ -7,6 +7,9 @@
name='com.intellij.testFramework.LightProjectDescriptor void configureModule(com.intellij.openapi.module.Module, com.intellij.openapi.roots.ModifiableRootModel, com.intellij.openapi.roots.ContentEntry) 1'>
+ -
+
+
-
diff --git a/annotations/com/intellij/util/annotations.xml b/annotations/com/intellij/util/annotations.xml
index 01e6a7e5584..b8e4ab96ac5 100644
--- a/annotations/com/intellij/util/annotations.xml
+++ b/annotations/com/intellij/util/annotations.xml
@@ -2,6 +2,9 @@
-
+ -
+
+
-
diff --git a/idea/testData/run/MainInTest/module/src/SrcFile.kt b/idea/testData/run/MainInTest/module/src/SrcFile.kt
new file mode 100644
index 00000000000..622567f3d7c
--- /dev/null
+++ b/idea/testData/run/MainInTest/module/src/SrcFile.kt
@@ -0,0 +1,5 @@
+package some
+
+fun foo() {
+
+}
diff --git a/idea/testData/run/MainInTest/module/test/WithMain.kt b/idea/testData/run/MainInTest/module/test/WithMain.kt
new file mode 100644
index 00000000000..445ae3a09de
--- /dev/null
+++ b/idea/testData/run/MainInTest/module/test/WithMain.kt
@@ -0,0 +1,5 @@
+package some
+
+fun main(args: Array) {
+
+}
diff --git a/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt
new file mode 100644
index 00000000000..372cfffef98
--- /dev/null
+++ b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2010-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.run
+
+import com.intellij.testFramework.PlatformTestCase
+import com.intellij.codeInsight.CodeInsightTestCase
+import com.intellij.testFramework.PsiTestUtil
+import com.intellij.psi.PsiDocumentManager
+import org.jetbrains.jet.plugin.PluginTestCaseBase
+import com.intellij.testFramework.MapDataContext
+import com.intellij.execution.actions.ConfigurationContext
+import com.intellij.execution.PsiLocation
+import com.intellij.execution.Location
+import com.intellij.openapi.actionSystem.CommonDataKeys
+import com.intellij.openapi.actionSystem.LangDataKeys
+import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex
+import com.intellij.psi.search.GlobalSearchScope
+import com.intellij.execution.configurations.RunConfiguration
+import com.intellij.execution.configurations.RunProfileState
+import com.intellij.execution.executors.DefaultRunExecutor
+import com.intellij.execution.Executor
+import com.intellij.execution.configurations.RunProfile
+import com.intellij.execution.runners.ExecutionEnvironment
+import com.intellij.execution.configurations.JavaParameters
+import org.junit.Assert
+import com.intellij.execution.configurations.JavaCommandLine
+import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.util.Computable
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.module.Module
+
+class RunConfigurationTest: CodeInsightTestCase() {
+ private val project: Project get() = myProject!!
+ private val module: Module get() = myModule!!
+
+ fun testMainInTest() {
+ val outDirs = configureModule(getTestDataPath() + getTestName(false) + "/module")
+
+ val runConfiguration = createRunConfiguration("some.main")
+ val javaParameters = getJavaRunParameters(runConfiguration)
+
+ Assert.assertTrue(javaParameters.getClassPath().getRootDirs().contains(outDirs.src))
+ Assert.assertTrue(javaParameters.getClassPath().getRootDirs().contains(outDirs.test))
+ }
+
+ private fun createRunConfiguration(mainFqn: String): RunConfiguration {
+ val mainFunction = JetTopLevelFunctionsFqnNameIndex.getInstance()!!.get(
+ mainFqn, project, GlobalSearchScope.allScope(project))!!.first();
+
+ val dataContext = MapDataContext()
+ dataContext.put(CommonDataKeys.PROJECT, project)
+ dataContext.put(LangDataKeys.MODULE, module)
+ dataContext.put(Location.DATA_KEY, PsiLocation(project, mainFunction))
+
+ return ConfigurationContext.getFromContext(dataContext)!!.getConfiguration()!!.getConfiguration()!!
+ }
+
+ private fun configureModule(moduleDir: String): ModuleOutputDirs {
+ val srcPath = moduleDir + "/src"
+ PsiTestUtil.createTestProjectStructure(project, module, srcPath, PlatformTestCase.myFilesToDelete, true)
+
+ val testPath = moduleDir + "/test"
+ val testDir = PsiTestUtil.createTestProjectStructure(project, module, testPath, PlatformTestCase.myFilesToDelete, false)
+ PsiTestUtil.addSourceRoot(getModule(), testDir, true)
+
+ val outDirs = ApplicationManager.getApplication()!!.runWriteAction(Computable {
+ val outDir = project.getBaseDir()!!.createChildDirectory(this, "out")
+ val srcOutDir = outDir.createChildDirectory(this, "production")
+ val testOutDir = outDir.createChildDirectory(this, "test")
+
+ PsiTestUtil.setCompilerOutputPath(module, srcOutDir.getUrl(), false)
+ PsiTestUtil.setCompilerOutputPath(module, testOutDir.getUrl(), true)
+
+ ModuleOutputDirs(srcOutDir, testOutDir)
+ })!!
+
+ PsiDocumentManager.getInstance(project).commitAllDocuments()
+
+ return outDirs
+ }
+
+ private fun getJavaRunParameters(configuration: RunConfiguration): JavaParameters {
+ val state = configuration.getState(MOCK_EXECUTOR, ExecutionEnvironment(MockProfile(), MOCK_EXECUTOR, myProject!!, null))
+
+ Assert.assertNotNull(state)
+ Assert.assertTrue(state is JavaCommandLine)
+
+ configuration.checkConfiguration()
+ return ((state as JavaCommandLine)).getJavaParameters()!!
+ }
+
+ override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/run/"
+ override fun getTestProjectJdk() = PluginTestCaseBase.jdkFromIdeaHome()
+
+ private data class ModuleOutputDirs(val src: VirtualFile, val test: VirtualFile)
+
+ private val MOCK_EXECUTOR: Executor = object : DefaultRunExecutor() {
+ override fun getId(): String {
+ return "mock"
+ }
+ }
+
+ private class MockProfile() : RunProfile {
+ override fun getState(executor: Executor, env: ExecutionEnvironment): RunProfileState? = null
+ override fun getIcon() = null
+ override fun getName() = null
+ }
+}