Packages

package core

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. case class EndOfFileWhen [+R](readFrom: FromInputStream = StdOut)(actions: Action[R, EndOfFileWhen]*) extends When[R] with Product with Serializable
  2. final class Expect [+R] extends LazyLogging

    Expect allows you to invoke CLIs and ensure they return what you expect.

    Expect allows you to invoke CLIs and ensure they return what you expect. You can describe a cli interaction which will be executed when run is invoked.

    Each interaction is described inside an ExpectBlock using Whens. Each When states under which circumstances the corresponding actions are to be executed. For example:

    import work.martins.simon.core._
    import scala.concurrent.ExecutionContext.Implicits.global
    
    val e = new Expect("bc -i", defaultValue = 5)(
      ExpectBlock(
        StringWhen("For details type `warranty'.")(
          Sendln("1 + 2")
        )
      ),
      ExpectBlock(
        RegexWhen("""\n(\d+)\n""".r)(
          SendlnWithRegex { m =>
            val previousAnswer = m.group(1)
            println(s"Got $$previousAnswer")
            s"$$previousAnswer + 3"
          }
        )
      ),
      ExpectBlock(
        RegexWhen("""\n(\d+)\n""".r)(
          ReturningWithRegex(_.group(1).toInt)
        )
      )
    )
    e.run() //Returns 6 inside a Future[Int]

    We are executing the command bc -i which is a cli calculator. bc, when it starts, writes to the terminal (more precisely to the standard out): "For details type warranty'." The expect we created reacts to it and sends to the terminal (more precisely to the standard in) the string "1 + 2". However it only does so when the expect in ran, until then it does nothing, or in other words, it only saves that it has to send "1 + 2" when the string "For details type warranty'." appears on the StdOut.

    If this interaction is successful it then proceeds to the next one defined by the next ExpectBlock. This interaction states that when bc outputs text that matches the regex """\n(\d+)\n""" the expect should react by sending the string "3 + 3" where the first 3 is obtained by inspecting the regex match and extracting the first group.

    Finally the last interaction is very similar to the second one, with the only difference being the matched digit is not used to send more text to bc but rather to set the value the expect will return in the end of the execution.

    If you find the syntax used to create the Expect too verbose you should look at work.martins.simon.expect.fluent.Expect or work.martins.simon.expect.dsl.Expect which provide a more terse syntax, especially dsl.Expect which provides a syntax very similar to Tcl Expect.

    R

    the type this Expect returns.

  3. final case class ExpectBlock [+R](whens: When[R]*) extends LazyLogging with Product with Serializable

  4. case class NuProcessRichProcess (command: Seq[String], settings: Settings) extends RichProcess with LazyLogging with Product with Serializable
  5. case class RegexWhen [+R](pattern: Regex, readFrom: FromInputStream = StdOut)(actions: Action[R, RegexWhen]*) extends When[R] with Product with Serializable
  6. trait RichProcess extends AnyRef
  7. final case class RunContext [+R](process: RichProcess, value: R, executionAction: ExecutionAction, readFrom: FromInputStream = StdOut, stdOutOutput: String = "", stdErrOutput: String = "", id: String = Random.nextInt.toString) extends LazyLogging with Product with Serializable
  8. case class StringWhen [+R](pattern: String, readFrom: FromInputStream = StdOut)(actions: Action[R, StringWhen]*) extends When[R] with Product with Serializable
  9. case class TimeoutWhen [+R]()(actions: Action[R, TimeoutWhen]*) extends When[R] with Product with Serializable
  10. sealed trait When [+R] extends LazyLogging

Value Members

  1. object RunContext extends Serializable

Ungrouped