From 1d3bfa035344299f3fa1404ed0d138cf97d59fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 10 Jul 2017 14:25:38 +0200 Subject: [PATCH] More include and impl refactoring --- CMakeLists.txt | 7 +- include/catch_session.hpp | 3 +- include/internal/catch_commandline.cpp | 163 ++++++++++++++++++ include/internal/catch_commandline.hpp | 149 +--------------- include/internal/catch_console_colour.cpp | 4 + include/internal/catch_console_colour.hpp | 2 +- .../catch_exception_translator_registry.cpp | 63 +++++++ .../catch_exception_translator_registry.h | 29 ++++ .../catch_exception_translator_registry.hpp | 74 -------- .../{catch_list.hpp => catch_list.cpp} | 49 +++--- include/internal/catch_list.h | 36 ++++ include/internal/catch_registry_hub.cpp | 2 +- include/reporters/catch_reporter_console.cpp | 5 +- 13 files changed, 329 insertions(+), 257 deletions(-) create mode 100644 include/internal/catch_commandline.cpp create mode 100644 include/internal/catch_exception_translator_registry.cpp create mode 100644 include/internal/catch_exception_translator_registry.h delete mode 100644 include/internal/catch_exception_translator_registry.hpp rename include/internal/{catch_list.hpp => catch_list.cpp} (87%) create mode 100644 include/internal/catch_list.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 599a874b..137aeb8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,7 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_default_main.hpp ${HEADER_DIR}/internal/catch_errno_guard.h ${HEADER_DIR}/internal/catch_evaluate.hpp - ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp + ${HEADER_DIR}/internal/catch_exception_translator_registry.h ${HEADER_DIR}/internal/catch_expression_lhs.hpp ${HEADER_DIR}/internal/catch_fatal_condition.h ${HEADER_DIR}/internal/catch_impl.hpp @@ -147,7 +147,7 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_interfaces_runner.h ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h ${HEADER_DIR}/internal/catch_interfaces_testcase.h - ${HEADER_DIR}/internal/catch_list.hpp + ${HEADER_DIR}/internal/catch_list.h ${HEADER_DIR}/internal/catch_matchers.hpp ${HEADER_DIR}/internal/catch_matchers_string.h ${HEADER_DIR}/internal/catch_matchers_vector.h @@ -193,12 +193,15 @@ set(INTERNAL_HEADERS ) set(IMPL_SOURCES ${HEADER_DIR}/internal/catch_assertionresult.cpp + ${HEADER_DIR}/internal/catch_commandline.cpp ${HEADER_DIR}/internal/catch_common.cpp ${HEADER_DIR}/internal/catch_console_colour.cpp ${HEADER_DIR}/internal/catch_context.cpp ${HEADER_DIR}/internal/catch_debugger.cpp ${HEADER_DIR}/internal/catch_errno_guard.cpp + ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp ${HEADER_DIR}/internal/catch_fatal_condition.cpp + ${HEADER_DIR}/internal/catch_list.cpp ${HEADER_DIR}/internal/catch_matchers_string.cpp ${HEADER_DIR}/internal/catch_message.cpp ${HEADER_DIR}/internal/catch_notimplemented_exception.cpp diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 42080cd1..7acf80a6 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -9,7 +9,8 @@ #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED #include "internal/catch_commandline.hpp" -#include "internal/catch_list.hpp" +#include "internal/catch_console_colour.hpp" +#include "internal/catch_list.h" #include "internal/catch_run_context.hpp" #include "internal/catch_test_spec.hpp" #include "internal/catch_version.h" diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp new file mode 100644 index 00000000..d5f2ab4e --- /dev/null +++ b/include/internal/catch_commandline.cpp @@ -0,0 +1,163 @@ +/* + * Created by Phil on 02/11/2010. + * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. + * + * 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) + */ + +#include "catch_commandline.hpp" + +#include "catch_common.h" + +#include +#include + +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ) { + + using namespace clara; + + auto const setWarning = [&]( std::string const& warning ) { + if( warning != "NoAssertions" ) + return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); + config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const loadTestNamesFromFile = [&]( std::string const& filename ) { + std::ifstream f( filename.c_str() ); + if( !f.is_open() ) + return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); + + std::string line; + while( std::getline( f, line ) ) { + line = trim(line); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + config.testsOrTags.push_back( line + ',' ); + } + } + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setTestOrder = [&]( std::string const& order ) { + if( startsWith( "declared", order ) ) + config.runOrder = RunTests::InDeclarationOrder; + else if( startsWith( "lexical", order ) ) + config.runOrder = RunTests::InLexicographicalOrder; + else if( startsWith( "random", order ) ) + config.runOrder = RunTests::InRandomOrder; + else + return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setRngSeed = [&]( std::string const& seed ) { + if( seed != "time" ) + return clara::detail::convertInto( seed, config.rngSeed ); + config.rngSeed = static_cast( std::time(0) ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setColourUsage = [&]( std::string const& useColour ) { + auto mode = toLower( useColour ); + + if( mode == "yes" ) + config.useColour = UseColour::Yes; + else if( mode == "no" ) + config.useColour = UseColour::No; + else if( mode == "auto" ) + config.useColour = UseColour::Auto; + else + return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setVerbosity = [&]( std::string const& verbosity ) { + auto lcVerbosity = toLower( verbosity ); + if( lcVerbosity == "quiet" ) + config.verbosity = Verbosity::Quiet; + else if( lcVerbosity == "normal" ) + config.verbosity = Verbosity::Normal; + else if( lcVerbosity == "high" ) + config.verbosity = Verbosity::High; + else + return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + + auto cli + = ExeName( config.processName ) + + Help( config.showHelp ) + + Opt( config.listTests ) + ["-l"]["--list-tests"] + ( "list all/matching test cases" ) + + Opt( config.listTags ) + ["-t"]["--list-tags"] + ( "list all/matching tags" ) + + Opt( config.showSuccessfulTests ) + ["-s"]["--success"] + ( "include successful tests in output" ) + + Opt( config.shouldDebugBreak ) + ["-b"]["--break"] + ( "break into debugger on failure" ) + + Opt( config.noThrow ) + ["-e"]["--nothrow"] + ( "skip exception tests" ) + + Opt( config.showInvisibles ) + ["-i"]["--invisibles"] + ( "show invisibles (tabs, newlines)" ) + + Opt( config.outputFilename, "filename" ) + ["-o"]["--out"] + ( "output filename" ) + + Opt( config.reporterNames, "name" ) + ["-r"]["--reporter"] + ( "reporter to use (defaults to console)" ) + + Opt( config.name, "name" ) + ["-n"]["--name"] + ( "suite name" ) + + Opt( [&]( bool ){ config.abortAfter = 1; } ) + ["-a"]["--abort"] + ( "abort at first failure" ) + + Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) + ["-x"]["--abortx"] + ( "abort after x failures" ) + + Opt( setWarning, "warning name" ) + ["-w"]["--warn"] + ( "enable warnings" ) + + Opt( [&]( bool ) { config.showDurations = ShowDurations::Always; } ) + ["-d"]["--durations"] + ( "show test durations" ) + + Opt( loadTestNamesFromFile, "filename" ) + ["-f"]["--input-file"] + ( "load test names to run from a file" ) + + Opt( config.filenamesAsTags ) + ["-#"]["--filenames-as-tags"] + ( "adds a tag for the filename" ) + + Opt( config.sectionsToRun, "section name" ) + ["-c"]["--section"] + ( "specify section to run" ) + + Opt( setVerbosity, "quiet|normal|high" ) + ["-v"]["--verbosity"] + ( "set output verbosity" ) + + Opt( config.listTestNamesOnly ) + ["--list-test-names-only"] + ( "list all/matching test cases names only" ) + + Opt( config.listReporters ) + ["--list-reporters"] + ( "list all reporters" ) + + Opt( setTestOrder, "decl|lex|rand" ) + ["--order"] + ( "test case order (defaults to decl)" ) + + Opt( setRngSeed, "'time'|number" ) + ["--rng-seed"] + ( "set a specific seed for random numbers" ) + + Opt( setColourUsage, "yes|no" ) + ["--use-colour"] + ( "should output be colourised" ) + + + Arg( config.testsOrTags, "test name|pattern|tags" ) + ( "which test or tests to use" ); + + return cli; + } + +} // end namespace Catch diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index b81e9931..b73cfa2d 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -9,158 +9,11 @@ #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED #include "catch_config.hpp" -#include "catch_common.h" #include "catch_clara.h" -#include -#include - namespace Catch { - inline clara::Parser makeCommandLineParser( ConfigData& config ) { - - using namespace clara; - - auto const setWarning = [&]( std::string const& warning ) { - if( warning != "NoAssertions" ) - return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); - config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const loadTestNamesFromFile = [&]( std::string const& filename ) { - std::ifstream f( filename.c_str() ); - if( !f.is_open() ) - return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); - - std::string line; - while( std::getline( f, line ) ) { - line = trim(line); - if( !line.empty() && !startsWith( line, '#' ) ) { - if( !startsWith( line, '"' ) ) - line = '"' + line + '"'; - config.testsOrTags.push_back( line + ',' ); - } - } - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setTestOrder = [&]( std::string const& order ) { - if( startsWith( "declared", order ) ) - config.runOrder = RunTests::InDeclarationOrder; - else if( startsWith( "lexical", order ) ) - config.runOrder = RunTests::InLexicographicalOrder; - else if( startsWith( "random", order ) ) - config.runOrder = RunTests::InRandomOrder; - else - return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setRngSeed = [&]( std::string const& seed ) { - if( seed != "time" ) - return clara::detail::convertInto( seed, config.rngSeed ); - config.rngSeed = static_cast( std::time(0) ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setColourUsage = [&]( std::string const& useColour ) { - auto mode = toLower( useColour ); - - if( mode == "yes" ) - config.useColour = UseColour::Yes; - else if( mode == "no" ) - config.useColour = UseColour::No; - else if( mode == "auto" ) - config.useColour = UseColour::Auto; - else - return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setVerbosity = [&]( std::string const& verbosity ) { - auto lcVerbosity = toLower( verbosity ); - if( lcVerbosity == "quiet" ) - config.verbosity = Verbosity::Quiet; - else if( lcVerbosity == "normal" ) - config.verbosity = Verbosity::Normal; - else if( lcVerbosity == "high" ) - config.verbosity = Verbosity::High; - else - return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - - auto cli - = ExeName( config.processName ) - + Help( config.showHelp ) - + Opt( config.listTests ) - ["-l"]["--list-tests"] - ( "list all/matching test cases" ) - + Opt( config.listTags ) - ["-t"]["--list-tags"] - ( "list all/matching tags" ) - + Opt( config.showSuccessfulTests ) - ["-s"]["--success"] - ( "include successful tests in output" ) - + Opt( config.shouldDebugBreak ) - ["-b"]["--break"] - ( "break into debugger on failure" ) - + Opt( config.noThrow ) - ["-e"]["--nothrow"] - ( "skip exception tests" ) - + Opt( config.showInvisibles ) - ["-i"]["--invisibles"] - ( "show invisibles (tabs, newlines)" ) - + Opt( config.outputFilename, "filename" ) - ["-o"]["--out"] - ( "output filename" ) - + Opt( config.reporterNames, "name" ) - ["-r"]["--reporter"] - ( "reporter to use (defaults to console)" ) - + Opt( config.name, "name" ) - ["-n"]["--name"] - ( "suite name" ) - + Opt( [&]( bool ){ config.abortAfter = 1; } ) - ["-a"]["--abort"] - ( "abort at first failure" ) - + Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) - ["-x"]["--abortx"] - ( "abort after x failures" ) - + Opt( setWarning, "warning name" ) - ["-w"]["--warn"] - ( "enable warnings" ) - + Opt( [&]( bool ) { config.showDurations = ShowDurations::Always; } ) - ["-d"]["--durations"] - ( "show test durations" ) - + Opt( loadTestNamesFromFile, "filename" ) - ["-f"]["--input-file"] - ( "load test names to run from a file" ) - + Opt( config.filenamesAsTags ) - ["-#"]["--filenames-as-tags"] - ( "adds a tag for the filename" ) - + Opt( config.sectionsToRun, "section name" ) - ["-c"]["--section"] - ( "specify section to run" ) - + Opt( setVerbosity, "quiet|normal|high" ) - ["-v"]["--verbosity"] - ( "set output verbosity" ) - + Opt( config.listTestNamesOnly ) - ["--list-test-names-only"] - ( "list all/matching test cases names only" ) - + Opt( config.listReporters ) - ["--list-reporters"] - ( "list all reporters" ) - + Opt( setTestOrder, "decl|lex|rand" ) - ["--order"] - ( "test case order (defaults to decl)" ) - + Opt( setRngSeed, "'time'|number" ) - ["--rng-seed"] - ( "set a specific seed for random numbers" ) - + Opt( setColourUsage, "yes|no" ) - ["--use-colour"] - ( "should output be colourised" ) - - + Arg( config.testsOrTags, "test name|pattern|tags" ) - ( "which test or tests to use" ); - - return cli; - } + clara::Parser makeCommandLineParser( ConfigData& config ); } // end namespace Catch diff --git a/include/internal/catch_console_colour.cpp b/include/internal/catch_console_colour.cpp index 5670b8bf..6ffe7ba5 100644 --- a/include/internal/catch_console_colour.cpp +++ b/include/internal/catch_console_colour.cpp @@ -187,4 +187,8 @@ namespace Catch { impl->use( _colourCode ); } + std::ostream& operator << ( std::ostream& os, Colour const& ) { + return os; + } + } // end namespace Catch diff --git a/include/internal/catch_console_colour.hpp b/include/internal/catch_console_colour.hpp index f0a8a697..7122decc 100644 --- a/include/internal/catch_console_colour.hpp +++ b/include/internal/catch_console_colour.hpp @@ -60,7 +60,7 @@ namespace Catch { bool m_moved; }; - inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; } + std::ostream& operator << ( std::ostream& os, Colour const& ); } // end namespace Catch diff --git a/include/internal/catch_exception_translator_registry.cpp b/include/internal/catch_exception_translator_registry.cpp new file mode 100644 index 00000000..18e7c0b6 --- /dev/null +++ b/include/internal/catch_exception_translator_registry.cpp @@ -0,0 +1,63 @@ +/* + * Created by Phil on 20/04/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * 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) + */ + +#include "catch_exception_translator_registry.h" +#include "catch_result_builder.h" + +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { + deleteAll( m_translators ); + } + + void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( translator ); + } + + std::string ExceptionTranslatorRegistry::translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + return tryTranslators(); + } + @catch (NSException *exception) { + return Catch::toString( [exception description] ); + } +#else + return tryTranslators(); +#endif + } + catch( TestFailureException& ) { + throw; + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + } + + std::string ExceptionTranslatorRegistry::tryTranslators() const { + if( m_translators.empty() ) + throw; + else + return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); + } +} diff --git a/include/internal/catch_exception_translator_registry.h b/include/internal/catch_exception_translator_registry.h new file mode 100644 index 00000000..dc5d8159 --- /dev/null +++ b/include/internal/catch_exception_translator_registry.h @@ -0,0 +1,29 @@ +/* + * Created by Phil on 20/04/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * 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) + */ +#ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED + +#include "catch_interfaces_exception.h" +#include +#include + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry(); + virtual void registerTranslator( const IExceptionTranslator* translator ); + virtual std::string translateActiveException() const; + std::string tryTranslators() const; + + private: + std::vector m_translators; + }; +} + +#endif // TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED diff --git a/include/internal/catch_exception_translator_registry.hpp b/include/internal/catch_exception_translator_registry.hpp deleted file mode 100644 index 07d83f21..00000000 --- a/include/internal/catch_exception_translator_registry.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Created by Phil on 20/04/2011. - * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. - * - * 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) - */ -#ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED - -#include "catch_interfaces_exception.h" -#include "catch_tostring.h" -#include "catch_result_builder.h" - -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif - -namespace Catch { - - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - public: - ~ExceptionTranslatorRegistry() { - deleteAll( m_translators ); - } - - virtual void registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( translator ); - } - - virtual std::string translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - return tryTranslators(); - } - @catch (NSException *exception) { - return Catch::toString( [exception description] ); - } -#else - return tryTranslators(); -#endif - } - catch( TestFailureException& ) { - throw; - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; - } - catch(...) { - return "Unknown exception"; - } - } - - std::string tryTranslators() const { - if( m_translators.empty() ) - throw; - else - return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); - } - - private: - std::vector m_translators; - }; -} - -#endif // TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.cpp similarity index 87% rename from include/internal/catch_list.hpp rename to include/internal/catch_list.cpp index 5d9d8ed4..8f13be8d 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.cpp @@ -5,22 +5,24 @@ * 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) */ -#ifndef TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED -#include "catch_commandline.hpp" +#include "catch_list.h" + +#include "catch_interfaces_registry_hub.h" +#include "catch_interfaces_reporter.h" +#include "catch_interfaces_testcase.h" + #include "catch_text.h" #include "catch_console_colour.hpp" -#include "catch_interfaces_reporter.h" #include "catch_test_spec_parser.hpp" #include #include +#include namespace Catch { - inline std::size_t listTests( Config const& config ) { - + std::size_t listTests( Config const& config ) { TestSpec testSpec = config.testSpec(); if( config.testSpec().hasFilters() ) Catch::cout() << "Matching test cases:\n"; @@ -62,7 +64,7 @@ namespace Catch { return matchedTests; } - inline std::size_t listTestsNamesOnly( Config const& config ) { + std::size_t listTestsNamesOnly( Config const& config ) { TestSpec testSpec = config.testSpec(); if( !config.testSpec().hasFilters() ) testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); @@ -81,22 +83,19 @@ namespace Catch { return matchedTests; } - struct TagInfo { - void add( std::string const& spelling ) { - ++count; - spellings.insert( spelling ); - } - std::string all() const { - std::string out; - for( auto const& spelling : spellings ) - out += "[" + spelling + "]"; - return out; - } - std::set spellings; - std::size_t count = 0; - }; + void TagInfo::add( std::string const& spelling ) { + ++count; + spellings.insert( spelling ); + } - inline std::size_t listTags( Config const& config ) { + std::string TagInfo::all() const { + std::string out; + for( auto const& spelling : spellings ) + out += "[" + spelling + "]"; + return out; + } + + std::size_t listTags( Config const& config ) { TestSpec testSpec = config.testSpec(); if( config.testSpec().hasFilters() ) Catch::cout() << "Tags for matching test cases:\n"; @@ -131,7 +130,7 @@ namespace Catch { return tagCounts.size(); } - inline std::size_t listReporters( Config const& /*config*/ ) { + std::size_t listReporters( Config const& /*config*/ ) { Catch::cout() << "Available reporters:\n"; IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); std::size_t maxNameLen = 0; @@ -153,7 +152,7 @@ namespace Catch { return factories.size(); } - inline Option list( Config const& config ) { + Option list( Config const& config ) { Option listedCount; if( config.listTests() ) listedCount = listedCount.valueOr(0) + listTests( config ); @@ -167,5 +166,3 @@ namespace Catch { } } // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED diff --git a/include/internal/catch_list.h b/include/internal/catch_list.h new file mode 100644 index 00000000..daf158d0 --- /dev/null +++ b/include/internal/catch_list.h @@ -0,0 +1,36 @@ +/* + * Created by Phil on 5/11/2010. + * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. + * + * 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) + */ +#ifndef TWOBLUECUBES_CATCH_LIST_H_INCLUDED +#define TWOBLUECUBES_CATCH_LIST_H_INCLUDED + +#include "catch_option.hpp" +#include "catch_config.hpp" + +namespace Catch { + + std::size_t listTests( Config const& config ); + + std::size_t listTestsNamesOnly( Config const& config ); + + struct TagInfo { + void add( std::string const& spelling ); + std::string all() const; + + std::set spellings; + std::size_t count = 0; + }; + + std::size_t listTags( Config const& config ); + + std::size_t listReporters( Config const& /*config*/ ); + + Option list( Config const& config ); + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_LIST_H_INCLUDED diff --git a/include/internal/catch_registry_hub.cpp b/include/internal/catch_registry_hub.cpp index 9f901085..71967f58 100644 --- a/include/internal/catch_registry_hub.cpp +++ b/include/internal/catch_registry_hub.cpp @@ -10,7 +10,7 @@ #include "catch_test_case_registry_impl.hpp" #include "catch_reporter_registry.hpp" -#include "catch_exception_translator_registry.hpp" +#include "catch_exception_translator_registry.h" #include "catch_tag_alias_registry.h" #include "catch_startup_exception_registry.h" diff --git a/include/reporters/catch_reporter_console.cpp b/include/reporters/catch_reporter_console.cpp index 25ad3668..9c18e6c5 100644 --- a/include/reporters/catch_reporter_console.cpp +++ b/include/reporters/catch_reporter_console.cpp @@ -11,16 +11,13 @@ #include "../internal/catch_reporter_registrars.hpp" #include "../internal/catch_console_colour.hpp" #include "../internal/catch_version.h" -#include "../external/tbc_text_format.h" +#include "../internal/catch_text.h" #include #include namespace Catch { - using Tbc::Text; - using Tbc::TextAttributes; - struct ConsoleReporter : StreamingReporterBase { using StreamingReporterBase::StreamingReporterBase;