Commit dbb7517c authored by math's avatar math
Browse files

[CHANGE]

 * We don't need to catch special boost::program_options::error exceptions just po::error suffice, since it gives a meaningful description of what actually went wrong
 * Disabled the usage-print after an option error occured, since one has to search the error message in the output
 * Error messages should be printed to stderr not stdout
 * Use TS_ASSERT_THROWS_* et. al for exception checking in the test cases
 * Added some more test cases
 * Added additionall "make vtest" target so incase something went wrong you may inspect the output of the test runner directly when calling this target
parent 960b7ee4
......@@ -84,3 +84,7 @@ ADD_CUSTOM_TARGET(stylecheck
COMMAND ${PROJECT_SOURCE_DIR}/../tools/brainlint.py ${STYLE_CPP} ${STYLE_H}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Check if code complies to CodingStandard" )
ADD_CUSTOM_TARGET(vtest
COMMAND make test ARGS="-V"
COMMENT "Runs the test in verboseness to see what actually went wrong" )
......@@ -37,22 +37,11 @@ WOptionHandler::WOptionHandler( int argc, char* argv[] )
{
parseOptions();
}
catch( po::multiple_occurrences error )
{
m_errorOccured = true;
std::cout << "Command-line option error: each option is allowed only once" << std::endl;
}
catch( po::unknown_option error )
{
m_errorOccured = true;
std::cout << "Command-line option error: " << error.what() << std::endl;
std::cout << m_desc << std::endl;
}
catch( po::error error )
{
m_errorOccured = true;
std::cout << "Unknown command-line option error: " << error.what() << std::endl;
std::cout << m_desc << std::endl;
std::cerr << "Error parsing command-line options: " << error.what() << std::endl;
std::cerr << "Try option: --help for more information." << std::endl;
}
}
......
......@@ -28,37 +28,79 @@
#include "../WOptionHandler.h"
/**
* Basic testing facilities for our OptionHandler.
*/
class WOptionHandlerTest : public CxxTest::TestSuite
{
public:
/**
* Even if invalid options are given the instantiation should not fail.
*/
void testInstanziation( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
TS_ASSERT_THROWS_NOTHING( WOptionHandler th( argc, arg ) );
}
/**
* If there are incorrect options then:
* 1. the internal error flag should be set
* 2. takeActions() should return 1
*/
void testCorrectSetErrorFlag( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
WOptionHandler th( argc, arg );
TS_ASSERT_EQUALS( th.m_errorOccured, true );
TS_ASSERT_EQUALS( th.takeActions(), 1 );
}
void testParsing( void )
/**
* If there are incorrect options a meaningful error message should be
* written to std::cerr
*/
void testParsingUnkownOption( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--thisoptiondoesnotexist" );
bool exceptionCaught = false;
WOptionHandler th( argc, arg );
try
{
th.parseOptions();
}
catch( po::error )
{
exceptionCaught = true;
}
TS_ASSERT_THROWS_EQUALS( th.parseOptions(), po::error &e, std::string( e.what() ),
"unknown option thisoptiondoesnotexist");
}
TS_ASSERT( exceptionCaught );
/**
* Using the help option (for example) should result in:
* 1. printing help to stdout (which we cannot check here)
* 2. Return immediately (don't start GUI) with exit code 0
*/
void testValidHelpOption( void )
{
const int argc = 2;
char* arg[argc];
arg[1] = const_cast<char *>( "--help" );
WOptionHandler th( argc, arg );
TS_ASSERT_EQUALS( th.takeActions(), 0 );
}
/**
* TODO(math): use QTTestLib for checking the QT-start.
*
* We cannot check if WMainApplication::runQT starts and return properly since
* it won't return unless we close the Window. At this point we should
* introduce QTTestLib to simulate the closing. But this isn't also a good
* idea since there must not be a display to which the window may connect.
* (e.g. consider automated testing without an X display)
*/
};
#endif // WOPTIONHANDLER_TEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment