Add arbitrary Action
s to this When
.
Add arbitrary Action
s to this When
.
This is helpful to refactor code. For example: imagine you want to perform the same actions whenever an error occurs. You could leverage this method to do so in the following way:
def preemtiveExit(when: When[String]): Unit { when .returning("Got some error") .exit() } def parseOutputA: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .action1 .when(...) .addActions(preemtiveExit) } def parseOutputB: Expect[String] = { val e = new Expect("some command", "") e.expect(...) .addActions(preemtiveExit) }
function that adds Action
s.
this When
.
Add arbitrary ExpectBlock
s to this Expect
.
Add arbitrary ExpectBlock
s to this Expect
.
This is helpful to refactor code. For example: imagine you have an error case you want to add to multiple expects. You could leverage this method to do so in the following way:
def errorCaseExpectBlock(expect: Expect[String]): Unit { expect.expect .when("Some error") .returning("Got some error") } //Then in your expects def parseOutputA: Expect[String] = { val e = new Expect("some command", "") e.expect(...) e.expect .when(...) .action1 .when(...) .action2 e.addExpectBlock(errorCaseExpectBlock) } def parseOutputB: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .action1 .action2 .when(...) .action1 e.expect(...) .action2 e.addExpectBlock(errorCaseExpectBlock) }
function that adds ExpectBlock
s.
this Expect
.
Add an arbitrary When
to this ExpectBlock
.
Add an arbitrary When
to this ExpectBlock
.
This is helpful to refactor code. For example: imagine you have an error case you want to add to
multiple ExpectBlock
s. You could leverage this method to do so in the following way:
def errorCaseWhen(expectBlock: ExpectBlock[String]): When[String] = { expectBlock .when("Some error") .returning("Got some error") } def parseOutputA: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .sendln(...) e.expect .addWhen(errorCaseWhen) .exit() } def parseOutputB: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .sendln(..) .returning(...) .addWhen(errorCaseWhen) }
This function returns the added When which allows you to add further actions, see the exit action of the
parseOutputA
method in the above code.
It is possible to add more than one When using this method, however this is discouraged since it will make the code somewhat more illegible because "hidden" Whens will also be added.
If you need to add more than one When you have two options:
e.expect .when(...) .sendln(..) .returning(...) .addWhen(errorCaseWhen) .addWhen(anotherWhen)
e.expect .when(...) .sendln(..) .returning(...) .addWhens(multipleWhens)
function that adds the When
.
the added When
.
Add arbitrary When
s to this ExpectBlock
.
Add arbitrary When
s to this ExpectBlock
.
This method is very similar to the addWhen
with the following differences:
f
has a more relaxed type.function that adds When
s.
this ExpectBlock.
Terminates the current run of Expect causing it to return the last returned value.
Terminates the current run of Expect causing it to return the last returned value. Any action or expect block added after this Exit will not be executed.
this When.
Adds, in a new ExpectBlock
, a EndOfFileWhen
that matches whenever the end of file is reached while trying to
read from the process output (stdOut).
Adds, in a new ExpectBlock
, a EndOfFileWhen
that matches whenever the end of file is reached while trying to
read from the process output (stdOut). This is a shortcut to expect.when(pattern)
.
the pattern to be used in the EndOfFileWhen
.
the new RegexWhen
.
Adds, in a new ExpectBlock
, a TimeoutWhen
that matches whenever the read from the process output (stdOut)
times out.
Adds, in a new ExpectBlock
, a TimeoutWhen
that matches whenever the read from the process output (stdOut)
times out. This is a shortcut to expect.when(pattern)
.
the pattern to be used in the TimeoutWhen
.
the new RegexWhen
.
Adds, in a new ExpectBlock
, a RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut).
Adds, in a new ExpectBlock
, a RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut). This is a shortcut to expect.when(pattern)
.
the pattern to be used in the RegexWhen
.
the new RegexWhen
.
Adds, in a new ExpectBlock
, a StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut).
Adds, in a new ExpectBlock
, a StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut). This is a shortcut to expect.when(pattern)
.
the pattern to be used in the StringWhen
.
the new StringWhen
.
Adds an empty new ExpectBlock
.
Returns result
when this Expect is run.
Returns result
when this Expect is run.
If this method is invoked more than once only the last result
will be returned.
Note however that the previous returning actions will also be executed.
this When.
Runs this Expect.
Runs this Expect.
the maximum time to wait for each read.
the charset to use when decoding/encoding the read/write text.
the size of the buffer to use when performing reads.
whether to redirect the stdErr of the spawned process to the stdOut.
the ExecutionContext upon which this Expect will be run.
a Future with the value returned by a ReturningAction
, if no ReturningAction
exists
defaultValue
will be returned. If an exception occurred during the execution of the future
then that exception will be returned in the Failure of the Future.
Send text
to the stdIn of the underlying process.
Send text
to the stdIn of the underlying process.
Send will only occur when Expect is run.
this When.
Sends text
terminated with System.lineSeparator()
to the stdIn of the underlying process.
Sends text
terminated with System.lineSeparator()
to the stdIn of the underlying process.
Send will only occur when Expect is run.
this When.
the core.When equivalent of this fluent.When.
Adds a new TimeoutWhen
that matches whenever a Timeout in thrown while trying to read text
from the process output (stdOut).
Adds a new TimeoutWhen
that matches whenever a Timeout in thrown while trying to read text
from the process output (stdOut).
the pattern to match against.
the new TimeoutWhen
.
Adds a new EndOfFileWhen
that matches whenever the EndOfFile in the process output (stdOut) is reached.
Adds a new EndOfFileWhen
that matches whenever the EndOfFile in the process output (stdOut) is reached.
the pattern to match against.
the new EndOfFileWhen
.
Adds a new RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut).
Adds a new RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut).
the pattern to match against.
the new RegexWhen
.
Adds a new StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut).
Adds a new StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut).
the pattern to match against.
the new StringWhen
.