mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	| @@ -110,7 +110,7 @@ namespace Catch { | ||||
|             Catch::cleanUp(); | ||||
|         } | ||||
|  | ||||
|         void showHelp() { | ||||
|         void showHelp() const { | ||||
|             Catch::cout() | ||||
|                     << "\nCatch v" << libraryVersion() << "\n" | ||||
|                     << m_cli << std::endl | ||||
|   | ||||
| @@ -55,7 +55,7 @@ namespace Catch { | ||||
|         auto const setRngSeed = [&]( std::string const& seed ) { | ||||
|                 if( seed != "time" ) | ||||
|                     return clara::detail::convertInto( seed, config.rngSeed ); | ||||
|                 config.rngSeed = static_cast<unsigned int>( std::time(0) ); | ||||
|                 config.rngSeed = static_cast<unsigned int>( std::time(nullptr) ); | ||||
|                 return ParserResult::ok( ParseResultType::Matched ); | ||||
|             }; | ||||
|         auto const setColourUsage = [&]( std::string const& useColour ) { | ||||
|   | ||||
| @@ -98,7 +98,7 @@ namespace Catch { | ||||
|     // as well as | ||||
|     //    >> stuff +StreamEndStop | ||||
|     struct StreamEndStop { | ||||
|         std::string operator+() { | ||||
|         std::string operator+() const { | ||||
|             return std::string(); | ||||
|         } | ||||
|     }; | ||||
|   | ||||
| @@ -59,7 +59,7 @@ namespace { | ||||
|             originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); | ||||
|         } | ||||
|  | ||||
|         virtual void use( Colour::Code _colourCode ) { | ||||
|         virtual void use( Colour::Code _colourCode ) override { | ||||
|             switch( _colourCode ) { | ||||
|                 case Colour::None:      return setTextAttribute( originalForegroundAttributes ); | ||||
|                 case Colour::White:     return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); | ||||
| @@ -118,7 +118,7 @@ namespace { | ||||
|     // https://github.com/philsquared/Catch/pull/131 | ||||
|     class PosixColourImpl : public IColourImpl { | ||||
|     public: | ||||
|         virtual void use( Colour::Code _colourCode ) { | ||||
|         virtual void use( Colour::Code _colourCode ) override { | ||||
|             switch( _colourCode ) { | ||||
|                 case Colour::None: | ||||
|                 case Colour::White:     return setColour( "[0m" ); | ||||
| @@ -179,10 +179,13 @@ namespace Catch { | ||||
| namespace Catch { | ||||
|  | ||||
|     Colour::Colour( Code _colourCode ) { use( _colourCode ); } | ||||
|     Colour::Colour( Colour&& _other ) { const_cast<Colour&>( _other ).m_moved = true; } | ||||
|     Colour& Colour::operator=( Colour&& _other ) { | ||||
|         m_moved = false; | ||||
|         const_cast<Colour&>( _other ).m_moved = true; | ||||
|     Colour::Colour( Colour&& rhs ) noexcept {  | ||||
|         m_moved = rhs.m_moved; | ||||
|         rhs.m_moved = true; | ||||
|     } | ||||
|     Colour& Colour::operator=( Colour&& rhs ) noexcept { | ||||
|         m_moved = rhs.m_moved; | ||||
|         rhs.m_moved  = true; | ||||
|         return *this; | ||||
|     } | ||||
|      | ||||
|   | ||||
| @@ -50,8 +50,8 @@ namespace Catch { | ||||
|  | ||||
|         // Use constructed object for RAII guard | ||||
|         Colour( Code _colourCode ); | ||||
|         Colour( Colour&& other ); | ||||
|         Colour& operator=( Colour&& other ); | ||||
|         Colour( Colour&& other ) noexcept; | ||||
|         Colour& operator=( Colour&& other ) noexcept; | ||||
|         ~Colour(); | ||||
|  | ||||
|         // Use static method for one-shot changes | ||||
|   | ||||
| @@ -16,32 +16,30 @@ namespace Catch { | ||||
|     class Context : public IMutableContext, NonCopyable { | ||||
|  | ||||
|     public: // IContext | ||||
|         virtual IResultCapture* getResultCapture() { | ||||
|         virtual IResultCapture* getResultCapture() override { | ||||
|             return m_resultCapture; | ||||
|         } | ||||
|         virtual IRunner* getRunner() { | ||||
|         virtual IRunner* getRunner() override { | ||||
|             return m_runner; | ||||
|         } | ||||
|  | ||||
|         virtual IConfigPtr getConfig() const { | ||||
|         virtual IConfigPtr getConfig() const override { | ||||
|             return m_config; | ||||
|         } | ||||
|  | ||||
|     public: // IMutableContext | ||||
|         virtual void setResultCapture( IResultCapture* resultCapture ) { | ||||
|         virtual void setResultCapture( IResultCapture* resultCapture ) override { | ||||
|             m_resultCapture = resultCapture; | ||||
|         } | ||||
|         virtual void setRunner( IRunner* runner ) { | ||||
|         virtual void setRunner( IRunner* runner ) override { | ||||
|             m_runner = runner; | ||||
|         } | ||||
|         virtual void setConfig( IConfigPtr const& config ) { | ||||
|         virtual void setConfig( IConfigPtr const& config ) override { | ||||
|             m_config = config; | ||||
|         } | ||||
|  | ||||
|         friend IMutableContext& getCurrentMutableContext(); | ||||
|  | ||||
|     private: | ||||
|  | ||||
|     private: | ||||
|         IConfigPtr m_config; | ||||
|         IRunner* m_runner = nullptr; | ||||
|   | ||||
| @@ -46,7 +46,7 @@ namespace Internal { | ||||
|     // So the compare overloads can be operator agnostic we convey the operator as a template | ||||
|     // enum, which is used to specialise an Evaluator for doing the comparison. | ||||
|     template<typename T1, typename T2, Operator Op> | ||||
|     class Evaluator{}; | ||||
|     struct Evaluator{}; | ||||
|  | ||||
|     template<typename T1, typename T2> | ||||
|     struct Evaluator<T1, T2, IsEqualTo> { | ||||
|   | ||||
| @@ -19,7 +19,7 @@ namespace Catch { | ||||
|     public: | ||||
|         ~ExceptionTranslatorRegistry(); | ||||
|         virtual void registerTranslator( const IExceptionTranslator* translator ); | ||||
|         virtual std::string translateActiveException() const; | ||||
|         virtual std::string translateActiveException() const override; | ||||
|         std::string tryTranslators() const; | ||||
|  | ||||
|     private: | ||||
|   | ||||
| @@ -19,7 +19,7 @@ namespace Catch { | ||||
|  | ||||
|         virtual ~NotImplementedException() noexcept = default; | ||||
|  | ||||
|         virtual const char* what() const noexcept; | ||||
|         virtual const char* what() const noexcept override; | ||||
|  | ||||
|     private: | ||||
|         std::string m_what; | ||||
|   | ||||
| @@ -17,11 +17,11 @@ namespace Catch { | ||||
|  | ||||
|         class ReporterFactory : public IReporterFactory { | ||||
|  | ||||
|             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const { | ||||
|             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { | ||||
|                 return std::unique_ptr<T>( new T( config ) ); | ||||
|             } | ||||
|  | ||||
|             virtual std::string getDescription() const { | ||||
|             virtual std::string getDescription() const override { | ||||
|                 return T::getDescription(); | ||||
|             } | ||||
|         }; | ||||
| @@ -38,10 +38,10 @@ namespace Catch { | ||||
|  | ||||
|         class ListenerFactory : public IReporterFactory { | ||||
|  | ||||
|             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const { | ||||
|             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { | ||||
|                 return std::make_shared<T>( config ); | ||||
|             } | ||||
|             virtual std::string getDescription() const { | ||||
|             virtual std::string getDescription() const override { | ||||
|                 return std::string(); | ||||
|             } | ||||
|         }; | ||||
|   | ||||
| @@ -63,33 +63,30 @@ namespace Catch { | ||||
|     private: // IResultCapture | ||||
|  | ||||
|  | ||||
|         virtual void assertionEnded(AssertionResult const& result); | ||||
|         virtual void assertionEnded(AssertionResult const& result) override; | ||||
|  | ||||
|         virtual bool sectionStarted( | ||||
|             SectionInfo const& sectionInfo, | ||||
|             Counts& assertions | ||||
|         ); | ||||
|         virtual bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; | ||||
|         bool testForMissingAssertions(Counts& assertions); | ||||
|  | ||||
|         virtual void sectionEnded(SectionEndInfo const& endInfo); | ||||
|         virtual void sectionEnded(SectionEndInfo const& endInfo) override; | ||||
|  | ||||
|         virtual void sectionEndedEarly(SectionEndInfo const& endInfo); | ||||
|         virtual void sectionEndedEarly(SectionEndInfo const& endInfo) override; | ||||
|  | ||||
|         virtual void pushScopedMessage(MessageInfo const& message); | ||||
|         virtual void pushScopedMessage(MessageInfo const& message) override; | ||||
|  | ||||
|         virtual void popScopedMessage(MessageInfo const& message); | ||||
|         virtual void popScopedMessage(MessageInfo const& message) override; | ||||
|  | ||||
|         virtual std::string getCurrentTestName() const; | ||||
|         virtual std::string getCurrentTestName() const override; | ||||
|  | ||||
|         virtual const AssertionResult* getLastResult() const; | ||||
|         virtual const AssertionResult* getLastResult() const override; | ||||
|  | ||||
|         virtual void exceptionEarlyReported(); | ||||
|         virtual void exceptionEarlyReported() override; | ||||
|  | ||||
|         virtual void handleFatalErrorCondition(std::string const& message); | ||||
|         virtual void handleFatalErrorCondition(std::string const& message) override; | ||||
|  | ||||
|     public: | ||||
|         // !TBD We need to do this another way! | ||||
|         bool aborting() const; | ||||
|         bool aborting() const override; | ||||
|  | ||||
|     private: | ||||
|  | ||||
|   | ||||
| @@ -30,11 +30,11 @@ namespace Catch { | ||||
|         } | ||||
|  | ||||
|         ~StreamBufImpl() noexcept { | ||||
|             sync(); | ||||
|             StreamBufImpl::sync(); | ||||
|         } | ||||
|  | ||||
|     private: | ||||
|         int overflow( int c ) { | ||||
|         int overflow( int c ) override { | ||||
|             sync(); | ||||
|  | ||||
|             if( c != EOF ) { | ||||
| @@ -46,7 +46,7 @@ namespace Catch { | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         int sync() { | ||||
|         int sync() override { | ||||
|             if( pbase() != pptr() ) { | ||||
|                 m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); | ||||
|                 setp( pbase(), epptr() ); | ||||
|   | ||||
| @@ -32,7 +32,7 @@ namespace Catch { | ||||
|     { | ||||
|         m_data->addRef(); | ||||
|     } | ||||
|     String::String( String&& other ) | ||||
|     String::String( String&& other ) noexcept | ||||
|     : m_data( other.m_data ) | ||||
|     { | ||||
|         other.m_data = StringData::getEmpty(); | ||||
|   | ||||
| @@ -28,7 +28,7 @@ namespace Catch { | ||||
|         String( StringRef const& stringRef ); | ||||
|         String( char const* rawString ); | ||||
|         String( String const& other ); | ||||
|         String( String&& other ); | ||||
|         String( String&& other ) noexcept; | ||||
|         String( StringBuilder&& stringBuf ); | ||||
|          | ||||
|         ~String() noexcept; | ||||
|   | ||||
| @@ -55,7 +55,7 @@ namespace Catch { | ||||
|     { | ||||
|         size_type rawSize = rawChars == nullptr ? 0 : static_cast<size_type>( std::strlen( rawChars ) ); | ||||
|         if( rawSize < size ) | ||||
|             size = rawSize; | ||||
|             m_size = rawSize; | ||||
|     } | ||||
|      | ||||
|     StringRef::StringRef( String const& other ) noexcept | ||||
|   | ||||
| @@ -63,7 +63,7 @@ namespace TestCaseTracking { | ||||
|  | ||||
|  | ||||
|     TrackerBase::TrackerHasName::TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} | ||||
|     bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) { | ||||
|     bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) const { | ||||
|         return | ||||
|             tracker->nameAndLocation().name == m_nameAndLocation.name && | ||||
|             tracker->nameAndLocation().location == m_nameAndLocation.location; | ||||
| @@ -133,7 +133,7 @@ namespace TestCaseTracking { | ||||
|  | ||||
|         switch( m_runState ) { | ||||
|             case NeedsAnotherRun: | ||||
|                 break;; | ||||
|                 break; | ||||
|  | ||||
|             case Executing: | ||||
|                 m_runState = CompletedSuccessfully; | ||||
|   | ||||
| @@ -101,7 +101,7 @@ namespace TestCaseTracking { | ||||
|             NameAndLocation m_nameAndLocation; | ||||
|         public: | ||||
|             TrackerHasName( NameAndLocation const& nameAndLocation ); | ||||
|             bool operator ()( ITrackerPtr const& tracker ); | ||||
|             bool operator ()( ITrackerPtr const& tracker ) const; | ||||
|         }; | ||||
|  | ||||
|         typedef std::vector<ITrackerPtr> Children; | ||||
|   | ||||
| @@ -33,7 +33,7 @@ namespace Catch { | ||||
|         public: | ||||
|             NamePattern( std::string const& name ); | ||||
|             virtual ~NamePattern() = default; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const override; | ||||
|         private: | ||||
|             WildcardPattern m_wildcardPattern; | ||||
|         }; | ||||
| @@ -42,7 +42,7 @@ namespace Catch { | ||||
|         public: | ||||
|             TagPattern( std::string const& tag ); | ||||
|             virtual ~TagPattern() = default; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const override; | ||||
|         private: | ||||
|             std::string m_tag; | ||||
|         }; | ||||
| @@ -51,7 +51,7 @@ namespace Catch { | ||||
|         public: | ||||
|             ExcludedPattern( PatternPtr const& underlyingPattern ); | ||||
|             virtual ~ExcludedPattern() = default; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const; | ||||
|             virtual bool matches( TestCaseInfo const& testCase ) const override; | ||||
|         private: | ||||
|             PatternPtr m_underlyingPattern; | ||||
|         }; | ||||
|   | ||||
| @@ -65,11 +65,11 @@ namespace Catch { | ||||
|     :   m_writer( writer ) | ||||
|     {} | ||||
|  | ||||
|     XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) | ||||
|     XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept | ||||
|     :   m_writer( other.m_writer ){ | ||||
|         other.m_writer = nullptr; | ||||
|     } | ||||
|     XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) { | ||||
|     XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { | ||||
|         if ( m_writer ) { | ||||
|             m_writer->endElement(); | ||||
|         } | ||||
|   | ||||
| @@ -38,8 +38,8 @@ namespace Catch { | ||||
|         public: | ||||
|             ScopedElement( XmlWriter* writer ); | ||||
|  | ||||
|             ScopedElement( ScopedElement&& other ); | ||||
|             ScopedElement& operator=( ScopedElement&& other ); | ||||
|             ScopedElement( ScopedElement&& other ) noexcept; | ||||
|             ScopedElement& operator=( ScopedElement&& other ) noexcept; | ||||
|  | ||||
|             ~ScopedElement(); | ||||
|  | ||||
|   | ||||
| @@ -17,6 +17,12 @@ | ||||
| #include <memory> | ||||
|  | ||||
| namespace Catch { | ||||
|     void prepareExpandedExpression(AssertionResult& result) { | ||||
|         if (result.isOk()) | ||||
|             result.discardDecomposedExpression(); | ||||
|         else | ||||
|             result.expandDecomposedExpression(); | ||||
|     } | ||||
|  | ||||
|     // Because formatting using c++ streams is stateful, drop down to C is required | ||||
|     // Alternatively we could use stringstream, but its performance is... not good. | ||||
|   | ||||
| @@ -17,6 +17,7 @@ | ||||
| #include <memory> | ||||
|  | ||||
| namespace Catch { | ||||
|     void prepareExpandedExpression(AssertionResult& result); | ||||
|  | ||||
|     // Returns double formatted as %.3f (format expected on output) | ||||
|     std::string getFormattedDuration( double duration ); | ||||
| @@ -230,13 +231,6 @@ namespace Catch { | ||||
|  | ||||
|         void skipTest(TestCaseInfo const&) override {} | ||||
|  | ||||
|         void prepareExpandedExpression(AssertionResult& result) const { | ||||
|             if (result.isOk()) | ||||
|                 result.discardDecomposedExpression(); | ||||
|             else | ||||
|                 result.expandDecomposedExpression(); | ||||
|         } | ||||
|  | ||||
|         IConfigPtr m_config; | ||||
|         std::ostream& stream; | ||||
|         std::vector<AssertionStats> m_assertions; | ||||
|   | ||||
| @@ -11,6 +11,25 @@ | ||||
| #include "../internal/catch_reporter_registrars.hpp" | ||||
| #include "../internal/catch_console_colour.hpp" | ||||
|  | ||||
| namespace { | ||||
|  | ||||
| #ifdef CATCH_PLATFORM_MAC | ||||
|     const char* failedString() { return "FAILED"; } | ||||
|     const char* passedString() { return "PASSED"; } | ||||
| #else | ||||
|     const char* failedString() { return "failed"; } | ||||
|     const char* passedString() { return "passed"; } | ||||
| #endif | ||||
|  | ||||
|     // Colour::LightGrey | ||||
|     Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } | ||||
|  | ||||
|     std::string bothOrAll( std::size_t count ) { | ||||
|         return count == 1 ? std::string() : | ||||
|                count == 2 ? "both " : "all " ; | ||||
|     } | ||||
| } | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
|     struct CompactReporter : StreamingReporterBase<CompactReporter> { | ||||
| @@ -148,18 +167,6 @@ namespace Catch { | ||||
|             } | ||||
|  | ||||
|         private: | ||||
|             // Colour::LightGrey | ||||
|  | ||||
|             static Colour::Code dimColour() { return Colour::FileName; } | ||||
|  | ||||
| #ifdef CATCH_PLATFORM_MAC | ||||
|             static const char* failedString() { return "FAILED"; } | ||||
|             static const char* passedString() { return "PASSED"; } | ||||
| #else | ||||
|             static const char* failedString() { return "failed"; } | ||||
|             static const char* passedString() { return "passed"; } | ||||
| #endif | ||||
|  | ||||
|             void printSourceInfo() const { | ||||
|                 Colour colourGuard( Colour::FileName ); | ||||
|                 stream << result.getSourceInfo() << ':'; | ||||
| @@ -253,10 +260,6 @@ namespace Catch { | ||||
|         // -   red: Failed N tests cases, failed M assertions. | ||||
|         // - green: Passed [both/all] N tests cases with M assertions. | ||||
|  | ||||
|         std::string bothOrAll( std::size_t count ) const { | ||||
|             return count == 1 ? std::string() : count == 2 ? "both " : "all " ; | ||||
|         } | ||||
|  | ||||
|         void printTotals( const Totals& totals ) const { | ||||
|             if( totals.testCases.total() == 0 ) { | ||||
|                 stream << "No tests ran."; | ||||
|   | ||||
| @@ -16,6 +16,22 @@ | ||||
| #include <cfloat> | ||||
| #include <cstdio> | ||||
|  | ||||
| namespace { | ||||
|     std::size_t makeRatio( std::size_t number, std::size_t total ) { | ||||
|         std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; | ||||
|         return ( ratio == 0 && number > 0 ) ? 1 : ratio; | ||||
|     } | ||||
|  | ||||
|     std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { | ||||
|         if( i > j && i > k ) | ||||
|             return i; | ||||
|         else if( j > k ) | ||||
|             return j; | ||||
|         else | ||||
|             return k; | ||||
|     } | ||||
| } | ||||
|  | ||||
| namespace Catch { | ||||
|  | ||||
|     struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> { | ||||
| @@ -390,19 +406,6 @@ namespace Catch { | ||||
|             stream << '\n'; | ||||
|         } | ||||
|  | ||||
|         static std::size_t makeRatio( std::size_t number, std::size_t total ) { | ||||
|             std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; | ||||
|             return ( ratio == 0 && number > 0 ) ? 1 : ratio; | ||||
|         } | ||||
|         static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { | ||||
|             if( i > j && i > k ) | ||||
|                 return i; | ||||
|             else if( j > k ) | ||||
|                 return j; | ||||
|             else | ||||
|                 return k; | ||||
|         } | ||||
|  | ||||
|         void printTotalsDivider( Totals const& totals ) { | ||||
|             if( totals.testCases.total() > 0 ) { | ||||
|                 std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() ); | ||||
|   | ||||
| @@ -187,7 +187,7 @@ namespace Catch { | ||||
|  | ||||
|         // if string has a : in first line will set indent to follow it on | ||||
|         // subsequent lines | ||||
|         void printHeaderString( std::ostream& os, std::string const& _string, std::size_t indent = 0 ) { | ||||
|         static void printHeaderString( std::ostream& os, std::string const& _string, std::size_t indent = 0 ) { | ||||
|             std::size_t i = _string.find( ": " ); | ||||
|             if( i != std::string::npos ) | ||||
|                 i+=2; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský