Skip to content

Commit

Permalink
Adds test for stack frame source path validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wpopielarski committed Jan 13, 2017
1 parent 3d687ee commit 343e4b0
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
Expand Up @@ -45,6 +45,7 @@ import org.scalaide.debug.internal.model.ScalaJdiEventDispatcherTest
classOf[StackFrameVariableOfTreeFinderTest],
classOf[ScalaApplicationLaunchConfigurationDelegateTest],
classOf[ScalaJUnitLaunchConfigurationDelegateTest],
classOf[ScalaJdiEventDispatcherTest]
classOf[ScalaJdiEventDispatcherTest],
classOf[SourcePathInStackFrameTest]
))
class ScalaDebugTestSuite
@@ -0,0 +1,76 @@
package org.scalaide.debug.internal

import java.io.File

import org.eclipse.core.resources.IncrementalProjectBuilder
import org.eclipse.core.runtime.NullProgressMonitor
import org.junit.After
import org.junit.AfterClass
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.scalaide.core.testsetup.SDTTestUtils
import org.scalaide.core.testsetup.TestProjectSetup

object SourcePathInStackFrameTest extends TestProjectSetup("source-path", bundleName = "org.scala-ide.sdt.debug.tests") with ScalaDebugRunningTest {
final val BP_TYPENAME = "test.a.Main"

var initialized = false

def initDebugSession(launchConfigurationName: String): ScalaDebugTestSession = ScalaDebugTestSession(file(launchConfigurationName + ".launch"))

@AfterClass
def deleteProject(): Unit = {
SDTTestUtils.deleteProjects(project)
}
}

class SourcePathInStackFrameTest {
import SourcePathInStackFrameTest._

var session: ScalaDebugTestSession = null

@Before
def initializeTests(): Unit = {
SDTTestUtils.enableAutoBuild(false)
if (!initialized) {
project.underlying.build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor)
project.underlying.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor)
initialized = true
}
}

@After
def cleanDebugSession(): Unit = {
if (session ne null) {
session.terminate()
session = null
}
}

private val mainBreakpoint = 16
private val expectedSourcePath = File.separator + "test" + File.separator + "SourcePath.scala"
@Test
def simpleCheckForSourcePathInTopMostStackFrameForClassesWithPkgsWhichDontReflectSourceFoldersStruct(): Unit = {
session = initDebugSession("SourcePath")
session.runToLine(BP_TYPENAME, mainBreakpoint)
Assert.assertTrue(session.currentStackFrame.getSourcePath == expectedSourcePath)

val bp4 = session.addLineBreakpoint("test.b.B", 4)
val bp8 = session.addLineBreakpoint("test.b.c.C", 8)
try {
session.waitForBreakpointsToBeEnabled(bp4, bp8)

session.resumeToSuspension()
Assert.assertTrue(session.currentStackFrame.getSourcePath == expectedSourcePath)

session.resumeToSuspension()
Assert.assertTrue(session.currentStackFrame.getSourcePath == expectedSourcePath)

session.resumeToCompletion()
} finally {
bp4.delete()
bp8.delete()
}
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
18 changes: 18 additions & 0 deletions org.scala-ide.sdt.debug.tests/test-workspace/source-path/.project
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>source-path</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>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="scala.application">
<stringAttribute key="bad_container_name" value="/source-path/f"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/source-path/src/test/SourcePath.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"/>
</mapAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.a.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="source-path"/>
</launchConfiguration>
@@ -0,0 +1,21 @@
package test {
package b {
class B {
def foo = 5
}
package c {
trait C {
def bar = 7
}
}
}
package a {
import test.b.c.C
object Main extends App with C {
import test.b.B
val b = new B
println(b.foo)
println(bar)
}
}
}

0 comments on commit 343e4b0

Please sign in to comment.