diff --git a/include/boost/test/impl/unit_test_parameters.ipp b/include/boost/test/impl/unit_test_parameters.ipp index f49079ea3e..315942e6c0 100644 --- a/include/boost/test/impl/unit_test_parameters.ipp +++ b/include/boost/test/impl/unit_test_parameters.ipp @@ -99,6 +99,7 @@ std::string WAIT_FOR_DEBUGGER = "wait_for_debugger"; std::string HELP = "help"; std::string USAGE = "usage"; +std::string VERSION = "version"; //____________________________________________________________________________// @@ -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).", @@ -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; @@ -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( USAGE ) ) { + if( runtime_config::get( VERSION ) ) { + parser->version( std::cerr ); + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) ); + } + else if( runtime_config::get( USAGE ) ) { parser->usage( std::cerr ); BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) ); } diff --git a/include/boost/test/included/unit_test.hpp b/include/boost/test/included/unit_test.hpp index 8835acd455..993d75e4c0 100644 --- a/include/boost/test/included/unit_test.hpp +++ b/include/boost/test/included/unit_test.hpp @@ -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 #include #include @@ -32,7 +34,6 @@ #include #include -#define BOOST_TEST_INCLUDED #include #endif // BOOST_INCLUDED_UNIT_TEST_FRAMEWORK_HPP_071894GER diff --git a/include/boost/test/utils/runtime/cla/parser.hpp b/include/boost/test/utils/runtime/cla/parser.hpp index effde33a52..9fe8e1bbd9 100644 --- a/include/boost/test/utils/runtime/cla/parser.hpp +++ b/include/boost/test/utils/runtime/cla/parser.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include // !! ?? unnecessary after cxx11 @@ -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() ) { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 422e7363e2..e213a1dfd1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ] ; #_________________________________________________________________________________________________# @@ -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) ; diff --git a/test/framework-ts/version-uses-module-name.cpp b/test/framework-ts/version-uses-module-name.cpp new file mode 100644 index 0000000000..8598d67cbe --- /dev/null +++ b/test/framework-ts/version-uses-module-name.cpp @@ -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_AUTO_TEST_CASE( check ) +{ + BOOST_TEST( true ); +}