1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import scala.tools.partest.{ ReplTest, Welcoming }
import scala.tools.nsc.{ GenericRunnerSettings, Settings }
import scala.tools.nsc.settings.MutableSettings
object Test extends ReplTest with HangingRepl with Welcoming {
def script = testPath changeExtension "script"
override def transformSettings(s: Settings) = s match {
case m: MutableSettings =>
val t = new GenericRunnerSettings(s.errorFn)
m copyInto t
t processArgumentString s"-i $script"
t
case _ => s
}
def code = "Console println Try(8)"
}
object Resulting {
import scala.concurrent._
import scala.concurrent.duration._
implicit class AwaitResult[A](val f: Future[A]) extends AnyVal {
def resultWithin(d: Duration): A = Await.result(f, d)
}
}
/** Test that hangs the REPL.
* Usually that is the "before" case.
*/
trait HangingRepl extends ReplTest {
import scala.language.postfixOps
import scala.util._
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits._
import Resulting._
def timeout = 120 seconds
def hanging[A](a: =>A): A = Future(a) resultWithin timeout
override def show() = Try(hanging(super.show())) recover {
case e => e.printStackTrace()
}
}
|