diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-01-27 10:03:48 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-01-27 10:03:48 +0000 |
commit | db25b914f56884d5d36b1e16191b0ce870e57faf (patch) | |
tree | 7b86b1756cf8b27628ebc289242074b097d26438 /test/files | |
parent | 942d844aebc63dd417c77911acf565bf1e2c027d (diff) | |
download | scala-db25b914f56884d5d36b1e16191b0ce870e57faf.tar.gz scala-db25b914f56884d5d36b1e16191b0ce870e57faf.tar.bz2 scala-db25b914f56884d5d36b1e16191b0ce870e57faf.zip |
Re-enabled one presentation compiler test.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/presentation/find-trees.check | 8 | ||||
-rw-r--r-- | test/files/presentation/find-trees/FindTrees.scala | 51 | ||||
-rw-r--r-- | test/files/presentation/find-trees/src/InteractiveTest.scala | 36 |
3 files changed, 95 insertions, 0 deletions
diff --git a/test/files/presentation/find-trees.check b/test/files/presentation/find-trees.check new file mode 100644 index 0000000000..73405e818c --- /dev/null +++ b/test/files/presentation/find-trees.check @@ -0,0 +1,8 @@ +reload: InteractiveTest.scala +asking position at 19:4 +retrieved tree: InteractiveTest.this.settings + +==================== +asking position at 20:16 +retrieved tree: lazy private[this] var compiler: scala.tools.nsc.interactive.CompilerControl = new Global(InteractiveTest.this.settings, InteractiveTest.this.reporter) + diff --git a/test/files/presentation/find-trees/FindTrees.scala b/test/files/presentation/find-trees/FindTrees.scala new file mode 100644 index 0000000000..2d748e64cb --- /dev/null +++ b/test/files/presentation/find-trees/FindTrees.scala @@ -0,0 +1,51 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest +import scala.tools.nsc.util.Position + + +/** Example interactive test that does everything by hand. It would be much simpler + * to just add the markers in the test file. This test shows how to drive + * the presentation compiler manually. + */ +object Test extends InteractiveTest { + + def askForPos(pos: Position) { + import compiler._ + val response = new Response[Tree] + + println("asking position at %d:%d".format(pos.line, pos.column)) + compiler.askTypeAt(pos, response) + response.get match { + case Left(EmptyTree) => + println("error retrieving tree at %d:%d".format(pos.line, pos.column)) + case Left(t) => + println("retrieved tree: " + t) + } + println(this.reporter.infos.mkString("\n")) + } + + // You can enable settings for the presentation compiler here + // but don't leave them in the nightly build since the log will most likely + // contain absolute paths + +// settings.YpresentationDebug.value = true +// settings.YpresentationVerbose.value = true + + override def runTest { + import compiler._ + val src = sourceFiles(0) // only one under src/ + val pos = rangePos(src, 426, 426, 433) + val pos1 = src.position(19, 15) // this is an offset position + + // reload is issued already by the framework, so we don't need to do it, but it doesn't hurt + val reload = new Response[Unit] + compiler.askReload(List(src), reload) + reload.get // it's important to let reload finish before asking other things. + + // re-enable when positions in the primary constructor are handled reliably + askForPos(pos) + println("=" * 20) + askForPos(pos1) + + compiler.askShutdown() + } +} diff --git a/test/files/presentation/find-trees/src/InteractiveTest.scala b/test/files/presentation/find-trees/src/InteractiveTest.scala new file mode 100644 index 0000000000..a1a3f96ee0 --- /dev/null +++ b/test/files/presentation/find-trees/src/InteractiveTest.scala @@ -0,0 +1,36 @@ +package scala.tools.nsc.interactive +package tests + +import scala.tools.nsc.Settings +import scala.tools.nsc.reporters.StoreReporter +import scala.tools.nsc.util.{BatchSourceFile, SourceFile, Position} +import scala.tools.nsc.io._ + +/** A base class for writing interactive compiler tests. + * + * @author Iulian Dragos + * + */ +abstract class InteractiveTest { + + val settings = new Settings + val reporter= new StoreReporter + + settings.YpresentationDebug.value = true + lazy val compiler: CompilerControl = new Global(settings, reporter) + + def sources(filename: String*): Seq[SourceFile] = + filename map source + + def source(filename: String) = new BatchSourceFile(AbstractFile.getFile(filename)) + + def pos(filename: String, line: Int, col: Int): Position = + source(filename).position(line, col) + + def runTest: Unit + + def main(args: Array[String]) { + runTest + } +} + |