Gromacs
5.1.5
|
#include <testutils/cmdlinetest.h>
Helper class for tests that construct command lines that need to reference existing files.
This class provides helper methods for:
All files created during the test are cleaned up at the end of the test.
All methods can throw std::bad_alloc.
Public Member Functions | |
CommandLineTestHelper (TestFileManager *fileManager) | |
Initializes an instance. More... | |
void | setInputFileContents (CommandLine *args, const char *option, const char *extension, const std::string &contents) |
Generates and sets an input file. More... | |
void | setInputFileContents (CommandLine *args, const char *option, const char *extension, const ConstArrayRef< const char * > &contents) |
Generates and sets an input file. More... | |
void | setOutputFile (CommandLine *args, const char *option, const char *filename) |
Sets an output file parameter and adds it to the set of tested files. More... | |
void | setOutputFileNoTest (CommandLine *args, const char *option, const char *extension) |
Sets an output file parameter. More... | |
void | checkOutputFiles (TestReferenceChecker checker) const |
Checks output files added with setOutputFile() against reference data. More... | |
Static Public Member Functions | |
static int | runModule (CommandLineModuleInterface *module, CommandLine *commandLine) |
Runs a command-line program that implements CommandLineModuleInterface. More... | |
static int | runModule (CommandLineOptionsModuleInterface *(*factory)(), CommandLine *commandLine) |
Runs a command-line program that implements CommandLineOptionsModuleInterface. More... | |
|
explicit |
Initializes an instance.
fileManager | File manager to use for generating temporary file names and to track temporary files. |
void gmx::test::CommandLineTestHelper::checkOutputFiles | ( | TestReferenceChecker | checker | ) | const |
Checks output files added with setOutputFile() against reference data.
checker | Reference data root location where the reference data is stored. |
The file contents are tested verbatim, using direct string comparison. The text can be found verbatim in the reference data XML files for manual inspection.
Generates non-fatal test failures if some output file contents do not match the reference data.
|
static |
Runs a command-line program that implements CommandLineModuleInterface.
[in,out] | module | Module to run. The function does not take ownership. |
[in,out] | commandLine | Command line parameters to pass. This is only modified if module modifies it. |
unspecified | Any exception thrown by the module. |
|
static |
Runs a command-line program that implements CommandLineOptionsModuleInterface.
[in] | factory | Factory method for the module to run. |
[in,out] | commandLine | Command line parameters to pass. This is only modified if the module modifies it. |
unspecified | Any exception thrown by the factory or the module. |
void gmx::test::CommandLineTestHelper::setInputFileContents | ( | CommandLine * | args, |
const char * | option, | ||
const char * | extension, | ||
const std::string & | contents | ||
) |
Generates and sets an input file.
[in,out] | args | CommandLine to which to add the option. |
[in] | option | Option to set. |
[in] | extension | Extension for the file to create. |
[in] | contents | Text to write to the input file. |
Creates a temporary file with contents from contents
, and adds option
to args
with a value that points to the generated file.
void gmx::test::CommandLineTestHelper::setInputFileContents | ( | CommandLine * | args, |
const char * | option, | ||
const char * | extension, | ||
const ConstArrayRef< const char * > & | contents | ||
) |
Generates and sets an input file.
[in,out] | args | CommandLine to which to add the option. |
[in] | option | Option to set. |
[in] | extension | Extension for the file to create. |
[in] | contents | Text to write to the input file. |
Creates a temporary file with contents from contents
(each array entry on its own line), and adds option
to args
with a value that points to the generated file.
void gmx::test::CommandLineTestHelper::setOutputFile | ( | CommandLine * | args, |
const char * | option, | ||
const char * | filename | ||
) |
Sets an output file parameter and adds it to the set of tested files.
[in,out] | args | CommandLine to which to add the option. |
[in] | option | Option to set. |
[in] | filename | Name of the output file. |
This method:
option
to args
to point a temporary file name constructed from filename
.filename
is given to TestTemporaryFileManager to make a unique filename for the temporary file, but is not otherwise used.
Currently, this method should not be called for an XVG file, because the comments in the beginning of the file contain timestamps and other variable information, causing the test to fail. Best used only for custom data formats.
void gmx::test::CommandLineTestHelper::setOutputFileNoTest | ( | CommandLine * | args, |
const char * | option, | ||
const char * | extension | ||
) |
Sets an output file parameter.
[in,out] | args | CommandLine to which to add the option. |
[in] | option | Option to set. |
[in] | extension | Extension for the file to create. |
This method:
option
to args
to point to a temporary file name with extension extension
.This method provides the mechanism to set output files that are required to trigger computation of values that are required for the test. The contents of the output file are not tested.
Another use case is to mark files that are unconditionally produced by the code under test, but do not need to be tested. This method makes the test code aware of those files such that it can remove them at the end of the test.