File: t7805-repl-i.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (42 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (4)
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()
  }
}