Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added code launch selected Scala Test suite.

  • Loading branch information...
commit 39484f83bbd85b88d99ded9b0c40ce2c416de378 1 parent 73fd098
@cheeseng authored
View
26 org.scala-ide.sdt.core/src/scala/tools/eclipse/launching/ScalaTestLaunchDelegate.scala
@@ -2,18 +2,15 @@ package scala.tools.eclipse.launching
import org.eclipse.jdt.launching.{AbstractJavaLaunchConfigurationDelegate, JavaRuntime,
IRuntimeClasspathEntry, VMRunnerConfiguration, ExecutionArguments}
-
import scala.tools.eclipse.ScalaPlugin
-
import java.io.File
import com.ibm.icu.text.MessageFormat
-
import org.eclipse.core.runtime.{Path, CoreException, IProgressMonitor, NullProgressMonitor}
import org.eclipse.debug.core.{ILaunch, ILaunchConfiguration}
import org.eclipse.jdt.internal.launching.LaunchingMessages
-
import scala.collection.JavaConversions._
import scala.collection.mutable
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants
class ScalaTestLaunchDelegate extends AbstractJavaLaunchConfigurationDelegate {
def launch(configuration: ILaunchConfiguration, mode: String, launch: ILaunch, monitor0: IProgressMonitor) {
@@ -28,17 +25,20 @@ class ScalaTestLaunchDelegate extends AbstractJavaLaunchConfigurationDelegate {
try {
monitor.subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1)
- val mainTypeName = verifyMainTypeName(configuration)
+ val mainTypeName = "org.scalatest.tools.Runner"
val runner = getVMRunner(configuration, mode)
val workingDir = verifyWorkingDirectory(configuration)
- val workingDirName = if (workingDir != null) workingDir.getAbsolutePath() else null
+ val workingDirName = if (workingDir != null) workingDir.getAbsolutePath() else null
// Environment variables
val envp = getEnvironment(configuration)
+ // Test Class
+ val testClass = getTestClass(configuration)
+
// Program & VM arguments
- val pgmArgs = getProgramArguments(configuration)
+ val pgmArgs = getProgramArguments(configuration) + " -s " + testClass + " -oW -g"
val vmArgs = getVMArguments(configuration)
val execArgs = new ExecutionArguments(vmArgs, pgmArgs)
@@ -110,8 +110,12 @@ class ScalaTestLaunchDelegate extends AbstractJavaLaunchConfigurationDelegate {
}
}
- private def resolveClasspath(a: IRuntimeClasspathEntry, configuration: ILaunchConfiguration): List[String] = {
- val bootEntry = JavaRuntime.resolveRuntimeClasspath(Array(a), configuration)
- bootEntry.toList.map(_.getLocation())
- }
+ private def resolveClasspath(a: IRuntimeClasspathEntry, configuration: ILaunchConfiguration): List[String] = {
+ val bootEntry = JavaRuntime.resolveRuntimeClasspath(Array(a), configuration)
+ bootEntry.toList.map(_.getLocation())
+ }
+
+ private def getTestClass(configuration: ILaunchConfiguration): String = {
+ configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "")
+ }
}
View
23 org.scala-ide.sdt.core/src/scala/tools/eclipse/launching/ScalaTestLaunchShortcut.scala
@@ -29,6 +29,9 @@ import org.scalatest.finders.Selection
import java.net.URLClassLoader
import java.net.URL
import java.io.File
+import org.eclipse.debug.core.DebugPlugin
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants
+import org.eclipse.debug.ui.DebugUITools
class ScalaTestLaunchShortcut extends ILaunchShortcut {
@@ -44,12 +47,30 @@ class ScalaTestLaunchShortcut extends ILaunchShortcut {
case Some(selection) =>
println("***Test Found, display name: " + selection.displayName() + ", test name(s):")
selection.testNames.foreach(println(_))
+
+ val configType = getLaunchManager.getLaunchConfigurationType("scala.scalatest")
+ val existingConfigs = getLaunchManager.getLaunchConfigurations(configType)
+ val existingConfigOpt = existingConfigs.find(config => config.getName == selection.displayName)
+ val config = existingConfigOpt match {
+ case Some(existingConfig) => existingConfig
+ case None =>
+ val wc = configType.newInstance(null, getLaunchManager.generateUniqueLaunchConfigurationNameFrom(selection.displayName))
+ val project = editorPart.getEditorInput.asInstanceOf[IFileEditorInput].getFile.getProject
+ val scProject = ScalaPlugin.plugin.getScalaProject(project)
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, selection.className)
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName)
+ wc.doSave
+ }
+ DebugUITools.launch(config, mode)
+
case None =>
println("#####Launch all suites within the source file")
}
}
- def resolveSelectedAst(editorPart: IEditorPart, typeRoot: ITypeRoot): Option[Selection] = {
+ private def getLaunchManager = DebugPlugin.getDefault.getLaunchManager
+
+ private def resolveSelectedAst(editorPart: IEditorPart, typeRoot: ITypeRoot): Option[Selection] = {
val selectionProvider:ISelectionProvider = editorPart.getSite().getSelectionProvider()
if(selectionProvider == null)
None
View
2  org.scala-ide.sdt.core/src/scala/tools/eclipse/launching/ScalaTestMainTab.scala
@@ -160,7 +160,7 @@ class ScalaTestMainTab extends SharedJavaMainTab {
}
name = fMainText.getText.trim
if (name.length == 0) {
- setErrorMessage(LauncherMessages.JavaMainTab_Main_type_not_specified_16)
+ setErrorMessage("Test Class cannot be empty.")
return false
}
return true
Please sign in to comment.
Something went wrong with that request. Please try again.