mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-30 19:57:10 +01:00 
			
		
		
		
	LegacyReporterAdapter unbundles INFO messages from assertion to mimic legacy behaviour
- Moved LegacyReporterAdapter out into its own file(s)
This commit is contained in:
		| @@ -29,6 +29,7 @@ | ||||
| #include "catch_version.hpp" | ||||
| #include "catch_line_wrap.hpp" | ||||
| #include "catch_message.hpp" | ||||
| #include "catch_legacy_reporter_adapter.hpp" | ||||
|  | ||||
| #include "../reporters/catch_reporter_basic.hpp" | ||||
| #include "../reporters/catch_reporter_xml.hpp" | ||||
| @@ -51,7 +52,6 @@ namespace Catch { | ||||
|     IReporterFactory::~IReporterFactory() {} | ||||
|     IReporterRegistry::~IReporterRegistry() {} | ||||
|     IStreamingReporter::~IStreamingReporter() {} | ||||
|     LegacyReporterAdapter::~LegacyReporterAdapter() {} | ||||
|     AssertionStats::~AssertionStats() {} | ||||
|     SectionStats::~SectionStats() {} | ||||
|     TestCaseStats::~TestCaseStats() {} | ||||
|   | ||||
| @@ -311,69 +311,6 @@ namespace Catch | ||||
|         virtual void Result( const AssertionResult& result ) = 0; | ||||
|     }; | ||||
|  | ||||
|     class LegacyReporterAdapter : public SharedImpl<IStreamingReporter> | ||||
|     { | ||||
|     public: | ||||
|         LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config ) | ||||
|         :   m_legacyReporter( legacyReporter ), | ||||
|             m_config( config ) | ||||
|         {} | ||||
|         virtual ~LegacyReporterAdapter(); | ||||
|  | ||||
|         virtual ReporterPreferences getPreferences() const { | ||||
|             ReporterPreferences prefs; | ||||
|             prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); | ||||
|             return prefs; | ||||
|         } | ||||
|  | ||||
|         virtual void noMatchingTestCases( std::string const& ) {} | ||||
|         virtual void testRunStarting( TestRunInfo const& ) { | ||||
|             m_legacyReporter->StartTesting(); | ||||
|         } | ||||
|         virtual void testGroupStarting( GroupInfo const& groupInfo ) { | ||||
|             m_legacyReporter->StartGroup( groupInfo.name ); | ||||
|         } | ||||
|         virtual void testCaseStarting( TestCaseInfo const& testInfo ) { | ||||
|             m_legacyReporter->StartTestCase( testInfo ); | ||||
|         } | ||||
|         virtual void sectionStarting( SectionInfo const& sectionInfo ) { | ||||
|             m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); | ||||
|         } | ||||
|         virtual void assertionStarting( AssertionInfo const& ) { | ||||
|             // Not on legacy interface | ||||
|         } | ||||
|  | ||||
|         virtual void assertionEnded( AssertionStats const& assertionStats ) { | ||||
|             m_legacyReporter->Result( assertionStats.assertionResult ); | ||||
|         } | ||||
|         virtual void sectionEnded( SectionStats const& sectionStats ) { | ||||
|             if( sectionStats.missingAssertions ) | ||||
|                 m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); | ||||
|             m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); | ||||
|         } | ||||
|         virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { | ||||
|             if( testCaseStats.missingAssertions ) | ||||
|                 m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name ); | ||||
|             m_legacyReporter->EndTestCase | ||||
|                 (   testCaseStats.testInfo, | ||||
|                     testCaseStats.totals, | ||||
|                     testCaseStats.stdOut, | ||||
|                     testCaseStats.stdErr ); | ||||
|         } | ||||
|         virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { | ||||
|             if( testGroupStats.aborting ) | ||||
|                 m_legacyReporter->Aborted(); | ||||
|             m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); | ||||
|         } | ||||
|         virtual void testRunEnded( TestRunStats const& testRunStats ) { | ||||
|             m_legacyReporter->EndTesting( testRunStats.totals ); | ||||
|         } | ||||
|  | ||||
|     private: | ||||
|         Ptr<IReporter> m_legacyReporter; | ||||
|         ReporterConfig m_config; | ||||
|     }; | ||||
|  | ||||
|      | ||||
|     struct IReporterFactory { | ||||
|         virtual ~IReporterFactory(); | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
| #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_interfaces_registry_hub.h" | ||||
| #include "catch_legacy_reporter_adapter.h" | ||||
|  | ||||
| namespace Catch {     | ||||
|  | ||||
|   | ||||
							
								
								
									
										40
									
								
								include/reporters/catch_legacy_reporter_adapter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								include/reporters/catch_legacy_reporter_adapter.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| /* | ||||
|  *  Created by Phil on 6th April 2013. | ||||
|  *  Copyright 2013 Two Blue Cubes Ltd. All rights reserved. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  */ | ||||
| #ifndef TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED | ||||
|  | ||||
| #include "catch_interfaces_reporter.h" | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|     class LegacyReporterAdapter : public SharedImpl<IStreamingReporter> | ||||
|     { | ||||
|     public: | ||||
|         LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config ); | ||||
|         virtual ~LegacyReporterAdapter(); | ||||
|  | ||||
|         virtual ReporterPreferences getPreferences() const; | ||||
|         virtual void noMatchingTestCases( std::string const& ); | ||||
|         virtual void testRunStarting( TestRunInfo const& ); | ||||
|         virtual void testGroupStarting( GroupInfo const& groupInfo ); | ||||
|         virtual void testCaseStarting( TestCaseInfo const& testInfo ); | ||||
|         virtual void sectionStarting( SectionInfo const& sectionInfo ); | ||||
|         virtual void assertionStarting( AssertionInfo const& ); | ||||
|         virtual void assertionEnded( AssertionStats const& assertionStats ); | ||||
|         virtual void sectionEnded( SectionStats const& sectionStats ); | ||||
|         virtual void testCaseEnded( TestCaseStats const& testCaseStats ); | ||||
|         virtual void testGroupEnded( TestGroupStats const& testGroupStats ); | ||||
|         virtual void testRunEnded( TestRunStats const& testRunStats ); | ||||
|  | ||||
|     private: | ||||
|         Ptr<IReporter> m_legacyReporter; | ||||
|         ReporterConfig m_config; | ||||
|     }; | ||||
| } | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED | ||||
							
								
								
									
										84
									
								
								include/reporters/catch_legacy_reporter_adapter.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								include/reporters/catch_legacy_reporter_adapter.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| /* | ||||
|  *  Created by Phil on 6th April 2013. | ||||
|  *  Copyright 2013 Two Blue Cubes Ltd. All rights reserved. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  */ | ||||
| #ifndef TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_legacy_reporter_adapter.h" | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|     LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config ) | ||||
|     :   m_legacyReporter( legacyReporter ), | ||||
|         m_config( config ) | ||||
|     {} | ||||
|     LegacyReporterAdapter::~LegacyReporterAdapter() {} | ||||
|  | ||||
|     ReporterPreferences LegacyReporterAdapter::getPreferences() const { | ||||
|         ReporterPreferences prefs; | ||||
|         prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); | ||||
|         return prefs; | ||||
|     } | ||||
|  | ||||
|     void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {} | ||||
|     void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) { | ||||
|         m_legacyReporter->StartTesting(); | ||||
|     } | ||||
|     void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) { | ||||
|         m_legacyReporter->StartGroup( groupInfo.name ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) { | ||||
|         m_legacyReporter->StartTestCase( testInfo ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) { | ||||
|         m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) { | ||||
|         // Not on legacy interface | ||||
|     } | ||||
|  | ||||
|     void LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { | ||||
|         if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { | ||||
|             for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); | ||||
|                     it != itEnd; | ||||
|                     ++it ) { | ||||
|                 if( it->type == ResultWas::Info ) { | ||||
|                     ExpressionResultBuilder expressionBuilder( it->type ); | ||||
|                         expressionBuilder << it->message; | ||||
|                     AssertionInfo info( it->macroName, it->lineInfo, "", ResultDisposition::Normal ); | ||||
|                     AssertionResult result = expressionBuilder.buildResult( info ); | ||||
|                     m_legacyReporter->Result( result ); | ||||
|                 } | ||||
|             } | ||||
|         }     | ||||
|         m_legacyReporter->Result( assertionStats.assertionResult ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { | ||||
|         if( sectionStats.missingAssertions ) | ||||
|             m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); | ||||
|         m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) { | ||||
|         if( testCaseStats.missingAssertions ) | ||||
|             m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name ); | ||||
|         m_legacyReporter->EndTestCase | ||||
|             (   testCaseStats.testInfo, | ||||
|                 testCaseStats.totals, | ||||
|                 testCaseStats.stdOut, | ||||
|                 testCaseStats.stdErr ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) { | ||||
|         if( testGroupStats.aborting ) | ||||
|             m_legacyReporter->Aborted(); | ||||
|         m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); | ||||
|     } | ||||
|     void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { | ||||
|         m_legacyReporter->EndTesting( testRunStats.totals ); | ||||
|     } | ||||
| } | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED | ||||
| @@ -57,6 +57,8 @@ | ||||
| /* Begin PBXFileReference section */ | ||||
| 		266B06B616F3A60A004ED264 /* VariadicMacrosTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VariadicMacrosTests.cpp; path = ../../../SelfTest/VariadicMacrosTests.cpp; sourceTree = "<group>"; }; | ||||
| 		266ECD73170F3C620030D735 /* BDDTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BDDTests.cpp; path = ../../../SelfTest/BDDTests.cpp; sourceTree = "<group>"; }; | ||||
| 		266ECD751710B2EB0030D735 /* catch_legacy_reporter_adapter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_legacy_reporter_adapter.h; sourceTree = "<group>"; }; | ||||
| 		266ECD761710B3970030D735 /* catch_legacy_reporter_adapter.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_legacy_reporter_adapter.hpp; sourceTree = "<group>"; }; | ||||
| 		26847E5B16BBAB790043B9C1 /* catch_message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_message.h; sourceTree = "<group>"; }; | ||||
| 		26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = "<group>"; }; | ||||
| 		26847E5D16BBADB40043B9C1 /* catch_message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_message.cpp; path = ../../../SelfTest/SurrogateCpps/catch_message.cpp; sourceTree = "<group>"; }; | ||||
| @@ -256,6 +258,8 @@ | ||||
| 				4A6D0C67149B3E3D00DB3EAA /* catch_reporter_junit.hpp */, | ||||
| 				4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */, | ||||
| 				4AB42F84166F3E1A0099F2C8 /* catch_reporter_console.hpp */, | ||||
| 				266ECD751710B2EB0030D735 /* catch_legacy_reporter_adapter.h */, | ||||
| 				266ECD761710B3970030D735 /* catch_legacy_reporter_adapter.hpp */, | ||||
| 			); | ||||
| 			name = reporters; | ||||
| 			path = ../../../../include/reporters; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash