diff options
Diffstat (limited to 'test/files/presentation')
-rw-r--r-- | test/files/presentation/find-trees.check | 5 | ||||
-rw-r--r-- | test/files/presentation/find-trees/FindTrees.scala | 51 | ||||
-rw-r--r-- | test/files/presentation/find-trees/src/InteractiveTest.scala | 36 | ||||
-rw-r--r-- | test/files/presentation/simple-tests.check | 188 | ||||
-rw-r--r-- | test/files/presentation/simple-tests.javaopts | 1 | ||||
-rw-r--r-- | test/files/presentation/simple-tests/SimpleInteractiveTest.scala | 10 | ||||
-rw-r--r-- | test/files/presentation/simple-tests/src/Tester.scala | 204 |
7 files changed, 0 insertions, 495 deletions
diff --git a/test/files/presentation/find-trees.check b/test/files/presentation/find-trees.check deleted file mode 100644 index 2b76b5aeb8..0000000000 --- a/test/files/presentation/find-trees.check +++ /dev/null @@ -1,5 +0,0 @@ -reload: InteractiveTest.scala -==================== -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 deleted file mode 100644 index 63272948a9..0000000000 --- a/test/files/presentation/find-trees/FindTrees.scala +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index a1a3f96ee0..0000000000 --- a/test/files/presentation/find-trees/src/InteractiveTest.scala +++ /dev/null @@ -1,36 +0,0 @@ -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 - } -} - diff --git a/test/files/presentation/simple-tests.check b/test/files/presentation/simple-tests.check deleted file mode 100644 index ed972ddcda..0000000000 --- a/test/files/presentation/simple-tests.check +++ /dev/null @@ -1,188 +0,0 @@ -reload: Tester.scala -askTypeCompletion at Tester.scala(12,39) - -================================================================================ -[response] aksTypeCompletion at (12,39) -TypeMember(method $asInstanceOf,[T0]()T0,true,false,method any2stringadd) -TypeMember(method !=,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method !=,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ##,()Int,true,false,method any2stringadd) -TypeMember(method $isInstanceOf,[T0]()Boolean,true,false,method any2stringadd) -TypeMember(method ->,[B](y: B)(scala.tools.nsc.reporters.StoreReporter, B),true,false,method any2ArrowAssoc) -TypeMember(method +,(other: String)java.lang.String,true,false,method any2stringadd) -TypeMember(method →,[B](y: B)(scala.tools.nsc.reporters.StoreReporter, B),true,false,method any2ArrowAssoc) -TypeMember(constructor StoreReporter,()scala.tools.nsc.reporters.StoreReporter,true,false,<none>) -TypeMember(constructor StringAdd,(self: Any)scala.runtime.StringAdd,true,false,method any2stringadd) -TypeMember(constructor ArrowAssoc,(x: scala.tools.nsc.reporters.StoreReporter)ArrowAssoc[scala.tools.nsc.reporters.StoreReporter],true,false,method any2ArrowAssoc) -TypeMember(value ERROR,=> scala.tools.nsc.reporters.StoreReporter#Severity,true,true,<none>) -TypeMember(value INFO,=> scala.tools.nsc.reporters.StoreReporter#Severity,true,true,<none>) -TypeMember(class Info,scala.tools.nsc.reporters.StoreReporter#Info,true,false,<none>) -TypeMember(class Severity,scala.tools.nsc.reporters.StoreReporter#Severity,true,true,<none>) -TypeMember(value WARNING,=> scala.tools.nsc.reporters.StoreReporter#Severity,true,true,<none>) -TypeMember(method _truncationOK,=> Boolean,false,true,<none>) -TypeMember(method asInstanceOf,[T0]=> T0,true,true,<none>) -TypeMember(method cancelled,=> Boolean,true,true,<none>) -TypeMember(method clone,()java.lang.Object,false,true,<none>) -TypeMember(method comment,(pos: scala.tools.nsc.util.Position,msg: String)Unit,true,true,<none>) -TypeMember(method countAsString,(n: Int)String,true,true,<none>) -TypeMember(method countElementsAsString,(n: Int,elements: String)String,true,true,<none>) -TypeMember(method ensuring,(cond: (scala.tools.nsc.reporters.StoreReporter) => Boolean,msg: => Any)scala.tools.nsc.reporters.StoreReporter,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: (scala.tools.nsc.reporters.StoreReporter) => Boolean)scala.tools.nsc.reporters.StoreReporter,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean,msg: => Any)scala.tools.nsc.reporters.StoreReporter,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean)scala.tools.nsc.reporters.StoreReporter,true,false,method any2Ensuring) -TypeMember(method eq,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method equals,(x$1: Any)Boolean,true,true,<none>) -TypeMember(method error,(pos: scala.tools.nsc.util.Position,msg: String)Unit,true,true,<none>) -TypeMember(method finalize,()Unit,false,true,<none>) -TypeMember(method flush,()Unit,true,true,<none>) -TypeMember(method formatted,(fmtstr: String)String,true,false,method any2stringadd) -TypeMember(method getSource,=> scala.tools.nsc.util.SourceFile,true,true,<none>) -TypeMember(method hasErrors,=> Boolean,true,true,<none>) -TypeMember(method hasWarnings,=> Boolean,true,true,<none>) -TypeMember(method hashCode,()Int,true,true,<none>) -TypeMember(method incompleteHandled,=> Boolean,true,true,<none>) -TypeMember(method incompleteInputError,=> (scala.tools.nsc.util.Position, String) => Unit,true,true,<none>) -TypeMember(method info,(pos: scala.tools.nsc.util.Position,msg: String,force: Boolean)Unit,true,true,<none>) -TypeMember(method info0,((pos: scala.tools.nsc.util.Position,msg: java.lang.String,severity: _5.Severity,force: Boolean)Unit) forSome { val _5: scala.tools.nsc.reporters.StoreReporter },false,false,<none>) -TypeMember(value infos,(=> scala.collection.mutable.HashSet[_3.Info]) forSome { val _3: scala.tools.nsc.reporters.StoreReporter },true,false,<none>) -TypeMember(value infos,scala.collection.mutable.HashSet[_4.Info] forSome { val _4: scala.tools.nsc.reporters.StoreReporter },false,false,<none>) -TypeMember(method isInstanceOf,[T0]=> Boolean,true,true,<none>) -TypeMember(method ne,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method notify,()Unit,true,true,<none>) -TypeMember(method notifyAll,()Unit,true,true,<none>) -TypeMember(method reset,()Unit,true,false,<none>) -TypeMember(value self,Any,false,false,method any2stringadd) -TypeMember(method setSource,(source: scala.tools.nsc.util.SourceFile)Unit,true,true,<none>) -TypeMember(object severity,object scala.tools.nsc.reporters.StoreReporter#severity,true,true,<none>) -TypeMember(method source,=> scala.tools.nsc.util.SourceFile,false,true,<none>) -TypeMember(method synchronized,[T0](x$1: T0)T0,true,true,<none>) -TypeMember(method toString,()java.lang.String,true,true,<none>) -TypeMember(method truncationOK,=> Boolean,true,true,<none>) -TypeMember(method wait,()Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long,x$2: Int)Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long)Unit,true,true,<none>) -TypeMember(method warning,(pos: scala.tools.nsc.util.Position,msg: String)Unit,true,true,<none>) -TypeMember(method withIncompleteHandler,[T](handler: (scala.tools.nsc.util.Position, String) => Unit)(thunk: => T)T,true,true,<none>) -TypeMember(method withSource,[A](src: scala.tools.nsc.util.SourceFile)(op: => A)A,true,true,<none>) -TypeMember(method withoutTruncating,[T](body: => T)T,true,true,<none>) -TypeMember(value x,=> scala.tools.nsc.reporters.StoreReporter,true,false,method any2ArrowAssoc) -TypeMember(value x,scala.tools.nsc.reporters.StoreReporter,false,false,method any2ArrowAssoc) -askTypeCompletion at Tester.scala(23,24) - -================================================================================ -[response] aksTypeCompletion at (23,24) -TypeMember(method $asInstanceOf,[T0]()T0,true,false,method any2stringadd) -TypeMember(method !=,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method !=,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ##,()Int,true,false,method any2stringadd) -TypeMember(method $isInstanceOf,[T0]()Boolean,true,false,method any2stringadd) -TypeMember(method ->,[B](y: B)(scala.tools.nsc.interactive.Response[U], B),true,false,method any2ArrowAssoc) -TypeMember(method +,(other: String)java.lang.String,true,false,method any2stringadd) -TypeMember(method →,[B](y: B)(scala.tools.nsc.interactive.Response[U], B),true,false,method any2ArrowAssoc) -TypeMember(constructor Response,()scala.tools.nsc.interactive.Response[U],true,false,<none>) -TypeMember(constructor StringAdd,(self: Any)scala.runtime.StringAdd,true,false,method any2stringadd) -TypeMember(constructor ArrowAssoc,(x: scala.tools.nsc.interactive.Response[U])ArrowAssoc[scala.tools.nsc.interactive.Response[U]],true,false,method any2ArrowAssoc) -TypeMember(method asInstanceOf,[T0]=> T0,true,true,<none>) -TypeMember(method cancel,()Unit,true,false,<none>) -TypeMember(method cancelled,=> Boolean,false,false,<none>) -TypeMember(variable cancelled,Boolean,false,false,<none>) -TypeMember(method clear,()Unit,true,false,<none>) -TypeMember(method clone,()java.lang.Object,false,true,<none>) -TypeMember(method complete,=> Boolean,false,false,<none>) -TypeMember(variable complete,Boolean,false,false,<none>) -TypeMember(method data,=> Option[Either[U,Throwable]],false,false,<none>) -TypeMember(variable data,Option[Either[U,Throwable]],false,false,<none>) -TypeMember(method ensuring,(cond: (scala.tools.nsc.interactive.Response[U]) => Boolean,msg: => Any)scala.tools.nsc.interactive.Response[U],true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: (scala.tools.nsc.interactive.Response[U]) => Boolean)scala.tools.nsc.interactive.Response[U],true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean,msg: => Any)scala.tools.nsc.interactive.Response[U],true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean)scala.tools.nsc.interactive.Response[U],true,false,method any2Ensuring) -TypeMember(method eq,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method equals,(x$1: Any)Boolean,true,true,<none>) -TypeMember(method finalize,()Unit,false,true,<none>) -TypeMember(method formatted,(fmtstr: String)String,true,false,method any2stringadd) -TypeMember(method get,=> Either[U,Throwable],true,false,<none>) -TypeMember(method get,(timeout: Long)Option[Either[U,Throwable]],true,false,<none>) -TypeMember(method hashCode,()Int,true,true,<none>) -TypeMember(method isCancelled,=> Boolean,true,false,<none>) -TypeMember(method isComplete,=> Boolean,true,false,<none>) -TypeMember(method isInstanceOf,[T0]=> Boolean,true,true,<none>) -TypeMember(method ne,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method notify,()Unit,true,true,<none>) -TypeMember(method notifyAll,()Unit,true,true,<none>) -TypeMember(method raise,(exc: Throwable)Unit,true,false,<none>) -TypeMember(value self,Any,false,false,method any2stringadd) -TypeMember(method set,(x: U)Unit,true,false,<none>) -TypeMember(method setProvisionally,(x: U)Unit,true,false,<none>) -TypeMember(method synchronized,[T0](x$1: T0)T0,true,true,<none>) -TypeMember(method toString,()java.lang.String,true,true,<none>) -TypeMember(method wait,()Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long,x$2: Int)Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long)Unit,true,true,<none>) -TypeMember(value x,=> scala.tools.nsc.interactive.Response[U],true,false,method any2ArrowAssoc) -TypeMember(value x,scala.tools.nsc.interactive.Response[U],false,false,method any2ArrowAssoc) -askTypeCompletion at Tester.scala(105,29) - -================================================================================ -[response] aksTypeCompletion at (105,29) -TypeMember(method $asInstanceOf,[T0]()T0,true,false,method any2stringadd) -TypeMember(method !=,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method !=,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: AnyRef)Boolean,true,false,method any2stringadd) -TypeMember(method ==,(x$1: Any)Boolean,true,false,method any2stringadd) -TypeMember(method ##,()Int,true,false,method any2stringadd) -TypeMember(method $isInstanceOf,[T0]()Boolean,true,false,method any2stringadd) -TypeMember(method ->,[B](y: B)(scala.tools.nsc.util.SourceFile, B),true,false,method any2ArrowAssoc) -TypeMember(method +,(other: String)java.lang.String,true,false,method any2stringadd) -TypeMember(method →,[B](y: B)(scala.tools.nsc.util.SourceFile, B),true,false,method any2ArrowAssoc) -TypeMember(constructor SourceFile,()scala.tools.nsc.util.SourceFile,true,false,<none>) -TypeMember(constructor StringAdd,(self: Any)scala.runtime.StringAdd,true,false,method any2stringadd) -TypeMember(constructor ArrowAssoc,(x: scala.tools.nsc.util.SourceFile)ArrowAssoc[scala.tools.nsc.util.SourceFile],true,false,method any2ArrowAssoc) -TypeMember(method asInstanceOf,[T0]=> T0,true,true,<none>) -TypeMember(method beginsWith,(offset: Int,text: String)Boolean,true,false,<none>) -TypeMember(method clone,()java.lang.Object,false,true,<none>) -TypeMember(method content,=> Array[Char],true,false,<none>) -TypeMember(method dbg,(offset: Int)java.lang.String,true,false,<none>) -TypeMember(method ensuring,(cond: (scala.tools.nsc.util.SourceFile) => Boolean,msg: => Any)scala.tools.nsc.util.SourceFile,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: (scala.tools.nsc.util.SourceFile) => Boolean)scala.tools.nsc.util.SourceFile,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean,msg: => Any)scala.tools.nsc.util.SourceFile,true,false,method any2Ensuring) -TypeMember(method ensuring,(cond: Boolean)scala.tools.nsc.util.SourceFile,true,false,method any2Ensuring) -TypeMember(method eq,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method equals,(x$1: Any)Boolean,true,true,<none>) -TypeMember(method file,=> scala.tools.nsc.io.AbstractFile,true,false,<none>) -TypeMember(method finalize,()Unit,false,true,<none>) -TypeMember(method formatted,(fmtstr: String)String,true,false,method any2stringadd) -TypeMember(method hashCode,()Int,true,true,<none>) -TypeMember(method identifier,(pos: scala.tools.nsc.util.Position,compiler: scala.tools.nsc.Global)Option[String],true,false,<none>) -TypeMember(method isInstanceOf,[T0]=> Boolean,true,true,<none>) -TypeMember(method isLineBreak,(idx: Int)Boolean,true,false,<none>) -TypeMember(method isSelfContained,=> Boolean,true,false,<none>) -TypeMember(method length,=> Int,true,false,<none>) -TypeMember(method lineToOffset,(index: Int)Int,true,false,<none>) -TypeMember(method lineToString,(index: Int)String,true,false,<none>) -TypeMember(method ne,(x$1: AnyRef)Boolean,true,true,<none>) -TypeMember(method notify,()Unit,true,true,<none>) -TypeMember(method notifyAll,()Unit,true,true,<none>) -TypeMember(method offsetToLine,(offset: Int)Int,true,false,<none>) -TypeMember(method path,=> String,true,false,<none>) -TypeMember(method position,(offset: Int)scala.tools.nsc.util.Position,true,false,<none>) -TypeMember(method position,(line: Int,column: Int)scala.tools.nsc.util.Position,true,false,<none>) -TypeMember(method positionInUltimateSource,(position: scala.tools.nsc.util.Position)scala.tools.nsc.util.Position,true,false,<none>) -TypeMember(value self,Any,false,false,method any2stringadd) -TypeMember(method skipWhitespace,(offset: Int)Int,true,false,<none>) -TypeMember(method synchronized,[T0](x$1: T0)T0,true,true,<none>) -TypeMember(method toString,()String,true,false,<none>) -TypeMember(method wait,()Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long,x$2: Int)Unit,true,true,<none>) -TypeMember(method wait,(x$1: Long)Unit,true,true,<none>) -TypeMember(value x,=> scala.tools.nsc.util.SourceFile,true,false,method any2ArrowAssoc) -TypeMember(value x,scala.tools.nsc.util.SourceFile,false,false,method any2ArrowAssoc) -askTypeAt at Tester.scala(12,14) -[response] askTypeAt at (12,14) -private[this] val reporter: scala.tools.nsc.reporters.StoreReporter = new reporters.StoreReporter() -askTypeAt at Tester.scala(13,14) -[response] askTypeAt at (13,14) -private[this] val compiler: scala.tools.nsc.interactive.Global = new Global(Tester.this.settings, Tester.this.reporter) diff --git a/test/files/presentation/simple-tests.javaopts b/test/files/presentation/simple-tests.javaopts deleted file mode 100644 index 4af888f9c2..0000000000 --- a/test/files/presentation/simple-tests.javaopts +++ /dev/null @@ -1 +0,0 @@ --Dfile.encoding=UTF-8
\ No newline at end of file diff --git a/test/files/presentation/simple-tests/SimpleInteractiveTest.scala b/test/files/presentation/simple-tests/SimpleInteractiveTest.scala deleted file mode 100644 index cfadc561ae..0000000000 --- a/test/files/presentation/simple-tests/SimpleInteractiveTest.scala +++ /dev/null @@ -1,10 +0,0 @@ -import scala.tools.nsc.interactive.tests._ - -/** Simple test that shows how to use the InteractiveTest class. It uses the - * inherited runTest method that runs completion and typedAt tests on all - * sources found under src/ - */ -object Test extends InteractiveTest { - override val runRandomTests = false -// override val synchronousRequests = false -} diff --git a/test/files/presentation/simple-tests/src/Tester.scala b/test/files/presentation/simple-tests/src/Tester.scala deleted file mode 100644 index 09e08727bf..0000000000 --- a/test/files/presentation/simple-tests/src/Tester.scala +++ /dev/null @@ -1,204 +0,0 @@ -package scala.tools.nsc -package interactive -package tests - -import util._ -import reporters._ -import io.AbstractFile -import collection.mutable.ArrayBuffer - -class Tester(ntests: Int, inputs: Array[SourceFile], settings: Settings) { - - val reporter/*?*/ = new StoreReporter/*!*/ - val compiler/*?*/ = new Global(settings, reporter) - - def askAndListen[T, U](msg: String, arg: T, op: (T, Response[U]) => Unit) { - if (settings.verbose.value) print(msg+" "+arg+": ") - val TIMEOUT = 10 // ms - val limit = System.currentTimeMillis() + randomDelayMillis - val res = new Response[U] - op(arg, res) - while (!res.isComplete && !res.isCancelled) { - if (System.currentTimeMillis() > limit) { - print("c"); res./*!*/cancel() - } else res.get(TIMEOUT) match { - case Some(Left(t)) => - /**/ - if (settings.verbose.value) println(t) - case Some(Right(ex)) => - ex.printStackTrace() - println(ex) - case None => - } - } - } - - def askReload(sfs: SourceFile*) = askAndListen("reload", sfs.toList, compiler.askReload) - def askTypeAt(pos: Position) = askAndListen("type at", pos, compiler.askTypeAt) - def askTypeCompletion(pos: Position) = askAndListen("type at", pos, compiler.askTypeCompletion) - def askScopeCompletion(pos: Position) = askAndListen("type at", pos, compiler.askScopeCompletion) - - val rand = new java.util.Random() - - private def randomInverse(n: Int) = n / (rand.nextInt(n) + 1) - - private def randomDecreasing(n: Int) = { - var r = rand.nextInt((1 to n).sum) - var limit = n - var result = 0 - while (r > limit) { - result += 1 - r -= limit - limit -= 1 - } - result - } - - def randomSourceFileIdx() = rand.nextInt(inputs.length) - - def randomBatchesPerSourceFile(): Int = randomDecreasing(100) - - def randomChangesPerBatch(): Int = randomInverse(50) - - def randomPositionIn(sf: SourceFile) = rand.nextInt(sf.content.length) - - def randomNumChars() = randomInverse(100) - - def randomDelayMillis = randomInverse(10000) - - class Change(sfidx: Int, start: Int, nchars: Int, toLeft: Boolean) { - - private var pos = start - private var deleted: List[Char] = List() - - override def toString = - "In "+inputs(sfidx)+" at "+start+" take "+nchars+" to "+ - (if (toLeft) "left" else "right") - - def deleteOne() { - val sf = inputs(sfidx) - deleted = sf.content(pos) :: deleted - val sf1 = new BatchSourceFile(sf.file, sf.content.take(pos) ++ sf.content.drop(pos + 1)) - inputs(sfidx) = sf1 - askReload(sf1) - } - - def deleteAll() { - print("/"+nchars) - for (i <- 0 until nchars) { - if (toLeft) { - if (pos > 0 && pos <= inputs(sfidx).length) { - pos -= 1 - deleteOne() - } - } else { - if (pos < inputs(sfidx).length) { - deleteOne() - } - } - } - } - - def insertAll() { - for (chr <- if (toLeft) deleted else deleted.reverse) { - val sf = inputs(sfidx) - val (pre, post) = sf./*!*/content splitAt pos - pos += 1 - val sf1 = new BatchSourceFile(sf.file, pre ++ (chr +: post)) - inputs(sfidx) = sf1 - askReload(sf1) - } - } - } - - val testComment = "/**/" - - def testFileChanges(sfidx: Int) = { - lazy val testPositions: Seq[Int] = { - val sf = inputs(sfidx) - val buf = new ArrayBuffer[Int] - var pos = sf.content.indexOfSlice(testComment) - while (pos > 0) { - buf += pos - pos = sf.content.indexOfSlice(testComment, pos + 1) - } - buf - } - def otherTest() { - if (testPositions.nonEmpty) { - val pos = new OffsetPosition(inputs(sfidx), rand.nextInt(testPositions.length)) - rand.nextInt(3) match { - case 0 => askTypeAt(pos) - case 1 => askTypeCompletion(pos) - case 2 => askScopeCompletion(pos) - } - } - } - for (i <- 0 until randomBatchesPerSourceFile()) { - val changes = Vector.fill(/**/randomChangesPerBatch()) { - /**/ - new Change(sfidx, randomPositionIn(inputs(sfidx)), randomNumChars(), rand.nextBoolean()) - } - doTest(sfidx, changes, testPositions, otherTest) match { - case Some(errortrace) => - println(errortrace) - minimize(errortrace) - case None => - } - } - } - - def doTest(sfidx: Int, changes: Seq[Change], testPositions: Seq[Int], otherTest: () => Unit): Option[ErrorTrace] = { - print("new round with "+changes.length+" changes:") - changes foreach (_.deleteAll()) - otherTest() - def errorCount() = compiler.ask(() => reporter.ERROR.count) -// println("\nhalf test round: "+errorCount()) - changes.view.reverse foreach (_.insertAll()) - otherTest() - println("done test round: "+errorCount()) - if (errorCount() != 0) - Some(ErrorTrace(sfidx, changes, reporter.infos, inputs(sfidx).content)) - else - None - } - - case class ErrorTrace( - sfidx: Int, changes: Seq[Change], infos: collection.Set[reporter.Info], content: Array[Char]) { - override def toString = - "Sourcefile: "+inputs(sfidx)+ - "\nChanges:\n "+changes.mkString("\n ")+ - "\nErrors:\n "+infos.mkString("\n ")+ - "\nContents:\n"+content.mkString - } - - def minimize(etrace: ErrorTrace) {} - - /**/ - def run() { - askReload(inputs: _*) - for (i <- 0 until ntests) - testFileChanges(randomSourceFileIdx()) - } -} - -/* A program to do presentation compiler stress tests. - * Usage: - * - * scala scala.tools.nsc.interactive.test.Tester <n> <files> - * - * where <n> is the number os tests to be run and <files> is the set of files to test. - * This will do random deletions and re-insertions in any of the files. - * At places where an empty comment /**/ appears it will in addition randomly - * do ask-types, type-completions, or scope-completions. - */ -object Tester { - def main(args: Array[String]) { - val settings = new Settings() - val (_, filenames) = settings.processArguments(args.toList.tail, true) - println("filenames = "+filenames) - val files = filenames.toArray map (str => new BatchSourceFile(AbstractFile.getFile(str)): SourceFile) - new Tester(args(0).toInt, files, settings).run() - sys.exit(0) - } -} |