Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cannot use scala evaluator with scalatest
Scalatest launcher extends standard java launcher both in 'run' and 'debug' modes. Unfortunately ScalaApplicationLaunchConfigDelegate' can be used in 'debug' mode only. So there is a need to expose it for 'run' mode as well. And it allows for extension of this launcher by other launcher including Scalatest one. Fix #1002447
- Loading branch information
1 parent
e773514
commit 14c5562
Showing
10 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
org.scala-ide.sdt.debug.tests/src/org/scalaide/debug/internal/launching/LaunchUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.scalaide.debug.internal.launching | ||
|
||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
import org.eclipse.core.resources.IProject | ||
import org.eclipse.core.resources.IncrementalProjectBuilder | ||
import org.eclipse.core.runtime.NullProgressMonitor | ||
import org.eclipse.debug.core.DebugPlugin | ||
import org.eclipse.debug.core.ILaunch | ||
import org.eclipse.debug.core.ILaunchConfiguration | ||
import org.eclipse.debug.core.ILaunchesListener2 | ||
|
||
/** | ||
* Used for launching application. | ||
*/ | ||
trait LaunchUtils { | ||
/** Points to launch configuration file. */ | ||
val launchConfigurationName: String | ||
|
||
private val DefaultMonitor = new NullProgressMonitor | ||
|
||
/** Create a launch listener for launchTerminated events on a launch of the given launchConfiguration. */ | ||
def onLaunchTerminates(f: () => Unit) = new ILaunchesListener2() { | ||
override def launchesTerminated(launches: Array[ILaunch]): Unit = { | ||
if (launches.exists(_.getLaunchConfiguration.getName == launchConfigurationName)) { | ||
f() | ||
} | ||
} | ||
override def launchesAdded(launches: Array[ILaunch]): Unit = {} | ||
override def launchesRemoved(launches: Array[ILaunch]): Unit = {} | ||
override def launchesChanged(launches: Array[ILaunch]): Unit = {} | ||
} | ||
|
||
/** Cleans and incrementally builds projects */ | ||
def cleanBuild(projects: IProject*): Unit = projects.foreach { project => | ||
project.build(IncrementalProjectBuilder.CLEAN_BUILD, DefaultMonitor) | ||
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, DefaultMonitor) | ||
} | ||
|
||
private def launchConfiguration(project: IProject): ILaunchConfiguration = | ||
DebugPlugin.getDefault.getLaunchManager.getLaunchConfiguration(project.getFile(launchConfigurationName + ".launch")) | ||
|
||
def whenApplicationWasLaunchedFor(project: IProject, inMode: String)(then: => Unit): Unit = { | ||
val latch = new CountDownLatch(1) | ||
DebugPlugin.getDefault.getLaunchManager.addLaunchListener(onLaunchTerminates(latch.countDown)) | ||
val lc = launchConfiguration(project) | ||
val launch = lc.launch(inMode, DefaultMonitor) | ||
val timeout = if (launch.canTerminate) 10 else 60 | ||
latch.await(timeout, TimeUnit.SECONDS) | ||
if (launch.canTerminate && !launch.isTerminated) { | ||
throw new IllegalStateException(s"launch did not terminate in ${timeout}s") | ||
} | ||
then | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...g/scalaide/debug/internal/launching/ScalaApplicationLaunchConfigurationDelegateTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.scalaide.debug.internal.launching | ||
|
||
import scala.io.Codec | ||
import scala.io.Source | ||
import scala.util.control.Exception.allCatch | ||
|
||
import org.eclipse.core.resources.IResource | ||
import org.eclipse.core.runtime.NullProgressMonitor | ||
import org.eclipse.debug.core.ILaunchManager | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.scalaide.core.testsetup.IProjectHelpers | ||
import org.scalaide.core.testsetup.TestProjectSetup | ||
|
||
import ScalaApplicationLaunchConfigurationDelegateTest.file | ||
import ScalaApplicationLaunchConfigurationDelegateTest.project | ||
|
||
object ScalaApplicationLaunchConfigurationDelegateTest | ||
extends TestProjectSetup("launchDelegate", bundleName = "org.scala-ide.sdt.debug.tests") | ||
|
||
class ScalaApplicationLaunchConfigurationDelegateTest extends LaunchUtils with IProjectHelpers { | ||
import ScalaApplicationLaunchConfigurationDelegateTest._ | ||
override val launchConfigurationName = "launchDelegate" | ||
|
||
@Before def setup(): Unit = { | ||
cleanBuild(project) | ||
} | ||
|
||
@Test def shouldLaunchTestInRunMode(): Unit = { | ||
whenApplicationWasLaunchedFor(project, ILaunchManager.RUN_MODE) { | ||
assertSideEffect(ILaunchManager.RUN_MODE) | ||
} | ||
} | ||
|
||
@Test def shouldLaunchTestInDebugMode(): Unit = { | ||
whenApplicationWasLaunchedFor(project, ILaunchManager.DEBUG_MODE) { | ||
assertSideEffect(ILaunchManager.DEBUG_MODE) | ||
} | ||
} | ||
|
||
private def assertSideEffect(inMode: String) = { | ||
project.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor) | ||
val resultFile = file("launchDelegate.result") | ||
if (resultFile.exists) { | ||
val source = Source.fromInputStream(resultFile.getContents)(Codec.UTF8) | ||
import scala.util.control.Exception._ | ||
val actual = allCatch.andFinally(source.close) opt source.mkString | ||
Assert.assertEquals("Wrong result file content", "success", actual.getOrElse("failure")) | ||
} else { | ||
Assert.fail(s"result file not found in mode '$inMode'") | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
org.scala-ide.sdt.debug.tests/test-workspace/launchDelegate/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
18 changes: 18 additions & 0 deletions
18
org.scala-ide.sdt.debug.tests/test-workspace/launchDelegate/.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>launchDelegate</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.scala-ide.sdt.core.scalabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.scala-ide.sdt.core.scalanature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
15 changes: 15 additions & 0 deletions
15
org.scala-ide.sdt.debug.tests/test-workspace/launchDelegate/launchDelegate.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="scala.application"> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/launchDelegate/src/test/ScalaTest.scala"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<mapAttribute key="org.eclipse.debug.core.preferred_launchers"> | ||
<mapEntry key="[debug]" value="scala.application.new"/> | ||
<mapEntry key="[run]" value="scala.application.new"/> | ||
</mapAttribute> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.ScalaTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="launchDelegate"/> | ||
</launchConfiguration> |
18 changes: 18 additions & 0 deletions
18
org.scala-ide.sdt.debug.tests/test-workspace/launchDelegate/src/test/ScalaTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package test | ||
|
||
import org.junit.Test | ||
import java.io.FileWriter | ||
|
||
object ScalaTest { | ||
def main(args: Array[String]): Unit = { | ||
(new ScalaTest).foo() | ||
} | ||
} | ||
|
||
class ScalaTest { | ||
def foo(): Unit = { | ||
val writer = new FileWriter("launchDelegate.result") | ||
writer.write("success") | ||
writer.close | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters