com.objectmentor.fixtures
Class CommandLineFixture

java.lang.Object
  |
  +--fit.Fixture
        |
        +--fit.ActionFixture
              |
              +--com.objectmentor.fixtures.CommandLineFixture

public class CommandLineFixture
extends fit.ActionFixture

A FIT test fixture that provides shell-like behavior to a FIT table. It allows you to run commands, and search their output. It allows you to invoke any shell command, either synchronously or asynchronously. It allows you to create and test files. The table rows are executed in order, from top to bottom. At the end of the table any processes that are still running are terminated and their stdout and stderr streams gathered into the cell that specified their command.

Author:
Robert C. Martin

Inner classes inherited from class fit.Fixture
fit.Fixture.Counts, fit.Fixture.RunTime
 
Fields inherited from class fit.ActionFixture
actor
 
Fields inherited from class fit.Fixture
counts, summary
 
Constructor Summary
CommandLineFixture()
           
 
Method Summary
 void command()
          Execute and wait for a command to complete.
 void contains()
          searches the existing output of the specified stream for the specified target string.
 void createFile()
          Creates a file with the specified name and the specified contents.
 void definition()
          creates a macro that will be replaced in all command and spawn commands.
 void doTable(fit.Parse table)
          Private function -- ignore.
 void fileExists()
          checks to see if a file exists.
 void find()
          searches the specified stream for the specified string.
 void pause()
          pauses execution of the table for the specified number of seconds
 void spawn()
          Starts a command but does not wait for it to finish.
 void title()
          prints a message on stdout of the FIT runner.
 void verbose()
          turns on verbose output.
 void verboseOff()
          turns verbose output off.
 void waitFor()
          Wait for a spawned process to complete.
 
Methods inherited from class fit.ActionFixture
check, doCells, enter, press, start
 
Methods inherited from class fit.Fixture
camel, check, counts, doCell, doRow, doRows, doTables, escape, escape, exception, gray, ignore, label, parse, right, wrong, wrong
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineFixture

public CommandLineFixture()
Method Detail

command

public void command()
Execute and wait for a command to complete. This command has the same syntax as spawn, except that it pauses execution of the table in order to wait for the command to complete.
See Also:
spawn()

contains

public void contains()
              throws java.lang.Exception
searches the existing output of the specified stream for the specified target string. The search does not wait for more output. Nor does it discard any lines in the existing stream. Two contains directives can be specified in any order and they will succeed so long as the target string is in the current output stream. However, any lines discareded by the find directive will not be searched.
Parameters:
streamId - See find().
target - See find().
See Also:
find()

createFile

public void createFile()
Creates a file with the specified name and the specified contents. The file is created in the directory that the FIT runner is running in.
Parameters:
filename - The name of the file to create. This can be a pathname.
contents - This string, which can contain many lines, is written to the file. Currently this operation unescapes &" sequences into double quotes.

definition

public void definition()
creates a macro that will be replaced in all command and spawn commands. These macros are recursive, so any macro that appears in another macro will be replaced properly.
Parameters:
name - The name of the macro. My convention has been to use all all uppercase for macro names, just as in C.
contents - The string that will replace the macro. This string can contain other macros.

doTable

public void doTable(fit.Parse table)
Private function -- ignore.
Overrides:
doTable in class fit.Fixture

fileExists

public void fileExists()
checks to see if a file exists.
Parameters:
filename - The name of the file to check. This can be a path.

find

public void find()
          throws java.lang.Exception
searches the specified stream for the specified string. The stream is searched line by line. The search stops at the first line that contains the specified target string. All previous lines are copied into the command cell and then discarded. They will not be searched again, either by find, or by contains. If the output stream is empty, the search waits for about a second for some output and then gives up. Use find when order is important. Use it to eliminate early output and restrict searches by find and contains to subsequent output.
Parameters:
stream - The stream to search. This stream is specified with the syntax processId.streamId. The processId is from the spawn or command method. The streamId is either 'stdout' or 'stderr'. Thus 'server.stdout' is the streamId for stdout of the server process.
target - The string to search for. No regular expressions are used right now.
See Also:
contains()

pause

public void pause()
           throws java.lang.Exception
pauses execution of the table for the specified number of seconds
Parameters:
seconds - the number of seconds to pause the table.

spawn

public void spawn()
           throws java.lang.Exception
Starts a command but does not wait for it to finish. The stdout and stderr streams are captured and accessible to the 'find' and 'contains' commands.
Parameters:
command - The command to execute
processId - An identifier for the process. This identifier can be used with other directives such as find, contains, and waitFor to reference the process and the stdout and stderr streams. This field can be left blank.

title

public void title()
prints a message on stdout of the FIT runner. Used to show progress in long test runs.
Parameters:
string - The string to print on stdout.

verbose

public void verbose()
turns on verbose output. All stdout and stderr from all commands and spawns are sent to the stdout of the FIT runner. This can be volumnous, so beware.
See Also:
verboseOff()

verboseOff

public void verboseOff()
turns verbose output off.
See Also:
verbose()

waitFor

public void waitFor()
Wait for a spawned process to complete.
Parameters:
processId - The processId of the process to wait for.