OutputCheck
OutputCheck is a tool for checking the output of console programs
that is inspired by the FileCheck tool used by LLVM. It has its own
small language (Check Directives) for describing the expected output of
a tool that is considerably more convenient and more powerful than GNU grep.
This tool was originally written for STP but it ended up being a very useful tool for other projects so it became its own project!
Obtaining OutputCheck
OutputCheck can be obtained in multple ways.
Cloning Git repository
$ git clone https://github.com/stp/OutputCheck.git
the tool can now be run as
$ cd OutputCheck/
$ bin/OutputCheck --help
Installing PyPi package
The tool is available in the Python package index. It can be installed using the pip tool.
$ pip install OutputCheck
the tool can now be run as
$ OutputCheck --help
Please note that this package may not be up to date.
It is recommended that you use virtualenv in conjunction with pip so that you do not need to install python packages as root.
Check Directives
Check Directives declare what output is expected from a tool. They are written as single line comments in a file (this file is usually used to by the tool being tested by OutputCheck).
The advantage of writing directives in this way is that the directives can be written next to the code that generates the output that the directive is checking for.
All directives use the regular expression syntax used by the re python
module. It is also important to note that the any spaces after the :
until the first non-whitespace character are not considered part of the
regular expression.
The following directives are supported
CHECK:
This declares that that regular expression should match somewhere
on a single line. This match must occur after previously declared Check directives.
Succesful example
HelloWorld.c
int main()
{
// CHECK: Hello World
printf("Hello World\n");
// CHECK: Goodbye
printf("Goodbye\n");
return 0;
}
$ cc HelloWorld.c -o HelloWorld
$ ./HelloWorld | OutputCheck HelloWorld.c
This example shows a simple C program being compiled and its output being checked. There are two CHECK: declarations which effectively say...
- At least one of the lines must match the regular expression
Hello World. - At least one line after the previous match must match regular expression
Goodbye.
It can be seen that the order the CHECK: directives are declared is important. If the directives were specified the other way round then the OutputCheck tool would report an error as shown below
Failing example
BrokenHelloWorld.c
int main()
{
// CHECK: Goodbye
printf("Hello World\n");
// CHECK: Hello World
printf("Goodbye\n");
return 0;
}
$ cc BrokenHelloWorld.c -o BrokenHelloWorld
$ ./BrokenHelloWorld | OutputCheck BrokenHelloWorld.c
ERROR: Could not find a match for Check Directive (BrokenHelloWorld.c:8 Pattern: 'Hello World')