frysk.expunit
Class Expect

java.lang.Object
  extended by frysk.expunit.Expect
Direct Known Subclasses:
TearDownExpect

public class Expect
extends Object

Simple expect like framework, that works within JUnit. This works creating a pty with a daemon process attached. XXX: At present, since it is a daemon, it isn't possible to expect an exit status.


Field Summary
private  Child child
           
private static int defaultTimeoutSeconds
          The global default timeout (in seconds).
private static Log fine
           
private  long timeoutMilliseconds
           
 
Constructor Summary
  Expect()
          Create a bash shell sitting at a prompt.
private Expect(Child child, long timeoutMilliseconds)
           
  Expect(File program)
          Create an expect instance running PROGRAM with no arguments.
  Expect(String command)
          Using bash
  Expect(String[] args)
          Create an expect instance running the specified program args[0] and args.
 
Method Summary
 void close()
          Clean up.
 void expect(Match match)
          Expect the specified pattern, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.
 void expect(Match[] matches)
          Expect a specified pattern, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.
 void expect(String regex)
          Expect the specified regular expression, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.
 void expectEOF()
          Expect an EOF.
 void expectTermination(int status)
          Expect the child process to exit with status.
 void expectTermination(Signal signal)
          Expect the child process to be terminated by SIGNAL.
 void finalize()
          Finalizer, also tries to clean up.
 ProcessIdentifier getPid()
          Return the Process ID of the child.
 void send(String string)
          Send "string" to the child process.
static void setDefaultTimeoutSeconds(int defaultTimeoutSeconds)
          Set the global default timeout (in seconds).
 Expect timeout(int timeoutSeconds)
          Create a new expect (that shares everything with the old one) only with a different timeout.
(package private)  Expect timeoutMilliseconds(long timeoutMilliseconds)
          Create a new expect (that shares everything with the old one) only with a different timeout.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fine

private static final Log fine

child

private final Child child

timeoutMilliseconds

private final long timeoutMilliseconds

defaultTimeoutSeconds

private static int defaultTimeoutSeconds
The global default timeout (in seconds).

Constructor Detail

Expect

private Expect(Child child,
               long timeoutMilliseconds)

Expect

public Expect(String[] args)
Create an expect instance running the specified program args[0] and args.


Expect

public Expect(File program)
Create an expect instance running PROGRAM with no arguments. Turns out that doing this is common and it saves the hassle of creating an argument list.


Expect

public Expect(String command)
Using bashbash it will be expanded using that shells variable and globbing rules.


Expect

public Expect()
Create a bash shell sitting at a prompt.

Method Detail

close

public void close()
Clean up. XXX: This drains all outstanding WAITPID events, and SIGCHLD events.


finalize

public void finalize()
Finalizer, also tries to clean up.

Overrides:
finalize in class Object

setDefaultTimeoutSeconds

public static void setDefaultTimeoutSeconds(int defaultTimeoutSeconds)
Set the global default timeout (in seconds). Any expect classes inherit this value.


timeout

public Expect timeout(int timeoutSeconds)
Create a new expect (that shares everything with the old one) only with a different timeout.


timeoutMilliseconds

Expect timeoutMilliseconds(long timeoutMilliseconds)
Create a new expect (that shares everything with the old one) only with a different timeout.


getPid

public ProcessIdentifier getPid()
Return the Process ID of the child.


send

public void send(String string)
Send "string" to the child process.


expect

public void expect(Match[] matches)
Expect a specified pattern, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.


expect

public void expect(Match match)
Expect the specified pattern, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.


expect

public void expect(String regex)
Expect the specified regular expression, throw a TimeoutException if the default timeout expires or EofException if end-of-file is reached.


expectEOF

public void expectEOF()
Expect an EOF.


expectTermination

public void expectTermination(int status)
Expect the child process to exit with status.


expectTermination

public void expectTermination(Signal signal)
Expect the child process to be terminated by SIGNAL.