summaryrefslogtreecommitdiff
path: root/src/interactive
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-11-06 15:38:02 +0100
committerLuc Bourlier <luc.bourlier@typesafe.com>2013-11-15 14:50:59 +0100
commit9c7c66ff7907e3ab814f0f4375eeaf6cdd230d5e (patch)
tree20ccbbe62fc7108ab60a71e463f9b628092f7c26 /src/interactive
parentab77f2af52b41f70f161891be51d8737b9086d53 (diff)
downloadscala-9c7c66ff7907e3ab814f0f4375eeaf6cdd230d5e.tar.gz
scala-9c7c66ff7907e3ab814f0f4375eeaf6cdd230d5e.tar.bz2
scala-9c7c66ff7907e3ab814f0f4375eeaf6cdd230d5e.zip
Test infrastructure for scope completion
Adds a new marker /*_*/ to trigger scope completion test. Original type completion test oracles update for the tweaked output
Diffstat (limited to 'src/interactive')
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala2
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala19
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala46
-rw-r--r--src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala4
4 files changed, 60 insertions, 11 deletions
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala b/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
index f30d896fb7..2cb4f5fd4a 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala
@@ -61,7 +61,7 @@ abstract class InteractiveTest
* Override this member if you need to change the default set of executed test actions.
*/
protected lazy val testActions: ListBuffer[PresentationCompilerTestDef] = {
- ListBuffer(new CompletionAction(compiler), new TypeAction(compiler), new HyperlinkAction(compiler))
+ ListBuffer(new TypeCompletionAction(compiler), new ScopeCompletionAction(compiler), new TypeAction(compiler), new HyperlinkAction(compiler))
}
/** Add new presentation compiler actions to test. Presentation compiler's test
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
index 8d446cbbf8..4f9df6808f 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala
@@ -42,7 +42,7 @@ trait AskParse extends AskCommand {
import compiler.Tree
/** `sources` need to be entirely parsed before running the test
- * (else commands such as `AskCompletionAt` may fail simply because
+ * (else commands such as `AskTypeCompletionAt` may fail simply because
* the source's AST is not yet loaded).
*/
def askParse(sources: Seq[SourceFile]) {
@@ -72,10 +72,10 @@ trait AskReload extends AskCommand {
}
/** Ask the presentation compiler for completion at a given position. */
-trait AskCompletionAt extends AskCommand {
+trait AskTypeCompletionAt extends AskCommand {
import compiler.Member
- private[tests] def askCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
+ private[tests] def askTypeCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
reporter.println("\naskTypeCompletion at " + pos.source.file.name + ((pos.line, pos.column)))
ask {
@@ -84,6 +84,19 @@ trait AskCompletionAt extends AskCommand {
}
}
+/** Ask the presentation compiler for scope completion at a given position. */
+trait AskScopeCompletionAt extends AskCommand {
+ import compiler.Member
+
+ private[tests] def askScopeCompletionAt(pos: Position)(implicit reporter: Reporter): Response[List[Member]] = {
+ reporter.println("\naskScopeCompletion at " + pos.source.file.name + ((pos.line, pos.column)))
+
+ ask {
+ compiler.askScopeCompletion(pos, _)
+ }
+ }
+}
+
/** Ask the presentation compiler for type info at a given position. */
trait AskTypeAt extends AskCommand {
import compiler.Tree
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
index e28bf20745..451cf70bc2 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
@@ -12,16 +12,16 @@ private[tests] trait CoreTestDefs
/** Ask the presentation compiler for completion at all locations
* (in all sources) where the defined `marker` is found. */
- class CompletionAction(override val compiler: Global)
+ class TypeCompletionAction(override val compiler: Global)
extends PresentationCompilerTestDef
- with AskCompletionAt {
+ with AskTypeCompletionAt {
override def runTest() {
- askAllSources(CompletionMarker) { pos =>
- askCompletionAt(pos)
+ askAllSources(TypeCompletionMarker) { pos =>
+ askTypeCompletionAt(pos)
} { (pos, members) =>
withResponseDelimiter {
- reporter.println("[response] askCompletionAt " + format(pos))
+ reporter.println("[response] askTypeCompletion at " + format(pos))
// we skip getClass because it changed signature between 1.5 and 1.6, so there is no
// universal check file that we can provide for this to work
reporter.println("retrieved %d members".format(members.size))
@@ -34,6 +34,40 @@ private[tests] trait CoreTestDefs
}
}
+ /** Ask the presentation compiler for completion at all locations
+ * (in all sources) where the defined `marker` is found. */
+ class ScopeCompletionAction(override val compiler: Global)
+ extends PresentationCompilerTestDef
+ with AskScopeCompletionAt {
+
+ def memberPrinter(member: compiler.Member): String =
+ "[accessible: %5s] ".format(member.accessible) + "`" + (member.sym.toString() + member.tpe.toString()).trim() + "`"
+
+ override def runTest() {
+ askAllSources(ScopeCompletionMarker) { pos =>
+ askScopeCompletionAt(pos)
+ } { (pos, members) =>
+ withResponseDelimiter {
+ reporter.println("[response] askScopeCompletion at " + format(pos))
+ try {
+ // exclude members not from source (don't have position), for more focused and self contained tests.
+ def eligible(sym: compiler.Symbol) = sym.pos != compiler.NoPosition
+ val filtered = members.filter(member => eligible(member.sym))
+
+ reporter.println("retrieved %d members".format(filtered.size))
+ compiler ask { () =>
+ reporter.println(filtered.map(_.forceInfoString).sorted mkString "\n")
+ }
+ } catch {
+ case t: Throwable =>
+ t.printStackTrace()
+ }
+
+ }
+ }
+ }
+ }
+
/** Ask the presentation compiler for type info at all locations
* (in all sources) where the defined `marker` is found. */
class TypeAction(override val compiler: Global)
@@ -57,7 +91,7 @@ private[tests] trait CoreTestDefs
class HyperlinkAction(override val compiler: Global)
extends PresentationCompilerTestDef
with AskTypeAt
- with AskCompletionAt {
+ with AskTypeCompletionAt {
override def runTest() {
askAllSources(HyperlinkMarker) { pos =>
diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
index a5c228a549..3f9b40277c 100644
--- a/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
+++ b/src/interactive/scala/tools/nsc/interactive/tests/core/TestMarker.scala
@@ -20,7 +20,9 @@ abstract case class TestMarker(marker: String) {
TestMarker.checkForDuplicate(this)
}
-object CompletionMarker extends TestMarker("/*!*/")
+object TypeCompletionMarker extends TestMarker("/*!*/")
+
+object ScopeCompletionMarker extends TestMarker("/*_*/")
object TypeMarker extends TestMarker("/*?*/")