Skip to content

Commit

Permalink
Test infrastructure for scope completion
Browse files Browse the repository at this point in the history
Adds a new marker /*_*/ to trigger scope completion test.
Original type completion test oracles update for the tweaked output
  • Loading branch information
retronym authored and Luc Bourlier committed Nov 15, 2013
1 parent ab77f2a commit 9c7c66f
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("/*?*/")

Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/callcc-interpreter.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: CallccInterpreter.scala

askTypeCompletion at CallccInterpreter.scala(51,38)
================================================================================
[response] askCompletionAt (51,38)
[response] askTypeCompletion at (51,38)
retrieved 59 members
abstract trait Term extends AnyRef
abstract trait Value extends AnyRef
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/completion-implicit-chained.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: Completions.scala

askTypeCompletion at Completions.scala(11,16)
================================================================================
[response] askCompletionAt (11,16)
[response] askTypeCompletion at (11,16)
retrieved 24 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/ide-bug-1000349.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: CompletionOnEmptyArgMethod.scala

askTypeCompletion at CompletionOnEmptyArgMethod.scala(2,17)
================================================================================
[response] askCompletionAt (2,17)
[response] askTypeCompletion at (2,17)
retrieved 32 members
def +(other: String): String
def ->[B](y: B): (Foo, B)
Expand Down
6 changes: 3 additions & 3 deletions test/files/presentation/ide-bug-1000475.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: Foo.scala

askTypeCompletion at Foo.scala(3,7)
================================================================================
[response] askCompletionAt (3,7)
[response] askTypeCompletion at (3,7)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down Expand Up @@ -36,7 +36,7 @@ final def wait(x$1: Long,x$2: Int): Unit

askTypeCompletion at Foo.scala(6,10)
================================================================================
[response] askCompletionAt (6,10)
[response] askTypeCompletion at (6,10)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down Expand Up @@ -70,7 +70,7 @@ final def wait(x$1: Long,x$2: Int): Unit

askTypeCompletion at Foo.scala(7,7)
================================================================================
[response] askCompletionAt (7,7)
[response] askTypeCompletion at (7,7)
retrieved 31 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/ide-bug-1000531.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: CrashOnLoad.scala

askTypeCompletion at CrashOnLoad.scala(6,12)
================================================================================
[response] askCompletionAt (6,12)
[response] askTypeCompletion at (6,12)
retrieved 120 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/implicit-member.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: ImplicitMember.scala

askTypeCompletion at ImplicitMember.scala(7,7)
================================================================================
[response] askCompletionAt (7,7)
[response] askTypeCompletion at (7,7)
retrieved 34 members
def +(other: String): String
def ->[B](y: B): (Implicit.type, B)
Expand Down
4 changes: 2 additions & 2 deletions test/files/presentation/ping-pong.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: PingPong.scala

askTypeCompletion at PingPong.scala(10,23)
================================================================================
[response] askCompletionAt (10,23)
[response] askTypeCompletion at (10,23)
retrieved 35 members
[inaccessible] private[this] val ping: Ping
[inaccessible] protected[package lang] def clone(): Object
Expand Down Expand Up @@ -39,7 +39,7 @@ private[this] val name: String

askTypeCompletion at PingPong.scala(19,20)
================================================================================
[response] askCompletionAt (19,20)
[response] askTypeCompletion at (19,20)
retrieved 35 members
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
Expand Down
12 changes: 6 additions & 6 deletions test/files/presentation/t1207.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: Completions.scala

askTypeCompletion at Completions.scala(10,15)
================================================================================
[response] askCompletionAt (10,15)
[response] askTypeCompletion at (10,15)
retrieved 3 members
final package bongo
final package lang
Expand All @@ -11,7 +11,7 @@ final package util

askTypeCompletion at Completions.scala(11,16)
================================================================================
[response] askCompletionAt (11,16)
[response] askTypeCompletion at (11,16)
retrieved 3 members
final package bongo
final package lang
Expand All @@ -20,7 +20,7 @@ final package util

askTypeCompletion at Completions.scala(12,19)
================================================================================
[response] askCompletionAt (12,19)
[response] askTypeCompletion at (12,19)
retrieved 3 members
final package bongo
final package lang
Expand All @@ -29,7 +29,7 @@ final package util

askTypeCompletion at Completions.scala(13,19)
================================================================================
[response] askCompletionAt (13,19)
[response] askTypeCompletion at (13,19)
retrieved 3 members
final package bongo
final package lang
Expand All @@ -38,7 +38,7 @@ final package util

askTypeCompletion at Completions.scala(14,23)
================================================================================
[response] askCompletionAt (14,23)
[response] askTypeCompletion at (14,23)
retrieved 3 members
final package bongo
final package lang
Expand All @@ -47,7 +47,7 @@ final package util

askTypeCompletion at Completions.scala(15,10)
================================================================================
[response] askCompletionAt (15,10)
[response] askTypeCompletion at (15,10)
retrieved 0 members

================================================================================
2 changes: 1 addition & 1 deletion test/files/presentation/t5708.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: Completions.scala

askTypeCompletion at Completions.scala(17,9)
================================================================================
[response] askCompletionAt (17,9)
[response] askTypeCompletion at (17,9)
retrieved 39 members
[inaccessible] private def privateM: String
[inaccessible] private[this] val privateV: String
Expand Down
10 changes: 5 additions & 5 deletions test/files/presentation/visibility.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ reload: Completions.scala

askTypeCompletion at Completions.scala(14,12)
================================================================================
[response] askCompletionAt (14,12)
[response] askTypeCompletion at (14,12)
retrieved 37 members
[inaccessible] private[this] def secretPrivateThis(): Unit
def +(other: String): String
Expand Down Expand Up @@ -42,7 +42,7 @@ protected[package lang] def finalize(): Unit

askTypeCompletion at Completions.scala(16,11)
================================================================================
[response] askCompletionAt (16,11)
[response] askTypeCompletion at (16,11)
retrieved 37 members
def +(other: String): String
def ->[B](y: B): (accessibility.Foo, B)
Expand Down Expand Up @@ -82,7 +82,7 @@ protected[package lang] def finalize(): Unit

askTypeCompletion at Completions.scala(22,11)
================================================================================
[response] askCompletionAt (22,11)
[response] askTypeCompletion at (22,11)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
def +(other: String): String
Expand Down Expand Up @@ -122,7 +122,7 @@ protected[package lang] def finalize(): Unit

askTypeCompletion at Completions.scala(28,10)
================================================================================
[response] askCompletionAt (28,10)
[response] askTypeCompletion at (28,10)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
[inaccessible] private[this] def secretPrivateThis(): Unit
Expand Down Expand Up @@ -162,7 +162,7 @@ protected[package accessibility] def secretProtectedInPackage(): Unit

askTypeCompletion at Completions.scala(37,8)
================================================================================
[response] askCompletionAt (37,8)
[response] askTypeCompletion at (37,8)
retrieved 37 members
[inaccessible] private def secretPrivate(): Unit
[inaccessible] private[this] def secretPrivateThis(): Unit
Expand Down

0 comments on commit 9c7c66f

Please sign in to comment.