From: Russ Combs (rucombs) Date: Mon, 26 Mar 2018 12:05:06 +0000 (-0400) Subject: Merge pull request #1163 in SNORT/snort3 from tidy_catch to master X-Git-Tag: 3.0.0-245~68 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7902706da4d297169503a5a64eeb778cfbc39748;p=thirdparty%2Fsnort3.git Merge pull request #1163 in SNORT/snort3 from tidy_catch to master Squashed commit of the following: commit e17dedf666af4553655d0d08dc83ef679b6f3f1c Author: Michael Altizer Date: Mon Mar 26 00:07:00 2018 -0400 build: Clean up HAVE_* definition checks commit aa8ee8f3c9aa4ed7736bad8692d5ac5767073326 Author: Michael Altizer Date: Sun Mar 25 14:22:18 2018 -0400 build: Modernize code with =default for special member functions Generated automatically with run-clang-tidy.py -header-filter=$(realpath ..) -checks='-*,modernize-use-equals-default' -fix. commit 8efb3c0b04500b685b02d950ef26b69420794ab2 Author: Michael Altizer Date: Sun Mar 25 14:17:23 2018 -0400 build: Modernize code with virtual/override/final cleanups Generated automatically with run-clang-tidy.py -header-filter=$(realpath ..) -checks='-*,modernize-use-override' -fix. commit adc85e1b6040f9d22fb230270de172420084487b Author: Michael Altizer Date: Sun Mar 25 14:14:24 2018 -0400 catch: Update to Catch v2.2.1 --- diff --git a/cmake/sanity_checks.cmake b/cmake/sanity_checks.cmake index ace993297..4907516cb 100644 --- a/cmake/sanity_checks.cmake +++ b/cmake/sanity_checks.cmake @@ -5,10 +5,17 @@ include(CheckTypeSize) include(CheckLibraryExists) include(CheckCXXSourceCompiles) - include (TestBigEndian) test_big_endian(WORDS_BIGENDIAN) +#-------------------------------------------------------------------------- +# Checks for system library functions +#-------------------------------------------------------------------------- + +check_function_exists(mallinfo HAVE_MALLINFO) +check_function_exists(malloc_trim HAVE_MALLOC_TRIM) +check_function_exists(memrchr HAVE_MEMRCHR) +check_function_exists(sigaction HAVE_SIGACTION) #-------------------------------------------------------------------------- # Checks for typedefs, structures, and compiler characteristics. diff --git a/config.cmake.h.in b/config.cmake.h.in index 417acf990..ba8014274 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -25,71 +25,69 @@ /* but luckily it is not yet needed */ #define API_OPTIONS "" -/* User configured options */ -/* include internal inspectors in binary */ -#cmakedefine STATIC_INSPECTORS 1 +/* User-configured options */ -/* include internal loggers in binary */ -#cmakedefine STATIC_LOGGERS 1 +/* enable debug messages */ +#cmakedefine DEBUG_MSGS 1 -/* include internal ips actions in binary */ -#cmakedefine STATIC_IPS_ACTIONS 1 +/* enable profiling */ +#cmakedefine PROFILE 1 -/* include internal ips options in binary */ -#cmakedefine STATIC_IPS_OPTIONS 1 +/* do not generate a core file on segfault etc */ +#cmakedefine NOCOREFILE 1 -/* include internal inspectors in binary */ -#cmakedefine STATIC_SEARCH_ENGINES 1 +/* enable piglet */ +#cmakedefine PIGLET 1 + +/* enable command shell */ +#cmakedefine SHELL 1 /* include internal decoders in binary */ #cmakedefine STATIC_CODECS 1 -/* enalbe debug messages */ -#cmakedefine DEBUG_MSGS 1 +/* include internal inspectors in binary */ +#cmakedefine STATIC_INSPECTORS 1 -/* enable profiling */ -#cmakedefine PROFILE 1 +/* include internal ips actions in binary */ +#cmakedefine STATIC_IPS_ACTIONS 1 -/* do not generate a core file on segfault etc */ -#cmakedefine NOCOREFILE 1 +/* include internal ips options in binary */ +#cmakedefine STATIC_IPS_OPTIONS 1 -/* enable ha capable build */ -#cmakedefine ENABLE_HA 1 +/* include internal loggers in binary */ +#cmakedefine STATIC_LOGGERS 1 + +/* include internal inspectors in binary */ +#cmakedefine STATIC_SEARCH_ENGINES 1 -/* enable unit tests in build */ +/* enable unit tests */ #cmakedefine UNIT_TEST 1 -/* enable piglet in build */ -#cmakedefine PIGLET 1 +/* enable stdlog */ +#cmakedefine USE_STDLOG 1 + +/* enable tsc clock */ +#cmakedefine USE_TSC_CLOCK 1 -/* Set by user */ +/* signal to dump stats */ #cmakedefine SIGNAL_SNORT_DUMP_STATS @SIGNAL_SNORT_DUMP_STATS@ -/* Set by user */ +/* signal to reload attribute table */ #cmakedefine SIGNAL_SNORT_READ_ATTR_TBL @SIGNAL_SNORT_READ_ATTR_TBL@ -/* Set by user */ +/* signal to reload configuration */ #cmakedefine SIGNAL_SNORT_RELOAD @SIGNAL_SNORT_RELOAD@ -/* Set by user */ +/* signal to reload stats */ #cmakedefine SIGNAL_SNORT_ROTATE_STATS @SIGNAL_SNORT_ROTATE_STATS@ -/* enable ha capable build */ -#cmakedefine SHELL 1 - /* large pcap options */ #cmakedefine _LARGEFILE_SOURCE 1 #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ -/* enable stdlog */ -#cmakedefine USE_STDLOG 1 - -/* enable tsc clock */ -#cmakedefine USE_TSC_CLOCK 1 - -/* Print available system types and their sizes */ +/* System types and their sizes */ /* The size of `long int', as computed by sizeof. */ #cmakedefine SIZEOF_LONG_INT @SIZEOF_LONG_INT@ @@ -125,10 +123,23 @@ #cmakedefine HAVE_UUID 1 -/* Library specific functions */ + +/* Availability of specific library functions */ + +/* Define to 1 if you have the `mallinfo' function. */ +#define HAVE_MALLINFO 1 + +/* Define to 1 if you have the `malloc_trim' function. */ +#define HAVE_MALLOC_TRIM 1 + +/* Define to 1 if you have the `memrchr' function. */ +#define HAVE_MEMRCHR 1 + +/* Define to 1 if you have the `sigaction' function. */ +#define HAVE_SIGACTION 1 -/* Available compiler options */ +/* Available compiler options */ /* Define if the compiler supports visibility declarations. */ #cmakedefine HAVE_VISIBILITY 1 diff --git a/src/catch/catch.hpp b/src/catch/catch.hpp index ef7209083..081cb41d8 100644 --- a/src/catch/catch.hpp +++ b/src/catch/catch.hpp @@ -1,6 +1,6 @@ /* - * Catch v2.1.0 - * Generated: 2018-01-10 13:51:15.378034 + * Catch v2.2.1 + * Generated: 2018-03-11 12:01:31.654719 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. @@ -13,6 +13,10 @@ // start catch.hpp +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 2 +#define CATCH_VERSION_PATCH 1 + #ifdef __clang__ # pragma clang system_header #elif defined __GNUC__ @@ -116,6 +120,14 @@ namespace Catch { # define CATCH_CPP14_OR_GREATER # endif +# if __cplusplus >= 201703L +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +#if defined(CATCH_CPP17_OR_GREATER) +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS #endif #ifdef __clang__ @@ -136,13 +148,15 @@ namespace Catch { #endif // __clang__ //////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) - -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# endif +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS #endif #ifdef __OS400__ @@ -164,6 +178,10 @@ namespace Catch { // Visual C++ #ifdef _MSC_VER +# if _MSC_VER >= 1900 // Visual Studio 2015 or newer +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +# endif + // Universal Windows platform does not support SEH // Or console colours (or console at all...) # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) @@ -176,6 +194,13 @@ namespace Catch { //////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// + // Use of __COUNTER__ is suppressed during code analysis in // CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly // handled by it. @@ -192,9 +217,17 @@ namespace Catch { # define CATCH_CONFIG_WINDOWS_SEH #endif // This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) # define CATCH_CONFIG_POSIX_SIGNALS #endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) +# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS @@ -423,16 +456,20 @@ namespace Catch { public: // substrings and searches auto substr( size_type start, size_type size ) const noexcept -> StringRef; + // Returns the current start pointer. + // Note that the pointer can change when if the StringRef is a substring + auto currentData() const noexcept -> char const*; + private: // ownership queries - may not be consistent between calls auto isOwned() const noexcept -> bool; auto isSubstring() const noexcept -> bool; - auto data() const noexcept -> char const*; }; auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { @@ -464,13 +501,13 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* { } struct NameAndTags { - NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept; + NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept; StringRef name; StringRef tags; }; struct AutoReg : NonCopyable { - AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept; + AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; ~AutoReg(); }; @@ -733,13 +770,18 @@ namespace Catch { std::string convertUnknownEnumToString( E e ); template - typename std::enable_if::value, std::string>::type convertUnstreamable( T const& ) { + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { +#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) + (void)value; return Detail::unprintableString; - }; +#else + return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); +#endif + } template typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { return convertUnknownEnumToString( value ); - }; + } } // namespace Detail @@ -785,10 +827,12 @@ namespace Catch { struct StringMaker { static std::string convert(const std::string& str); }; +#ifdef CATCH_CONFIG_WCHAR template<> struct StringMaker { static std::string convert(const std::wstring& wstr); }; +#endif template<> struct StringMaker { @@ -798,6 +842,7 @@ namespace Catch { struct StringMaker { static std::string convert(char * str); }; +#ifdef CATCH_CONFIG_WCHAR template<> struct StringMaker { static std::string convert(wchar_t const * str); @@ -806,18 +851,7 @@ namespace Catch { struct StringMaker { static std::string convert(wchar_t * str); }; - - template - struct is_string_array : std::false_type {}; - - template - struct is_string_array : std::true_type {}; - - template - struct is_string_array : std::true_type {}; - - template - struct is_string_array : std::true_type {}; +#endif template struct StringMaker { @@ -1069,12 +1103,19 @@ namespace Catch { } template - struct StringMaker::value && !is_string_array::value>::type> { + struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>::type> { static std::string convert( R const& range ) { return rangeToString( range ); } }; + template + struct StringMaker { + static std::string convert(T const(&arr)[SZ]) { + return rangeToString(arr); + } + }; + } // namespace Catch // Separate std::chrono::duration specialization @@ -1269,7 +1310,7 @@ namespace Catch { // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) template - auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; }; + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); } template auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } template @@ -1280,7 +1321,7 @@ namespace Catch { auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } template - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; }; + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); } template auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } template @@ -1314,19 +1355,19 @@ namespace Catch { template auto operator > ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs > rhs, m_lhs, ">", rhs }; + return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; } template auto operator < ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs < rhs, m_lhs, "<", rhs }; + return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; } template auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs >= rhs, m_lhs, ">=", rhs }; + return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; } template auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs <= rhs, m_lhs, "<=", rhs }; + return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; } auto makeUnaryExpr() const -> UnaryExpr { @@ -1724,6 +1765,7 @@ namespace Catch { Totals delta( Totals const& prevTotals ) const; + int error = 0; Counts assertions; Counts testCases; }; @@ -2681,7 +2723,7 @@ namespace Catch { class TestCase : public TestCaseInfo { public: - TestCase( ITestInvoker* testCase, TestCaseInfo const& info ); + TestCase( ITestInvoker* testCase, TestCaseInfo&& info ); TestCase withName( std::string const& _newName ) const; @@ -2698,8 +2740,7 @@ namespace Catch { TestCase makeTestCase( ITestInvoker* testCase, std::string const& className, - std::string const& name, - std::string const& description, + NameAndTags const& nameAndTags, SourceLineInfo const& lineInfo ); } @@ -3129,7 +3170,8 @@ namespace Catch { struct WarnAbout { enum What { Nothing = 0x00, - NoAssertions = 0x01 + NoAssertions = 0x01, + NoTests = 0x02 }; }; struct ShowDurations { enum OrNot { @@ -3166,10 +3208,12 @@ namespace Catch { virtual bool includeSuccessfulResults() const = 0; virtual bool shouldDebugBreak() const = 0; virtual bool warnAboutMissingAssertions() const = 0; + virtual bool warnAboutNoTests() const = 0; virtual int abortAfter() const = 0; virtual bool showInvisibles() const = 0; virtual ShowDurations::OrNot showDurations() const = 0; virtual TestSpec const& testSpec() const = 0; + virtual bool hasTestFilters() const = 0; virtual RunTests::InWhatOrder runOrder() const = 0; virtual unsigned int rngSeed() const = 0; virtual int benchmarkResolutionMultiple() const = 0; @@ -3247,9 +3291,11 @@ namespace Catch { std::string getProcessName() const; std::vector const& getReporterNames() const; + std::vector const& getTestsOrTags() const; std::vector const& getSectionsToRun() const override; virtual TestSpec const& testSpec() const override; + bool hasTestFilters() const override; bool showHelp() const; @@ -3259,6 +3305,7 @@ namespace Catch { std::string name() const override; bool includeSuccessfulResults() const override; bool warnAboutMissingAssertions() const override; + bool warnAboutNoTests() const override; ShowDurations::OrNot showDurations() const override; RunTests::InWhatOrder runOrder() const override; unsigned int rngSeed() const override; @@ -3276,6 +3323,7 @@ namespace Catch { std::unique_ptr m_stream; TestSpec m_testSpec; + bool m_hasTestFilters = false; }; } // end namespace Catch @@ -3886,10 +3934,11 @@ namespace Catch { BrightGreen = Bright | Green, LightGrey = Bright | Grey, BrightWhite = Bright | White, + BrightYellow = Bright | Yellow, // By intention FileName = LightGrey, - Warning = Yellow, + Warning = BrightYellow, ResultError = BrightRed, ResultSuccess = BrightGreen, ResultExpectedFailure = Warning, @@ -3898,7 +3947,7 @@ namespace Catch { Success = Green, OriginalExpression = Cyan, - ReconstructedExpression = Yellow, + ReconstructedExpression = BrightYellow, SecondaryText = LightGrey, Headers = White @@ -4611,7 +4660,10 @@ namespace Catch { #ifdef CATCH_TRAP #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } #else - #define CATCH_BREAK_INTO_DEBUGGER() (void)0, 0 + namespace Catch { + inline void doNothing() {} + } + #define CATCH_BREAK_INTO_DEBUGGER() Catch::doNothing() #endif // end catch_debugger.h @@ -4619,9 +4671,6 @@ namespace Catch { // start catch_fatal_condition.h -#include - -#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// // start catch_windows_h_proxy.h @@ -4652,16 +4701,7 @@ namespace Catch { #endif // defined(CATCH_PLATFORM_WINDOWS) // end catch_windows_h_proxy.h - -# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} - -# else // CATCH_CONFIG_WINDOWS_SEH is defined +#if defined( CATCH_CONFIG_WINDOWS_SEH ) namespace Catch { @@ -4680,19 +4720,7 @@ namespace Catch { } // namespace Catch -# endif // CATCH_CONFIG_WINDOWS_SEH - -#else // Not Windows - assumed to be POSIX compatible ////////////////////////// - -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) - -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} - -# else // CATCH_CONFIG_POSIX_SIGNALS is defined +#elif defined ( CATCH_CONFIG_POSIX_SIGNALS ) #include @@ -4701,7 +4729,7 @@ namespace Catch { struct FatalConditionHandler { static bool isSet; - static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)]; + static struct sigaction oldSigActions[]; static stack_t oldSigStack; static char altStackMem[]; @@ -4714,9 +4742,15 @@ namespace Catch { } // namespace Catch -# endif // CATCH_CONFIG_POSIX_SIGNALS +#else -#endif // not Windows +namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} + +#endif // end catch_fatal_condition.h #include @@ -4997,9 +5031,9 @@ namespace Catch { expr = m_info.capturedExpression; else { expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); - expr += m_info.macroName.c_str(); + expr += m_info.macroName; expr += "( "; - expr += m_info.capturedExpression.c_str(); + expr += m_info.capturedExpression; expr += " )"; } return expr; @@ -5062,7 +5096,7 @@ namespace Catch { using StringMatcher = Matchers::Impl::MatcherBase; // This is the general overload that takes a any string matcher - // There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers + // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers // the Equals matcher (so the header does not mention matchers) void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { std::string exceptionMessage = Catch::translateActiveException(); @@ -5093,8 +5127,14 @@ namespace Catch { #endif // start clara.hpp -// v1.0-develop.2 -// See https://github.com/philsquared/Clara +// Copyright 2017 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) +// +// See https://github.com/philsquared/Clara for more details + +// Clara v1.1.4 #ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH @@ -5105,6 +5145,15 @@ namespace Catch { #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH #endif +#ifndef CLARA_CONFIG_OPTIONAL_TYPE +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +#include +#define CLARA_CONFIG_OPTIONAL_TYPE std::optional +#endif +#endif +#endif + // ----------- #included from clara_textflow.hpp ----------- // TextFlowCpp @@ -5457,7 +5506,7 @@ namespace detail { template struct UnaryLambdaTraits { static const bool isValid = true; - using ArgType = typename std::remove_const::type>::type;; + using ArgType = typename std::remove_const::type>::type; using ReturnType = ReturnT; }; @@ -5470,11 +5519,9 @@ namespace detail { std::vector m_args; public: - Args( int argc, char *argv[] ) { - m_exeName = argv[0]; - for( int i = 1; i < argc; ++i ) - m_args.push_back( argv[i] ); - } + Args( int argc, char const* const* argv ) + : m_exeName(argv[0]), + m_args(argv + 1, argv + argc) {} Args( std::initializer_list args ) : m_exeName( *args.begin() ), @@ -5621,7 +5668,7 @@ namespace detail { return *this; } - ~ResultValueBase() { + ~ResultValueBase() override { if( m_type == Ok ) m_value.~T(); } @@ -5659,16 +5706,14 @@ namespace detail { auto errorMessage() const -> std::string { return m_errorMessage; } protected: - virtual void enforceOk() const { - // !TBD: If no exceptions, std::terminate here or something - switch( m_type ) { - case ResultBase::LogicError: - throw std::logic_error( m_errorMessage ); - case ResultBase::RuntimeError: - throw std::runtime_error( m_errorMessage ); - case ResultBase::Ok: - break; - } + void enforceOk() const override { + + // Errors shouldn't reach this point, but if they do + // the actual error message will be in m_errorMessage + assert( m_type != ResultBase::LogicError ); + assert( m_type != ResultBase::RuntimeError ); + if( m_type != ResultBase::Ok ) + std::abort(); } std::string m_errorMessage; // Only populated if resultType is an error @@ -5738,47 +5783,43 @@ namespace detail { return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); return ParserResult::ok( ParseResultType::Matched ); } +#ifdef CLARA_CONFIG_OPTIONAL_TYPE + template + inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { + T temp; + auto result = convertInto( source, temp ); + if( result ) + target = std::move(temp); + return result; + } +#endif // CLARA_CONFIG_OPTIONAL_TYPE - struct BoundRefBase { - BoundRefBase() = default; - BoundRefBase( BoundRefBase const & ) = delete; - BoundRefBase( BoundRefBase && ) = delete; - BoundRefBase &operator=( BoundRefBase const & ) = delete; - BoundRefBase &operator=( BoundRefBase && ) = delete; - - virtual ~BoundRefBase() = default; + struct NonCopyable { + NonCopyable() = default; + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable &operator=( NonCopyable const & ) = delete; + NonCopyable &operator=( NonCopyable && ) = delete; + }; - virtual auto isFlag() const -> bool = 0; + struct BoundRef : NonCopyable { + virtual ~BoundRef() = default; virtual auto isContainer() const -> bool { return false; } - virtual auto setValue( std::string const &arg ) -> ParserResult = 0; - virtual auto setFlag( bool flag ) -> ParserResult = 0; + virtual auto isFlag() const -> bool { return false; } }; - - struct BoundValueRefBase : BoundRefBase { - auto isFlag() const -> bool override { return false; } - - auto setFlag( bool ) -> ParserResult override { - return ParserResult::logicError( "Flags can only be set on boolean fields" ); - } + struct BoundValueRefBase : BoundRef { + virtual auto setValue( std::string const &arg ) -> ParserResult = 0; }; - - struct BoundFlagRefBase : BoundRefBase { - auto isFlag() const -> bool override { return true; } - - auto setValue( std::string const &arg ) -> ParserResult override { - bool flag; - auto result = convertInto( arg, flag ); - if( result ) - setFlag( flag ); - return result; - } + struct BoundFlagRefBase : BoundRef { + virtual auto setFlag( bool flag ) -> ParserResult = 0; + virtual auto isFlag() const -> bool { return true; } }; template - struct BoundRef : BoundValueRefBase { + struct BoundValueRef : BoundValueRefBase { T &m_ref; - explicit BoundRef( T &ref ) : m_ref( ref ) {} + explicit BoundValueRef( T &ref ) : m_ref( ref ) {} auto setValue( std::string const &arg ) -> ParserResult override { return convertInto( arg, m_ref ); @@ -5786,10 +5827,10 @@ namespace detail { }; template - struct BoundRef> : BoundValueRefBase { + struct BoundValueRef> : BoundValueRefBase { std::vector &m_ref; - explicit BoundRef( std::vector &ref ) : m_ref( ref ) {} + explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} auto isContainer() const -> bool override { return true; } @@ -5834,12 +5875,12 @@ namespace detail { template inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { - ArgType temp; + ArgType temp{}; auto result = convertInto( arg, temp ); return !result ? result : LambdaInvoker::ReturnType>::invoke( lambda, temp ); - }; + } template struct BoundLambda : BoundValueRefBase { @@ -5888,6 +5929,9 @@ namespace detail { public: template auto operator|( T const &other ) const -> Parser; + + template + auto operator+( T const &other ) const -> Parser; }; // Common code and state for Args and Opts @@ -5895,16 +5939,16 @@ namespace detail { class ParserRefImpl : public ComposableParserImpl { protected: Optionality m_optionality = Optionality::Optional; - std::shared_ptr m_ref; + std::shared_ptr m_ref; std::string m_hint; std::string m_description; - explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} public: template ParserRefImpl( T &ref, std::string const &hint ) - : m_ref( std::make_shared>( ref ) ), + : m_ref( std::make_shared>( ref ) ), m_hint( hint ) {} @@ -5945,10 +5989,10 @@ namespace detail { class ExeName : public ComposableParserImpl { std::shared_ptr m_name; - std::shared_ptr m_ref; + std::shared_ptr m_ref; template - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { return std::make_shared>( lambda) ; } @@ -5956,7 +6000,7 @@ namespace detail { ExeName() : m_name( std::make_shared( "" ) ) {} explicit ExeName( std::string &ref ) : ExeName() { - m_ref = std::make_shared>( ref ); + m_ref = std::make_shared>( ref ); } template @@ -5999,7 +6043,10 @@ namespace detail { if( token.type != TokenType::Argument ) return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - auto result = m_ref->setValue( remainingTokens->token ); + assert( !m_ref->isFlag() ); + auto valueRef = static_cast( m_ref.get() ); + + auto result = valueRef->setValue( remainingTokens->token ); if( !result ) return InternalParseResult( result ); else @@ -6073,19 +6120,21 @@ namespace detail { auto const &token = *remainingTokens; if( isMatch(token.token ) ) { if( m_ref->isFlag() ) { - auto result = m_ref->setFlag( true ); + auto flagRef = static_cast( m_ref.get() ); + auto result = flagRef->setFlag( true ); if( !result ) return InternalParseResult( result ); if( result.value() == ParseResultType::ShortCircuitAll ) return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); } else { + auto valueRef = static_cast( m_ref.get() ); ++remainingTokens; if( !remainingTokens ) return InternalParseResult::runtimeError( "Expected argument following " + token.token ); auto const &argToken = *remainingTokens; if( argToken.type != TokenType::Argument ) return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto result = m_ref->setValue( argToken.token ); + auto result = valueRef->setValue( argToken.token ); if( !result ) return InternalParseResult( result ); if( result.value() == ParseResultType::ShortCircuitAll ) @@ -6161,6 +6210,12 @@ namespace detail { return Parser( *this ) |= other; } + // Forward deprecated interface with '+' instead of '|' + template + auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } + template + auto operator+( T const &other ) const -> Parser { return operator|( other ); } + auto getHelpColumns() const -> std::vector { std::vector cols; for (auto const &o : m_options) { @@ -6200,6 +6255,8 @@ namespace detail { for( auto const &cols : rows ) optWidth = (std::max)(optWidth, cols.left.size() + 2); + optWidth = (std::min)(optWidth, consoleWidth/2); + for( auto const &cols : rows ) { auto row = TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + @@ -6339,9 +6396,19 @@ namespace Catch { using namespace clara; auto const setWarning = [&]( std::string const& warning ) { - if( warning != "NoAssertions" ) + auto warningSet = [&]() { + if( warning == "NoAssertions" ) + return WarnAbout::NoAssertions; + + if ( warning == "NoTests" ) + return WarnAbout::NoTests; + + return WarnAbout::Nothing; + }(); + + if (warningSet == WarnAbout::Nothing) return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); - config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); + config.warnings = static_cast( config.warnings | warningSet ); return ParserResult::ok( ParseResultType::Matched ); }; auto const loadTestNamesFromFile = [&]( std::string const& filename ) { @@ -6542,10 +6609,9 @@ namespace Catch { // start catch_enforce.h #include -#include #define CATCH_PREPARE_EXCEPTION( type, msg ) \ - type( static_cast( Catch::ReusableStringStream().get() << msg ).str() ) + type( ( Catch::ReusableStringStream() << msg ).str() ) #define CATCH_INTERNAL_ERROR( msg ) \ throw CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg); #define CATCH_ERROR( msg ) \ @@ -6560,12 +6626,16 @@ namespace Catch { : m_data( data ), m_stream( openStream() ) { - if( !data.testsOrTags.empty() ) { - TestSpecParser parser( ITagAliasRegistry::get() ); + TestSpecParser parser(ITagAliasRegistry::get()); + if (data.testsOrTags.empty()) { + parser.parse("~[.]"); // All not hidden tests + } + else { + m_hasTestFilters = true; for( auto const& testOrTags : data.testsOrTags ) parser.parse( testOrTags ); - m_testSpec = parser.testSpec(); } + m_testSpec = parser.testSpec(); } std::string const& Config::getFilename() const { @@ -6580,9 +6650,11 @@ namespace Catch { std::string Config::getProcessName() const { return m_data.processName; } std::vector const& Config::getReporterNames() const { return m_data.reporterNames; } + std::vector const& Config::getTestsOrTags() const { return m_data.testsOrTags; } std::vector const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } TestSpec const& Config::testSpec() const { return m_testSpec; } + bool Config::hasTestFilters() const { return m_hasTestFilters; } bool Config::showHelp() const { return m_data.showHelp; } @@ -6591,7 +6663,8 @@ namespace Catch { std::ostream& Config::stream() const { return m_stream->stream(); } std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - bool Config::warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } + bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); } + bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); } ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } unsigned int Config::rngSeed() const { return m_data.rngSeed; } @@ -6690,8 +6763,12 @@ namespace { case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + + default: + CATCH_ERROR( "Unknown colour requested" ); } } @@ -6749,8 +6826,10 @@ namespace { case Colour::BrightRed: return setColour( "[1;31m" ); case Colour::BrightGreen: return setColour( "[1;32m" ); case Colour::BrightWhite: return setColour( "[1;37m" ); + case Colour::BrightYellow: return setColour( "[1;33m" ); case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + default: CATCH_INTERNAL_ERROR( "Unknown colour requested" ); } } static IColourImpl* instance() { @@ -6769,7 +6848,12 @@ namespace { #ifdef CATCH_PLATFORM_MAC !isDebuggerActive() && #endif - isatty(STDOUT_FILENO); +#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__)) + isatty(STDOUT_FILENO) +#else + false +#endif + ; } IColourImpl* platformColourInstance() { ErrnoGuard guard; @@ -6903,13 +6987,16 @@ namespace Catch { ::OutputDebugStringA( text.c_str() ); } } + #else + namespace Catch { void writeToDebugConsole( std::string const& text ) { // !TBD: Need a version for Mac/ XCode and other IDEs Catch::cout() << text; } } + #endif // Platform // end catch_debug_console.cpp // start catch_debugger.cpp @@ -7086,6 +7173,17 @@ namespace Catch { return Catch::Detail::stringify( [exception description] ); } #else + // Compiling a mixed mode project with MSVC means that CLR + // exceptions will be caught in (...) as well. However, these + // do not fill-in std::current_exception and thus lead to crash + // when attempting rethrow. + // /EHa switch also causes structured exceptions to be caught + // here, but they fill-in current_exception properly, so + // at worst the output should be a little weird, instead of + // causing a crash. + if (std::current_exception() == nullptr) { + return "Non C++ exception. Possibly a CLR exception."; + } return tryTranslators(); #endif } @@ -7121,6 +7219,8 @@ namespace Catch { # pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif +#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS ) + namespace { // Report the error condition void reportFatal( char const * const message ) { @@ -7128,15 +7228,9 @@ namespace { } } -#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// +#endif // signals/SEH handling -# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - void FatalConditionHandler::reset() {} -} - -# else // CATCH_CONFIG_WINDOWS_SEH is defined +#if defined( CATCH_CONFIG_WINDOWS_SEH ) namespace Catch { struct SignalDefs { DWORD id; const char* name; }; @@ -7176,7 +7270,6 @@ namespace Catch { void FatalConditionHandler::reset() { if (isSet) { - // Unregister handler and restore the old guarantee RemoveVectoredExceptionHandler(exceptionHandlerHandle); SetThreadStackGuarantee(&guaranteeSize); exceptionHandlerHandle = nullptr; @@ -7194,19 +7287,7 @@ PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; } // namespace Catch -# endif // CATCH_CONFIG_WINDOWS_SEH - -#else // Not Windows - assumed to be POSIX compatible ////////////////////////// - -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) - -namespace Catch { - void FatalConditionHandler::reset() {} -} - -# else // CATCH_CONFIG_POSIX_SIGNALS is defined - -#include +#elif defined( CATCH_CONFIG_POSIX_SIGNALS ) namespace Catch { @@ -7275,9 +7356,13 @@ namespace Catch { } // namespace Catch -# endif // CATCH_CONFIG_POSIX_SIGNALS +#else + +namespace Catch { + void FatalConditionHandler::reset() {} +} -#endif // not Windows +#endif // signals/SEH handling #if defined(__GNUC__) # pragma GCC diagnostic pop @@ -7559,11 +7644,10 @@ namespace Catch { std::size_t listTests( Config const& config ) { TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) + if( config.hasTestFilters() ) Catch::cout() << "Matching test cases:\n"; else { Catch::cout() << "All available test cases:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); } auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); @@ -7585,7 +7669,7 @@ namespace Catch { Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; } - if( !config.testSpec().hasFilters() ) + if( !config.hasTestFilters() ) Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; else Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; @@ -7594,8 +7678,6 @@ namespace Catch { std::size_t listTestsNamesOnly( Config const& config ) { TestSpec testSpec = config.testSpec(); - if( !config.testSpec().hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); std::size_t matchedTests = 0; std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); for( auto const& testCaseInfo : matchedTestCases ) { @@ -7625,11 +7707,10 @@ namespace Catch { std::size_t listTags( Config const& config ) { TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) + if( config.hasTestFilters() ) Catch::cout() << "Tags for matching test cases:\n"; else { Catch::cout() << "All available tags:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); } std::map tagCounts; @@ -7950,6 +8031,13 @@ namespace Matchers { // end catch_matchers_string.cpp // start catch_message.cpp +// start catch_uncaught_exceptions.h + +namespace Catch { + bool uncaught_exceptions(); +} // end namespace Catch + +// end catch_uncaught_exceptions.h namespace Catch { MessageInfo::MessageInfo( std::string const& _macroName, @@ -7988,19 +8076,11 @@ namespace Catch { getResultCapture().pushScopedMessage( m_info ); } -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17 -#endif ScopedMessage::~ScopedMessage() { - if ( !std::uncaught_exception() ){ + if ( !uncaught_exceptions() ){ getResultCapture().popScopedMessage(m_info); } } -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - } // end namespace Catch // end catch_message.cpp // start catch_random_number_generator.cpp @@ -8106,7 +8186,7 @@ namespace Catch { void invoke() const override; }; - std::string extractClassName( std::string const& classOrQualifiedMethodName ); + std::string extractClassName( StringRef const& classOrQualifiedMethodName ); /////////////////////////////////////////////////////////////////////////// @@ -8377,7 +8457,7 @@ namespace Catch { m_context(getCurrentMutableContext()), m_config(_config), m_reporter(std::move(reporter)), - m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal }, + m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, m_includeSuccessfulResults( m_config->includeSuccessfulResults() ) { m_context.setRunner(this); @@ -8404,7 +8484,7 @@ namespace Catch { std::string redirectedCout; std::string redirectedCerr; - TestCaseInfo testInfo = testCase.getTestCaseInfo(); + auto const& testInfo = testCase.getTestCaseInfo(); m_reporter->testCaseStarting(testInfo); @@ -8611,7 +8691,7 @@ namespace Catch { Counts prevAssertions = m_totals.assertions; double duration = 0; m_shouldReportUnexpected = true; - m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal }; + m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; seedRng(*m_config); @@ -8640,12 +8720,13 @@ namespace Catch { handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); } } + Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + m_testCaseTracker->close(); handleUnfinishedSections(); m_messages.clear(); - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions(assertions); SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); m_reporter->sectionEnded(testCaseSectionStats); } @@ -8792,22 +8873,15 @@ namespace Catch { m_timer.start(); } -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17 -#endif Section::~Section() { if( m_sectionIncluded ) { SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); - if( std::uncaught_exception() ) + if( uncaught_exceptions() ) getResultCapture().sectionEndedEarly( endInfo ); else getResultCapture().sectionEnded( endInfo ); } } -#if defined(_MSC_VER) -#pragma warning(pop) -#endif // This indicates whether the section should be executed or not Section::operator bool() const { @@ -8852,12 +8926,12 @@ namespace Catch { void showHelp() const; void libIdentify(); - int applyCommandLine( int argc, char* argv[] ); + int applyCommandLine( int argc, char const * const * argv ); void useConfigData( ConfigData const& configData ); int run( int argc, char* argv[] ); - #if defined(WIN32) && defined(UNICODE) + #if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) int run( int argc, wchar_t* const argv[] ); #endif int run(); @@ -8958,8 +9032,6 @@ namespace Catch { context.testGroupStarting(config->name(), 1, 1); TestSpec testSpec = config->testSpec(); - if (!testSpec.hasFilters()) - testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests auto const& allTestCases = getAllTestCasesSorted(*config); for (auto const& testCase : allTestCases) { @@ -8969,6 +9041,20 @@ namespace Catch { context.reporter().skipTest(testCase); } + if (config->warnAboutNoTests() && totals.testCases.total() == 0) { + ReusableStringStream testConfig; + + bool first = true; + for (const auto& input : config->getTestsOrTags()) { + if (!first) { testConfig << ' '; } + first = false; + testConfig << input; + } + + context.reporter().noMatchingTestCases(testConfig.str()); + totals.error = -1; + } + context.testGroupEnded(config->name(), totals, 1, 1); return totals; } @@ -9008,7 +9094,7 @@ namespace Catch { if ( !exceptions.empty() ) { m_startupExceptions = true; Colour colourGuard( Colour::Red ); - Catch::cerr() << "Errors occured during startup!" << '\n'; + Catch::cerr() << "Errors occurred during startup!" << '\n'; // iterate over all exceptions and notify user for ( const auto& ex_ptr : exceptions ) { try { @@ -9040,7 +9126,7 @@ namespace Catch { << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; } - int Session::applyCommandLine( int argc, char* argv[] ) { + int Session::applyCommandLine( int argc, char const * const * argv ) { if( m_startupExceptions ) return 1; @@ -9077,7 +9163,7 @@ namespace Catch { return returnCode; } -#if defined(WIN32) && defined(UNICODE) +#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE) int Session::run( int argc, wchar_t* const argv[] ) { char **utf8Argv = new char *[ argc ]; @@ -9148,7 +9234,11 @@ namespace Catch { if( Option listed = list( config() ) ) return static_cast( *listed ); - return (std::min)( MaxExitCode, static_cast( runTests( m_config ).assertions.failed ) ); + auto totals = runTests( m_config ); + // Note that on unices only the lower 8 bits are usually used, clamping + // the return value to 255 prevents false negative when some multiple + // of 256 tests has failed + return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast(totals.assertions.failed))); } catch( std::exception& ex ) { Catch::cerr() << ex.what() << std::endl; @@ -9455,6 +9545,13 @@ namespace Catch { #include #include +#include + +namespace { + const uint32_t byte_2_lead = 0xC0; + const uint32_t byte_3_lead = 0xE0; + const uint32_t byte_4_lead = 0xF0; +} namespace Catch { StringRef::StringRef( char const* rawChars ) noexcept @@ -9476,7 +9573,7 @@ namespace Catch { const_cast( this )->takeOwnership(); return m_start; } - auto StringRef::data() const noexcept -> char const* { + auto StringRef::currentData() const noexcept -> char const* { return m_start; } @@ -9519,13 +9616,12 @@ namespace Catch { // Make adjustments for uft encodings for( size_type i=0; i < m_size; ++i ) { char c = m_start[i]; - if( ( c & 0b11000000 ) == 0b11000000 ) { - if( ( c & 0b11100000 ) == 0b11000000 ) + if( ( c & byte_2_lead ) == byte_2_lead ) { + noChars--; + if (( c & byte_3_lead ) == byte_3_lead ) + noChars--; + if( ( c & byte_4_lead ) == byte_4_lead ) noChars--; - else if( ( c & 0b11110000 ) == 0b11100000 ) - noChars-=2; - else if( ( c & 0b11111000 ) == 0b11110000 ) - noChars-=3; } } return noChars; @@ -9546,7 +9642,12 @@ namespace Catch { } auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { - return os << str.c_str(); + return os.write(str.currentData(), str.size()); + } + + auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { + lhs.append(rhs.currentData(), rhs.size()); + return lhs; } } // namespace Catch @@ -9661,8 +9762,7 @@ namespace Catch { TestCase makeTestCase( ITestInvoker* _testCase, std::string const& _className, - std::string const& _name, - std::string const& _descOrTags, + NameAndTags const& nameAndTags, SourceLineInfo const& _lineInfo ) { bool isHidden = false; @@ -9671,6 +9771,7 @@ namespace Catch { std::vector tags; std::string desc, tag; bool inTag = false; + std::string _descOrTags = nameAndTags.tags; for (char c : _descOrTags) { if( !inTag ) { if( c == '[' ) @@ -9698,8 +9799,8 @@ namespace Catch { tags.push_back( "." ); } - TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); - return TestCase( _testCase, info ); + TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo ); + return TestCase( _testCase, std::move(info) ); } void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { @@ -9759,7 +9860,7 @@ namespace Catch { return ret; } - TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} + TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {} TestCase TestCase::withName( std::string const& _newName ) const { TestCase other( *this ); @@ -9870,7 +9971,7 @@ namespace Catch { m_testAsFunction(); } - std::string extractClassName( std::string const& classOrQualifiedMethodName ) { + std::string extractClassName( StringRef const& classOrQualifiedMethodName ) { std::string className = classOrQualifiedMethodName; if( startsWith( className, '&' ) ) { @@ -10167,17 +10268,16 @@ namespace Catch { return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); } - NameAndTags::NameAndTags( StringRef name_ , StringRef tags_ ) noexcept : name( name_ ), tags( tags_ ) {} + NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {} - AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept { + AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { try { getMutableRegistryHub() .registerTest( makeTestCase( invoker, extractClassName( classOrMethod ), - nameAndTags.name, - nameAndTags.tags, + nameAndTags, lineInfo)); } catch (...) { // Do not throw when constructing global objects, instead register the exception to be processed later @@ -10481,6 +10581,7 @@ std::string StringMaker::convert(const std::string& str) { return s; } +#ifdef CATCH_CONFIG_WCHAR std::string StringMaker::convert(const std::wstring& wstr) { std::string s; s.reserve(wstr.size()); @@ -10489,6 +10590,7 @@ std::string StringMaker::convert(const std::wstring& wstr) { } return ::Catch::Detail::stringify(s); } +#endif std::string StringMaker::convert(char const* str) { if (str) { @@ -10504,6 +10606,7 @@ std::string StringMaker::convert(char* str) { return{ "{null string}" }; } } +#ifdef CATCH_CONFIG_WCHAR std::string StringMaker::convert(wchar_t const * str) { if (str) { return ::Catch::Detail::stringify(std::wstring{ str }); @@ -10518,6 +10621,7 @@ std::string StringMaker::convert(wchar_t * str) { return{ "{null string}" }; } } +#endif std::string StringMaker::convert(int value) { return ::Catch::Detail::stringify(static_cast(value)); @@ -10657,6 +10761,20 @@ namespace Catch { } // end catch_totals.cpp +// start catch_uncaught_exceptions.cpp + +#include + +namespace Catch { + bool uncaught_exceptions() { +#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + return std::uncaught_exceptions() > 0; +#else + return std::uncaught_exception(); +#endif + } +} // end namespace Catch +// end catch_uncaught_exceptions.cpp // start catch_version.cpp #include @@ -10689,7 +10807,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 2, 1, 0, "", 0 ); + static Version version( 2, 2, 1, "", 0 ); return version; } @@ -11918,7 +12036,7 @@ namespace Catch { m_reporterPrefs.shouldRedirectStdOut = true; } - JunitReporter::~JunitReporter() {}; + JunitReporter::~JunitReporter() {} std::string JunitReporter::getDescription() { return "Reports test results in an XML format that looks like Ant's junitreport target"; @@ -12423,7 +12541,7 @@ namespace Catch { #ifndef __OBJC__ -#if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) +#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) // Standard C/C++ Win32 Unicode wmain entry point extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { #else diff --git a/src/connectors/file_connector/test/file_connector_module_test.cc b/src/connectors/file_connector/test/file_connector_module_test.cc index 4060659d6..54ac2f740 100644 --- a/src/connectors/file_connector/test/file_connector_module_test.cc +++ b/src/connectors/file_connector/test/file_connector_module_test.cc @@ -49,12 +49,12 @@ char* snort_strdup(const char* s) TEST_GROUP(file_connector_module) { - void setup() + void setup() override { MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } diff --git a/src/connectors/file_connector/test/file_connector_test.cc b/src/connectors/file_connector/test/file_connector_test.cc index f75395233..41cefaa61 100644 --- a/src/connectors/file_connector/test/file_connector_test.cc +++ b/src/connectors/file_connector/test/file_connector_test.cc @@ -73,7 +73,7 @@ FileConnectorConfig::FileConnectorConfigSet* FileConnectorModule::get_and_clear_ return config_set; } -FileConnectorModule::~FileConnectorModule() { } +FileConnectorModule::~FileConnectorModule() = default; ProfileStats* FileConnectorModule::get_profile() const { return nullptr; } @@ -86,7 +86,7 @@ PegCount* FileConnectorModule::get_counts() const { return nullptr; } TEST_GROUP(file_connector) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -109,7 +109,7 @@ TEST_GROUP(file_connector) connector_rx_binary_config.text_format = false; } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -136,7 +136,7 @@ TEST(file_connector, mod_instance_ctor_dtor) TEST_GROUP(file_connector_tinit_tterm) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -172,7 +172,7 @@ TEST_GROUP(file_connector_tinit_tterm) CHECK(connector_rb != nullptr); } - void teardown() + void teardown() override { fc_api->tterm(connector_tt); fc_api->tterm(connector_rt); @@ -198,7 +198,7 @@ TEST(file_connector_tinit_tterm, alloc_discard) TEST_GROUP(file_connector_text) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -214,7 +214,7 @@ TEST_GROUP(file_connector_text) CHECK(file_connector != nullptr); } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -264,7 +264,7 @@ TEST(file_connector_text, alloc_transmit_rename_receive_discard) TEST_GROUP(file_connector_binary) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -280,7 +280,7 @@ TEST_GROUP(file_connector_binary) CHECK(file_connector != nullptr); } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -330,11 +330,11 @@ TEST(file_connector_binary, alloc_transmit_rename_receive_discard) TEST_GROUP(file_connector_msg_handle) { - void setup() + void setup() override { } - void teardown() + void teardown() override { } }; diff --git a/src/connectors/tcp_connector/test/tcp_connector_module_test.cc b/src/connectors/tcp_connector/test/tcp_connector_module_test.cc index db639332b..818aa1efb 100644 --- a/src/connectors/tcp_connector/test/tcp_connector_module_test.cc +++ b/src/connectors/tcp_connector/test/tcp_connector_module_test.cc @@ -49,12 +49,12 @@ char* snort_strdup(const char* s) TEST_GROUP(tcp_connector_module) { - void setup() + void setup() override { MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } diff --git a/src/connectors/tcp_connector/test/tcp_connector_test.cc b/src/connectors/tcp_connector/test/tcp_connector_test.cc index 3db2e47bc..932e67cc0 100644 --- a/src/connectors/tcp_connector/test/tcp_connector_test.cc +++ b/src/connectors/tcp_connector/test/tcp_connector_test.cc @@ -179,7 +179,7 @@ TcpConnectorConfig::TcpConnectorConfigSet* TcpConnectorModule::get_and_clear_con return config_set; } -TcpConnectorModule::~TcpConnectorModule() { } +TcpConnectorModule::~TcpConnectorModule() = default; ProfileStats* TcpConnectorModule::get_profile() const { return nullptr; } @@ -192,7 +192,7 @@ PegCount* TcpConnectorModule::get_counts() const { return nullptr; } TEST_GROUP(tcp_connector) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -205,7 +205,7 @@ TEST_GROUP(tcp_connector) connector_config.async_receive = false; } - void teardown() + void teardown() override { //MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -232,7 +232,7 @@ TEST(tcp_connector, mod_instance_ctor_dtor) TEST_GROUP(tcp_connector_call_error) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -251,7 +251,7 @@ TEST_GROUP(tcp_connector_call_error) CHECK(connector_common != nullptr); } - void teardown() + void teardown() override { connector = tcpc_api->tinit(&connector_config); CHECK(connector == nullptr); @@ -263,13 +263,13 @@ TEST_GROUP(tcp_connector_call_error) TEST_GROUP(tcp_connector_call_other) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); } - void teardown() + void teardown() override { //MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -277,7 +277,7 @@ TEST_GROUP(tcp_connector_call_other) TEST_GROUP(tcp_connector_answer_error) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -295,7 +295,7 @@ TEST_GROUP(tcp_connector_answer_error) CHECK(connector_common != nullptr); } - void teardown() + void teardown() override { connector = tcpc_api->tinit(&connector_config); CHECK(connector == nullptr); @@ -365,7 +365,7 @@ TEST(tcp_connector_call_other, bad_setup) TEST_GROUP(tcp_connector_tinit_tterm_thread_call) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -388,7 +388,7 @@ TEST_GROUP(tcp_connector_tinit_tterm_thread_call) CHECK(connector->get_connector_direction() == Connector::CONN_DUPLEX); } - void teardown() + void teardown() override { tcpc_api->tterm(connector); tcpc_api->dtor(connector_common); @@ -399,7 +399,7 @@ TEST_GROUP(tcp_connector_tinit_tterm_thread_call) TEST_GROUP(tcp_connector_tinit_tterm_call) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -422,7 +422,7 @@ TEST_GROUP(tcp_connector_tinit_tterm_call) CHECK(connector->get_connector_direction() == Connector::CONN_DUPLEX); } - void teardown() + void teardown() override { tcpc_api->tterm(connector); tcpc_api->dtor(connector_common); @@ -433,7 +433,7 @@ TEST_GROUP(tcp_connector_tinit_tterm_call) TEST_GROUP(tcp_connector_no_tinit_tterm_call) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -453,7 +453,7 @@ TEST_GROUP(tcp_connector_no_tinit_tterm_call) CHECK(connector_common != nullptr); } - void teardown() + void teardown() override { tcpc_api->tterm(connector); tcpc_api->dtor(connector_common); @@ -510,7 +510,7 @@ TEST(tcp_connector_no_tinit_tterm_call, poll_error) TEST_GROUP(tcp_connector_tinit_tterm_answer) { - void setup() + void setup() override { // FIXIT-L workaround for CppUTest mem leak detector issue //MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -532,7 +532,7 @@ TEST_GROUP(tcp_connector_tinit_tterm_answer) CHECK(connector != nullptr); } - void teardown() + void teardown() override { tcpc_api->tterm(connector); tcpc_api->dtor(connector_common); @@ -783,11 +783,11 @@ TEST(tcp_connector_no_tinit_tterm_call, receive_recv_body_closed) TEST_GROUP(tcp_connector_msg_handle) { - void setup() + void setup() override { } - void teardown() + void teardown() override { } }; diff --git a/src/flow/ha.cc b/src/flow/ha.cc index 59d367707..e21b507c6 100644 --- a/src/flow/ha.cc +++ b/src/flow/ha.cc @@ -561,12 +561,8 @@ bool HighAvailabilityManager::instantiate(PortBitSet* mod_ports, bool mod_use_da DebugMessage(DEBUG_HA,"HighAvailabilityManager::instantiate()\n"); ports = mod_ports; FlowHAState::config_timers(*min_session_lifetime, *min_sync_interval); -#ifdef HAVE_DAQ_EXT_MODFLOW use_daq_channel = mod_use_daq_channel; -#else - if ( mod_use_daq_channel ) - return false; -#endif + return true; } diff --git a/src/flow/test/ha_module_test.cc b/src/flow/test/ha_module_test.cc index a0d071b27..7f9f7c217 100644 --- a/src/flow/test/ha_module_test.cc +++ b/src/flow/test/ha_module_test.cc @@ -78,11 +78,11 @@ bool HighAvailabilityManager::instantiate(PortBitSet* mod_ports, bool mod_use_da TEST_GROUP(high_availability_module_test) { - void setup() + void setup() override { } - void teardown() + void teardown() override { } }; diff --git a/src/flow/test/ha_test.cc b/src/flow/test/ha_test.cc index bdbf846fa..94706d1fd 100644 --- a/src/flow/test/ha_test.cc +++ b/src/flow/test/ha_test.cc @@ -95,20 +95,20 @@ class StreamHAClient : public FlowHAClient { public: StreamHAClient() : FlowHAClient(10, true) { } - ~StreamHAClient() { } - bool consume(Flow*&, FlowKey*, HAMessage*) + ~StreamHAClient() override = default; + bool consume(Flow*&, FlowKey*, HAMessage*) override { s_stream_consume_called = true; return true; } - bool produce(Flow*, HAMessage* msg) + bool produce(Flow*, HAMessage* msg) override { for ( uint8_t i=0; i<10; i++ ) *(msg->cursor)++ = i; return true; } uint8_t get_message_size() { return 10; } - bool is_update_required(Flow*) { return s_stream_update_required; } + bool is_update_required(Flow*) override { return s_stream_update_required; } bool fit(HAMessage*,uint8_t) { return true; } bool place(HAMessage*,uint8_t*,uint8_t) { return true; } @@ -119,20 +119,20 @@ class OtherHAClient : public FlowHAClient { public: OtherHAClient() : FlowHAClient(5, false) { } - ~OtherHAClient() { } + ~OtherHAClient() override = default; bool consume(Flow*&, HAMessage*) { s_other_consume_called = true; return true; } - bool produce(Flow*, HAMessage* msg) + bool produce(Flow*, HAMessage* msg) override { for ( uint8_t i=0; i<5; i++ ) *(msg->cursor)++ = i; return true; } uint8_t get_message_size() { return 5; } - bool is_update_required(Flow*) { return s_other_update_required; } + bool is_update_required(Flow*) override { return s_other_update_required; } bool fit(HAMessage*,uint8_t) { return true; } bool place(HAMessage*,uint8_t*,uint8_t) { return true; } @@ -167,9 +167,9 @@ Flow::Flow() { ha_state = new FlowHAState; key = new FlowKey; } SideChannel* SideChannelManager::get_side_channel(SCPort) { return &s_side_channel; } -SideChannel::~SideChannel() { } +SideChannel::~SideChannel() = default; -SideChannel::SideChannel() { } +SideChannel::SideChannel() = default; Connector::Direction SideChannel::get_direction() { return Connector::CONN_DUPLEX; } @@ -220,12 +220,12 @@ SCMessage* SideChannel::alloc_transmit_message(uint32_t len) TEST_GROUP(high_availability_manager_test) { - void setup() + void setup() override { MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); } - void teardown() + void teardown() override { MemoryLeakWarningPlugin::turnOnNewDeleteOverloads(); } @@ -258,8 +258,8 @@ TEST(high_availability_manager_test, inst_init_term) TEST_GROUP(flow_ha_state_test) { - void setup() { } - void teardown() { } + void setup() override { } + void teardown() override { } }; TEST(flow_ha_state_test, timing_test) @@ -321,7 +321,7 @@ TEST(flow_ha_state_test, state_test) TEST_GROUP(high_availability_test) { - void setup() + void setup() override { MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); HighAvailabilityManager::pre_config_init(); @@ -335,7 +335,7 @@ TEST_GROUP(high_availability_test) s_other_ha_client = new OtherHAClient; } - void teardown() + void teardown() override { delete s_other_ha_client; delete s_ha_client; diff --git a/src/host_tracker/test/host_cache_test.cc b/src/host_tracker/test/host_cache_test.cc index 31e33f0c7..18ab34239 100644 --- a/src/host_tracker/test/host_cache_test.cc +++ b/src/host_tracker/test/host_cache_test.cc @@ -37,7 +37,7 @@ THREAD_LOCAL SnortConfig* snort_conf = &s_conf; SnortConfig::SnortConfig(const SnortConfig* const) { } -SnortConfig::~SnortConfig() { } +SnortConfig::~SnortConfig() = default; SnortConfig* SnortConfig::get_conf() { return snort_conf; } diff --git a/src/ips_options/test/ips_regex_test.cc b/src/ips_options/test/ips_regex_test.cc index c25ea8601..78dc7e142 100644 --- a/src/ips_options/test/ips_regex_test.cc +++ b/src/ips_options/test/ips_regex_test.cc @@ -64,13 +64,13 @@ SnortConfig::SnortConfig(const SnortConfig* const) num_slots = 1; } -SnortConfig::~SnortConfig() { } +SnortConfig::~SnortConfig() = default; SnortConfig* SnortConfig::get_conf() { return snort_conf; } Packet::Packet(bool) { } -Packet::~Packet() { } +Packet::~Packet() = default; } Cursor::Cursor(Packet* p) @@ -85,7 +85,7 @@ unsigned get_instance_id() { return 0; } MemoryContext::MemoryContext(MemoryTracker&) { } -MemoryContext::~MemoryContext() { } +MemoryContext::~MemoryContext() = default; void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*, FILE*) { } @@ -139,7 +139,7 @@ static IpsOption* get_option(const char* pat, bool relative = false) TEST_GROUP(ips_regex_base) { - void setup() + void setup() override { CHECK(ips_regex); } }; @@ -173,14 +173,14 @@ TEST_GROUP(ips_regex_module) bool end = true; unsigned expect = 0; - void setup() + void setup() override { s_parse_errors = 0; mod = ips_regex->mod_ctor(); CHECK(mod); CHECK(mod->begin(ips_regex->name, 0, nullptr)); } - void teardown() + void teardown() override { CHECK(mod->end(ips_regex->name, 0, nullptr) == end); LONGS_EQUAL(expect, s_parse_errors); @@ -264,14 +264,14 @@ TEST_GROUP(ips_regex_option) { IpsOption* opt = nullptr; - void setup() + void setup() override { // FIXIT-L cpputest hangs or crashes in the leak detector MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); opt = get_option(" foo "); regex_setup(snort_conf); } - void teardown() + void teardown() override { IpsApi* api = (IpsApi*)ips_regex; api->dtor(opt); @@ -338,14 +338,14 @@ TEST_GROUP(ips_regex_option_relative) { IpsOption* opt = nullptr; - void setup() + void setup() override { // FIXIT-L cpputest hangs or crashes in the leak detector MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); opt = get_option("\\bfoo", true); regex_setup(snort_conf); } - void teardown() + void teardown() override { IpsApi* api = (IpsApi*)ips_regex; api->dtor(opt); diff --git a/src/log/packet_tracer.cc b/src/log/packet_tracer.cc index 06e7bb9be..333de1d3a 100644 --- a/src/log/packet_tracer.cc +++ b/src/log/packet_tracer.cc @@ -317,7 +317,7 @@ public: static uint8_t get_dump_reason() { return ((TestPacketTracer*)s_pkt_trace)->dump_reason; } - virtual void dump_to_daq(const DAQ_PktHdr_t*) override + void dump_to_daq(const DAQ_PktHdr_t*) override { dump_reason = reason; } static std::vector get_mutes() diff --git a/src/network_inspectors/appid/appid_dns_session.h b/src/network_inspectors/appid/appid_dns_session.h index 85b0c4e68..d13682fb5 100644 --- a/src/network_inspectors/appid/appid_dns_session.h +++ b/src/network_inspectors/appid/appid_dns_session.h @@ -30,7 +30,7 @@ class AppIdDnsSession { public: - virtual ~AppIdDnsSession() {} + virtual ~AppIdDnsSession() = default; void reset() { diff --git a/src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h b/src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h index 9293c7827..608bfeca1 100644 --- a/src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h +++ b/src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h @@ -33,10 +33,10 @@ namespace snort { // Stubs for packet Packet::Packet(bool) { } -Packet::~Packet() { } +Packet::~Packet() = default; -Inspector::Inspector() {} -Inspector::~Inspector() {} +Inspector::Inspector() = default; +Inspector::~Inspector() = default; bool Inspector::likes(Packet*) { return true; } bool Inspector::get_buf(const char*, Packet*, InspectionBuffer&) { return true; } class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; } @@ -46,19 +46,19 @@ class AppIdInspector : public snort::Inspector { public: AppIdInspector(AppIdModule& ) {} - ~AppIdInspector() {} - void eval(Packet*) {} - bool configure(snort::SnortConfig*) { return true; } - void show(snort::SnortConfig*) {} - void tinit() {} - void tterm() {} + ~AppIdInspector() override = default; + void eval(Packet*) override {} + bool configure(snort::SnortConfig*) override { return true; } + void show(snort::SnortConfig*) override {} + void tinit() override {} + void tterm() override {} }; // Stubs for modules, config -AppIdModuleConfig::~AppIdModuleConfig() {} +AppIdModuleConfig::~AppIdModuleConfig() = default; AppIdModule::AppIdModule() : Module("a", "b") {} -AppIdModule::~AppIdModule() {} +AppIdModule::~AppIdModule() = default; bool AppIdModule::begin(const char*, int, snort::SnortConfig*) { return false; @@ -100,10 +100,10 @@ snort::FlowData::~FlowData() = default; unsigned AppIdSession::inspector_id = 0; AppIdSession::AppIdSession(IpProtocol, const SfIp*, uint16_t, AppIdInspector& inspector) : snort::FlowData(inspector_id, (snort::Inspector*)&inspector), inspector(inspector) {} -AppIdSession::~AppIdSession() {} +AppIdSession::~AppIdSession() = default; AppIdHttpSession::AppIdHttpSession(AppIdSession& session) : asd(session) {} -AppIdHttpSession::~AppIdHttpSession() {} +AppIdHttpSession::~AppIdHttpSession() = default; // Stubs for AppIdPegCounts void AppIdPegCounts::inc_disco_peg(enum DiscoveryPegs) {} @@ -120,7 +120,7 @@ namespace snort { // Stubs for search_tool.cc SearchTool::SearchTool(const char*, bool) {} -SearchTool::~SearchTool() {} +SearchTool::~SearchTool() = default; void SearchTool::add(const char*, unsigned, int, bool) {} void SearchTool::add(const char*, unsigned, void*, bool) {} void SearchTool::add(const uint8_t*, unsigned, int, bool) {} diff --git a/src/network_inspectors/appid/test/appid_debug_test.cc b/src/network_inspectors/appid/test/appid_debug_test.cc index f7df9658a..a30803ce4 100644 --- a/src/network_inspectors/appid/test/appid_debug_test.cc +++ b/src/network_inspectors/appid/test/appid_debug_test.cc @@ -40,15 +40,15 @@ class AppIdInspector { public: - AppIdInspector() { } + AppIdInspector() = default; }; FlowData::FlowData(unsigned, Inspector*) { } -FlowData::~FlowData() { } +FlowData::~FlowData() = default; AppIdSession::AppIdSession(IpProtocol, const SfIp*, uint16_t, AppIdInspector& inspector) : FlowData(0), inspector(inspector) { } -AppIdSession::~AppIdSession() { } +AppIdSession::~AppIdSession() = default; // Utility functions diff --git a/src/network_inspectors/appid/test/appid_expected_flags_test.cc b/src/network_inspectors/appid/test/appid_expected_flags_test.cc index e57065ab3..2566107be 100644 --- a/src/network_inspectors/appid/test/appid_expected_flags_test.cc +++ b/src/network_inspectors/appid/test/appid_expected_flags_test.cc @@ -31,7 +31,7 @@ class MockServiceDetector : public ServiceDetector { public: - int validate(AppIdDiscoveryArgs&) { return 0; } + int validate(AppIdDiscoveryArgs&) override { return 0; } }; AppIdSession* parent = nullptr; @@ -51,14 +51,14 @@ static inline void cleanup() TEST_GROUP(appid_expected_flags) { - void setup() + void setup() override { MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); parent = new AppIdSession(IpProtocol::TCP, nullptr, 1492, appid_inspector); expected = new AppIdSession(IpProtocol::TCP, nullptr, 1492, appid_inspector); } - void teardown() + void teardown() override { delete parent; delete expected; diff --git a/src/network_inspectors/appid/test/appid_mock_inspector.h b/src/network_inspectors/appid/test/appid_mock_inspector.h index 7fe730184..6c765545d 100644 --- a/src/network_inspectors/appid/test/appid_mock_inspector.h +++ b/src/network_inspectors/appid/test/appid_mock_inspector.h @@ -28,7 +28,7 @@ Inspector::Inspector() set_api(nullptr); } -Inspector::~Inspector() { } +Inspector::~Inspector() = default; bool Inspector::likes(Packet*) { return true; } bool Inspector::get_buf(const char*, Packet*, InspectionBuffer&) { return true; } class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; } @@ -37,8 +37,8 @@ class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; } class AppIdModule { public: - AppIdModule() {} - ~AppIdModule() {} + AppIdModule() = default; + ~AppIdModule() = default; }; @@ -46,12 +46,12 @@ class AppIdInspector : public snort::Inspector { public: AppIdInspector(AppIdModule& ) { } - ~AppIdInspector() { } - void eval(snort::Packet*) { } - bool configure(snort::SnortConfig*) { return true; } - void show(snort::SnortConfig*) { } - void tinit() { } - void tterm() { } + ~AppIdInspector() override = default; + void eval(snort::Packet*) override { } + bool configure(snort::SnortConfig*) override { return true; } + void show(snort::SnortConfig*) override { } + void tinit() override { } + void tterm() override { } }; AppIdModule appid_mod; diff --git a/src/network_inspectors/perf_monitor/perf_monitor.cc b/src/network_inspectors/perf_monitor/perf_monitor.cc index ce7e80c19..3bbdc5025 100644 --- a/src/network_inspectors/perf_monitor/perf_monitor.cc +++ b/src/network_inspectors/perf_monitor/perf_monitor.cc @@ -88,7 +88,7 @@ public: PerfIdleHandler(PerfMonitor& p) : perf_monitor(p) { DataBus::subscribe_default(THREAD_IDLE_EVENT, this); } - virtual void handle(DataEvent&, Flow*) override + void handle(DataEvent&, Flow*) override { perf_monitor.eval(nullptr); } private: @@ -101,7 +101,7 @@ public: PerfRotateHandler(PerfMonitor& p) : perf_monitor(p) { DataBus::subscribe_default(THREAD_ROTATE_EVENT, this); } - virtual void handle(DataEvent&, Flow*) override + void handle(DataEvent&, Flow*) override { perf_monitor.rotate(); } private: @@ -114,7 +114,7 @@ public: FlowIPDataHandler(PerfMonitor& p) : perf_monitor(p) { DataBus::subscribe_default(FLOW_STATE_EVENT, this); } - virtual void handle(DataEvent&, Flow* flow) override + void handle(DataEvent&, Flow* flow) override { FlowState state = SFS_STATE_MAX; diff --git a/src/search_engines/test/hyperscan_test.cc b/src/search_engines/test/hyperscan_test.cc index e1507d9c8..486996a17 100644 --- a/src/search_engines/test/hyperscan_test.cc +++ b/src/search_engines/test/hyperscan_test.cc @@ -69,7 +69,7 @@ SnortConfig::SnortConfig(const SnortConfig* const) num_slots = 1; } -SnortConfig::~SnortConfig() { } +SnortConfig::~SnortConfig() = default; SnortConfig* SnortConfig::get_conf() { return snort_conf; } @@ -127,7 +127,7 @@ static MpseAgent s_agent = TEST_GROUP(mpse_hs_base) { - void setup() + void setup() override { CHECK(se_hyperscan); } @@ -170,7 +170,7 @@ TEST_GROUP(mpse_hs_match) Mpse* hs = nullptr; const MpseApi* mpse_api = (MpseApi*)se_hyperscan; - void setup() + void setup() override { // FIXIT-L cpputest hangs or crashes in the leak detector MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -180,7 +180,7 @@ TEST_GROUP(mpse_hs_match) hits = 0; parse_errors = 0; } - void teardown() + void teardown() override { mpse_api->dtor(hs); hyperscan_cleanup(snort_conf); @@ -311,7 +311,7 @@ TEST_GROUP(mpse_hs_multi) Mpse* hs2 = nullptr; const MpseApi* mpse_api = (MpseApi*)se_hyperscan; - void setup() + void setup() override { // FIXIT-L cpputest hangs or crashes in the leak detector MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -326,7 +326,7 @@ TEST_GROUP(mpse_hs_multi) hits = 0; parse_errors = 0; } - void teardown() + void teardown() override { mpse_api->dtor(hs1); mpse_api->dtor(hs2); diff --git a/src/search_engines/test/search_tool_test.cc b/src/search_engines/test/search_tool_test.cc index 4e8ca96c0..9adca659d 100644 --- a/src/search_engines/test/search_tool_test.cc +++ b/src/search_engines/test/search_tool_test.cc @@ -60,7 +60,7 @@ SnortConfig::SnortConfig(const SnortConfig* const) fast_pattern_config = nullptr; } -SnortConfig::~SnortConfig() { } +SnortConfig::~SnortConfig() = default; SnortConfig* SnortConfig::get_conf() { return snort_conf; } @@ -161,7 +161,7 @@ static int Test_SearchStrFound( TEST_GROUP(search_tool_tests) { - void setup() + void setup() override { CHECK(se_ac_bnfa); } }; diff --git a/src/service_inspectors/http2_inspect/test/http2_flow_data_test.h b/src/service_inspectors/http2_inspect/test/http2_flow_data_test.h index b1ebcd47e..d2bb731b4 100644 --- a/src/service_inspectors/http2_inspect/test/http2_flow_data_test.h +++ b/src/service_inspectors/http2_inspect/test/http2_flow_data_test.h @@ -27,7 +27,7 @@ // Stubs whose sole purpose is to make the test code link snort::FlowData::FlowData(unsigned u, Inspector* ph) : next(nullptr), prev(nullptr), handler(ph), id(u) {} -snort::FlowData::~FlowData() {} +snort::FlowData::~FlowData() = default; unsigned snort::FlowData::flow_data_id = 0; void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { } void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*, FILE*) { } diff --git a/src/service_inspectors/http_inspect/test/http_transaction_test.cc b/src/service_inspectors/http_inspect/test/http_transaction_test.cc index c50c8d90a..1a37de231 100644 --- a/src/service_inspectors/http_inspect/test/http_transaction_test.cc +++ b/src/service_inspectors/http_inspect/test/http_transaction_test.cc @@ -38,7 +38,7 @@ using namespace HttpEnums; // Stubs whose sole purpose is to make the test code link unsigned FlowData::flow_data_id = 0; FlowData::FlowData(unsigned, Inspector*) {} -FlowData::~FlowData() {} +FlowData::~FlowData() = default; int DetectionEngine::queue_event(unsigned int, unsigned int, Actions::Type) { return 0; } THREAD_LOCAL PegCount HttpModule::peg_counts[1]; fd_status_t File_Decomp_StopFree(fd_session_t*) { return File_Decomp_OK; } @@ -58,7 +58,7 @@ TEST_GROUP(http_transaction_test) SectionType* const section_type = HttpUnitTestSetup::get_section_type(flow_data); SectionType* const type_expected = HttpUnitTestSetup::get_type_expected(flow_data); - void teardown() + void teardown() override { delete flow_data; } diff --git a/src/sfip/sf_ip.cc b/src/sfip/sf_ip.cc index a935b5e5b..2a758bee3 100644 --- a/src/sfip/sf_ip.cc +++ b/src/sfip/sf_ip.cc @@ -420,7 +420,7 @@ const char* snort_inet_ntop(int family, const void* ip_raw, char* buf, int bufsi return buf; } -#if defined(HAVE_INET_NTOP) && !defined(REG_TEST) +#ifndef REG_TEST if (!inet_ntop(family, ip_raw, buf, bufsize)) snprintf(buf, bufsize, "ERROR"); #else diff --git a/src/side_channel/test/side_channel_test.cc b/src/side_channel/test/side_channel_test.cc index 3d6bf8be0..a42915d97 100644 --- a/src/side_channel/test/side_channel_test.cc +++ b/src/side_channel/test/side_channel_test.cc @@ -53,61 +53,61 @@ public: class DuplexConnector : public Connector { - ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) + ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) override { TestConnectorMsgHandle* msg = new TestConnectorMsgHandle(length); *data = (uint8_t*)msg->connector_msg.data; return msg; } - void discard_message(ConnectorMsgHandle* msg) + void discard_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; } - bool transmit_message(ConnectorMsgHandle* msg) + bool transmit_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; return true; } - ConnectorMsgHandle* receive_message(bool) + ConnectorMsgHandle* receive_message(bool) override { return new TestConnectorMsgHandle(30); } - ConnectorMsg* get_connector_msg(ConnectorMsgHandle* handle) + ConnectorMsg* get_connector_msg(ConnectorMsgHandle* handle) override { return &((TestConnectorMsgHandle*)handle)->connector_msg; } - Direction get_connector_direction() + Direction get_connector_direction() override { return CONN_DUPLEX; } }; class ReceiveConnector : public Connector { - ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) + ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) override { TestConnectorMsgHandle* msg = new TestConnectorMsgHandle(length); *data = (uint8_t*)msg->connector_msg.data; return msg; } - void discard_message(ConnectorMsgHandle* msg) + void discard_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; } - bool transmit_message(ConnectorMsgHandle* msg) + bool transmit_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; return true; } - ConnectorMsgHandle* receive_message(bool) + ConnectorMsgHandle* receive_message(bool) override { return new TestConnectorMsgHandle(30); } - ConnectorMsg* get_connector_msg(ConnectorMsgHandle* handle) + ConnectorMsg* get_connector_msg(ConnectorMsgHandle* handle) override { return &((TestConnectorMsgHandle*)handle)->connector_msg; } - Direction get_connector_direction() + Direction get_connector_direction() override { return CONN_RECEIVE; } }; class TransmitConnector : public Connector { - ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) + ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data) override { TestConnectorMsgHandle* msg = new TestConnectorMsgHandle(length); *data = (uint8_t*)msg->connector_msg.data; return msg; } - void discard_message(ConnectorMsgHandle* msg) + void discard_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; } - bool transmit_message(ConnectorMsgHandle* msg) + bool transmit_message(ConnectorMsgHandle* msg) override { delete (TestConnectorMsgHandle*)msg; return true; } - ConnectorMsgHandle* receive_message(bool) + ConnectorMsgHandle* receive_message(bool) override { return nullptr; } - ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) + ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) override { return nullptr; } - Direction get_connector_direction() + Direction get_connector_direction() override { return CONN_TRANSMIT; } }; @@ -149,7 +149,7 @@ void Debug::print(const char*, int, uint64_t, const char*, ...) { } TEST_GROUP(side_channel) { - void setup() + void setup() override { // FIXIT-L workaround for issue with CppUTest memory leak detection MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); @@ -201,7 +201,7 @@ TEST_GROUP(side_channel) SideChannelManager::thread_init(); } - void teardown() + void teardown() override { SideChannelManager::thread_term(); SideChannelManager::term(); diff --git a/src/stream/test/stream_splitter_test.cc b/src/stream/test/stream_splitter_test.cc index 101cc266c..fe59e6519 100644 --- a/src/stream/test/stream_splitter_test.cc +++ b/src/stream/test/stream_splitter_test.cc @@ -43,7 +43,7 @@ SnortConfig* SnortConfig::get_conf() static StreamSplitter* next_splitter = nullptr; -Flow::Flow() { } +Flow::Flow() = default; struct Packet* DetectionEngine::get_current_packet() { return nullptr; }