Skip to content

Commit

Permalink
Boost.Test learned the '--version' command line argument
Browse files Browse the repository at this point in the history
- added '--version' that prints information equivalent to "--build_info" and then exits
- prints the Boost.Test variant in use
- moved the definition of the BOOST_TEST_INCLUDED macro on the top of the files such that CLA can safely print the Boost.Test variant in use
- added smoke test
- Module name printing should use BOOST_TEST_MODULE (and not BOOST_TEST_MAIN): adding compilation check
  • Loading branch information
raffienficiaud committed Nov 9, 2016
1 parent cbbacca commit 86bcffe
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
18 changes: 15 additions & 3 deletions include/boost/test/impl/unit_test_parameters.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ std::string WAIT_FOR_DEBUGGER = "wait_for_debugger";

std::string HELP = "help";
std::string USAGE = "usage";
std::string VERSION = "version";

This comment has been minimized.

Copy link
@tsuna

tsuna Jan 11, 2017

This variable clashes with the #define VERSION that is found in the vast majority of the projects built with the GNU Autotools.

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Jan 11, 2017

Author Member

Ok, can you open a bug on trac please? https://svn.boost.org/trac/boost/
Thanks

This comment has been minimized.

Copy link
@tsuna

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Jan 11, 2017

Author Member

Thanks!


//____________________________________________________________________________//

Expand Down Expand Up @@ -148,12 +149,11 @@ register_parameters( rt::parameters_store& store )
"compiler, STL version and Boost version."
));

///////////////////////////////////////////////

build_info.add_cla_id( "--", BUILD_INFO, "=" );
build_info.add_cla_id( "-", "i", " " );
store.add( build_info );

///////////////////////////////////////////////

rt::option catch_sys_errors( CATCH_SYS_ERRORS, (
rt::description = "Allows to switch between catching and ignoring system errors (signals).",
Expand Down Expand Up @@ -635,6 +635,14 @@ register_parameters( rt::parameters_store& store )
));
usage.add_cla_id( "-", "?", " " );
store.add( usage );

///////////////////////////////////////////////

rt::option version( VERSION, (
rt::description = "Prints Boost.Test version and exits."
));
version.add_cla_id( "--", VERSION, " " );
store.add( version );
}

static rt::arguments_store s_arguments_store;
Expand Down Expand Up @@ -668,7 +676,11 @@ init( int& argc, char** argv )
rt::finalize_arguments( s_parameters_store, s_arguments_store );

// Report help if requested
if( runtime_config::get<bool>( USAGE ) ) {
if( runtime_config::get<bool>( VERSION ) ) {
parser->version( std::cerr );
BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) );
}
else if( runtime_config::get<bool>( USAGE ) ) {
parser->usage( std::cerr );
BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) );
}
Expand Down
3 changes: 2 additions & 1 deletion include/boost/test/included/unit_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef BOOST_INCLUDED_UNIT_TEST_FRAMEWORK_HPP_071894GER
#define BOOST_INCLUDED_UNIT_TEST_FRAMEWORK_HPP_071894GER

#define BOOST_TEST_INCLUDED

#include <boost/test/impl/compiler_log_formatter.ipp>
#include <boost/test/impl/junit_log_formatter.ipp>
#include <boost/test/impl/debug.ipp>
Expand All @@ -32,7 +34,6 @@
#include <boost/test/impl/junit_log_formatter.ipp>
#include <boost/test/impl/xml_report_formatter.ipp>

#define BOOST_TEST_INCLUDED
#include <boost/test/unit_test.hpp>

#endif // BOOST_INCLUDED_UNIT_TEST_FRAMEWORK_HPP_071894GER
33 changes: 32 additions & 1 deletion include/boost/test/utils/runtime/cla/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <boost/test/utils/foreach.hpp>
#include <boost/test/utils/algorithm.hpp>
#include <boost/test/detail/throw_exception.hpp>
#include <boost/test/detail/global_typedef.hpp>

#include <boost/algorithm/cxx11/all_of.hpp> // !! ?? unnecessary after cxx11

Expand Down Expand Up @@ -254,7 +255,37 @@ class parser {
return tr.remainder();
}

// help/usage
// help/usage/version
void
version( std::ostream& ostr )
{
ostr << "Boost.Test module ";

#if defined(BOOST_TEST_MODULE)
// we do not want to refer to the master test suite there
ostr << '\'' << BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ) << "' ";
#endif

ostr << "in executable '" << m_program_name << "'\n";
ostr << "Compiled from Boost version "
<< BOOST_VERSION/100000 << "."
<< BOOST_VERSION/100 % 1000 << "."
<< BOOST_VERSION % 100 ;
ostr << " with ";
#if defined(BOOST_TEST_INCLUDED)
ostr << "single header inclusion of";
#elif defined(BOOST_TEST_DYN_LINK)
ostr << "dynamic linking to";
#else
ostr << "static linking to";
#endif
ostr << " Boost.Test\n";
ostr << "- Compiler: " << BOOST_COMPILER << '\n'
<< "- Platform: " << BOOST_PLATFORM << '\n'
<< "- STL : " << BOOST_STDLIB;
ostr << std::endl;
}

void
usage( std::ostream& ostr, cstring param_name = cstring() )
{
Expand Down
2 changes: 2 additions & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ test-suite "framework-ts"
[ boost.test-self-test run : framework-ts : result-report-test : : baseline-outputs/result-report-test.pattern ]
[ boost.test-self-test run : framework-ts : log-formatter-test : : baseline-outputs/log-formatter-test.pattern ]
[ boost.test-self-test run : framework-ts : run-by-name-or-label-test ]
[ boost.test-self-test run : framework-ts : version-uses-module-name : included ]
;

#_________________________________________________________________________________________________#
Expand Down Expand Up @@ -296,6 +297,7 @@ alias "smoke-ts"
[ boost.test-smoke-ts-logger bt-st-thrf : HRF : report ]
[ boost.test-smoke-ts-logger bt-st-tjunit : JUNIT : log ]
[ boost.test-smoke-ts-logger bt-st-tjunit : JUNIT : log : : yes ]
[ run smoke-ts-included : --version : : $(requirements_datasets) : cla-check-print-version ]
# : $(requirements_datasets)
;

Expand Down
18 changes: 18 additions & 0 deletions test/framework-ts/version-uses-module-name.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// (C) Copyright Raffi Enficiaud 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/test for the library home page.

// explicitely not using BOOST_TEST_MODULE to check the compilation of the
// parser (prints the BOOST_TEST_MODULE if defined)
// Also this should be the included version

#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE( check )
{
BOOST_TEST( true );
}

0 comments on commit 86bcffe

Please sign in to comment.