-
Notifications
You must be signed in to change notification settings - Fork 44
Expect for Ant
Expectit comes with three custom Ant tasks for performing expect operations on the standard input and output streams of spawn processes, sockets and SSH services.
The expect Ant tasks are defined as an antlib resource in the expectit-ant.jar
file. The file can be downloaded from the project release page or from the Maven central.
Here is an example of the taskdef
element that adds the expect tasks definitions to the current project with the given XML namespace URI.
<taskdef classpath="${expectit-ant.jar}"
resource="net/sf/expectit/ant/antlib.xml" uri="antlib:net.sf.expectit.ant" />
<target name="main" xmlns:expect="antlib:net.sf.expectit.ant">
<expect:exec executable="/bin/sh">
<expect:sequential>
<expect:send line="exit"/>
</expect:sequential>
</expect:exec>
</target>
For more information about the task definition please refer to the Ant taskdef documentation.
The expect ssh
task depends on external library which is not included in the Ant distribution. For more information please refer to the Ant sshexec task documentation.
All three tasks share same set of parameters to configure an Expect instance.
Attribute | Description | Required |
---|---|---|
expectTimeout | The timeout for expect operations. Defaults to 30 seconds. | No |
charset | The charset used to convert bytes to characters. Defaults to the system local default. | No |
errorOnTimeout | Stops when the first expect operation times and exits with error status. Defaults to false. | No |
lineSeparator | The default line separator for send . Default to the system default. |
No |
echoOutput | Enables logging of the input and output streams by the Ant's logger. Default to false | No |
Element | Description |
---|---|
filters | The container for the input filter elements applied for the Expect instance |
sequential | The container for the expect elements as well as any Ant tasks that will be executed sequentially |
Filter | Description | Attributes |
---|---|---|
removeColors | Removes [ANSI escape sequences for colors] (http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) from the input streams | No |
removeNonPrintable | Removes all the non-printable characters expect white spaces | No |
replaceInString | Replaces every substring in the input string that matches the given regular expression and replaces it with given replacement |
regexp - the regular expression replacement - the string to be substituted for each match |
replaceInBuffer | Replaces every substring in the entire input buffer that matches the given regular expression and replaces it with given replacement |
regexp - the regular expression replacement - the string to be substituted for each match |
The sequential
element can contains any Ant tasks that will be executed sequentially. The following table describes the expect specific tasks.
Tasks | Description | Attributes |
---|---|---|
send | Sends string data to the output stream |
string - a string to be passed to the output stream line - a string to be passed to the output stream and followed by the line separator |
contains | Matches when the examined input contains the given string |
string - the string to find |
regexp | Matches when the examined input contains the given regular expression |
regexp - the regular expression to find. Common expect attributes
|
matches | Matches when the examined input matches the given regular expression |
regexp - the regular expression to match Common expect attributes
|
anyString | Matches if the input contains any characters |
Common expect attributes
|
eof | Matches is the input has been closed |
Common expect attributes
|
times | A container element for another matcher. Matches when the child matcher matches the given number of times. |
number - the number of times the child matcher must match Common expect attributes
|
anyOf | A container element for other matchers. Matches when any of the child matcher matches. | Common expect attributes |
allOf | A container element for other matchers. Matches when any of the child matcher matches. | Common expect attributes |
Attribute | Description |
---|---|
input | The number of the input stream. Defaults to 0. |
timeout | The timeout in milliseconds of the expect operation. Defaults to the global expect timeout |
resultPrefix | The prefix for the properties that will be set as the result of the successful expect operation. The properties key/value format is as follows: prefix .before = result.getBefore() prefix .group = result.group() prefix .success = true prefix .group.number = result.group(), where the number is between 1 and result.groupCount() |