@ -6,8 +6,7 @@
BOOST_AUTO_TEST_SUITE ( getarg_tests )
BOOST_AUTO_TEST_SUITE ( getarg_tests )
static void
static void ResetArgs ( const std : : string & strArg )
ResetArgs ( const std : : string & strArg )
{
{
std : : vector < std : : string > vecArg ;
std : : vector < std : : string > vecArg ;
boost : : split ( vecArg , strArg , boost : : is_space ( ) , boost : : token_compress_on ) ;
boost : : split ( vecArg , strArg , boost : : is_space ( ) , boost : : token_compress_on ) ;
@ -26,62 +25,50 @@ ResetArgs(const std::string& strArg)
BOOST_AUTO_TEST_CASE ( boolarg )
BOOST_AUTO_TEST_CASE ( boolarg )
{
{
ResetArgs ( " -foo " ) ;
ResetArgs ( " -foo " ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -fo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -fo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fooo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fooo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -fooo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -fooo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -fooo " , true ) ) ;
ResetArgs ( " -foo=0 " ) ;
ResetArgs ( " -foo=0 " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " -foo=1 " ) ;
ResetArgs ( " -foo=1 " ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
// New 0.6 feature: auto-map -nosomething to !-something:
// New 0.6 feature: auto-map -nosomething to !-something:
ResetArgs ( " -nofoo " ) ;
ResetArgs ( " -nofoo " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " -nofoo=1 " ) ;
ResetArgs ( " -nofoo=1 " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " -foo -nofoo " ) ; // -foo should win
ResetArgs ( " -foo -nofoo " ) ; // -foo should win
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " -foo=1 -nofoo=1 " ) ; // -foo should win
ResetArgs ( " -foo=1 -nofoo=1 " ) ; // -foo should win
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " -foo=0 -nofoo=0 " ) ; // -foo should win
ResetArgs ( " -foo=0 -nofoo=0 " ) ; // -foo should win
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
// New 0.6 feature: treat -- same as -:
// New 0.6 feature: treat -- same as -:
ResetArgs ( " --foo=1 " ) ;
ResetArgs ( " --foo=1 " ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
ResetArgs ( " --nofoo=1 " ) ;
ResetArgs ( " --nofoo=1 " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
@ -133,7 +120,7 @@ BOOST_AUTO_TEST_CASE(intarg)
BOOST_AUTO_TEST_CASE ( doubledash )
BOOST_AUTO_TEST_CASE ( doubledash )
{
{
ResetArgs ( " --foo " ) ;
ResetArgs ( " --foo " ) ;
BOOST_CHECK_EQUAL ( GetBoolArg ( " -foo " ) , true ) ;
BOOST_CHECK_EQUAL ( GetBoolArg ( " -foo " , false ) , true ) ;
ResetArgs ( " --foo=verbose --bar=1 " ) ;
ResetArgs ( " --foo=verbose --bar=1 " ) ;
BOOST_CHECK_EQUAL ( GetArg ( " -foo " , " " ) , " verbose " ) ;
BOOST_CHECK_EQUAL ( GetArg ( " -foo " , " " ) , " verbose " ) ;
@ -143,25 +130,24 @@ BOOST_AUTO_TEST_CASE(doubledash)
BOOST_AUTO_TEST_CASE ( boolargno )
BOOST_AUTO_TEST_CASE ( boolargno )
{
{
ResetArgs ( " -nofoo " ) ;
ResetArgs ( " -nofoo " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
ResetArgs ( " -nofoo=1 " ) ;
ResetArgs ( " -nofoo=1 " ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( ! GetBoolArg ( " -foo " , false ) ) ;
ResetArgs ( " -nofoo=0 " ) ;
ResetArgs ( " -nofoo=0 " ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
ResetArgs ( " -foo --nofoo " ) ;
ResetArgs ( " -foo --nofoo " ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
ResetArgs ( " -nofoo -foo " ) ; // foo always wins:
ResetArgs ( " -nofoo -foo " ) ; // foo always wins:
BOOST_CHECK ( GetBoolArg ( " -foo " ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , true ) ) ;
BOOST_CHECK ( GetBoolArg ( " -foo " , false ) ) ;
}
}
BOOST_AUTO_TEST_SUITE_END ( )
BOOST_AUTO_TEST_SUITE_END ( )