Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

TeamCity reporter

added more detail to the assertion message
Commit
7306eb3cfcf36b8f4d8ff478a25be358b1651ef0
Author
Phil Nash ·
Parents
458b3ae257d4

Files · Download .tar.gz

Changes

 include/reporters/catch_reporter_teamcity.hpp | 56 +++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/include/reporters/catch_reporter_teamcity.hpp b/include/reporters/catch_reporter_teamcity.hpp
index 2de57d6a..16215e7a 100644
--- a/include/reporters/catch_reporter_teamcity.hpp
+++ b/include/reporters/catch_reporter_teamcity.hpp
@@ -62,11 +62,61 @@ namespace Catch {
         }
         
         virtual bool assertionEnded( AssertionStats const& assertionStats ) {
-            if( !assertionStats.assertionResult.isOk() ) {
+            AssertionResult const& result = assertionStats.assertionResult;
+            if( !result.isOk() ) {
+                
+                std::string message;
+                switch( result.getResultType() ) {
+                    case ResultWas::ExpressionFailed:
+                        message = "expression failed";
+                        break;
+                    case ResultWas::ThrewException:
+                        message = "unexpected exception with message";
+                        break;
+                    case ResultWas::FatalErrorCondition:
+                        message = "fatal error condition";
+                        break;
+                    case ResultWas::DidntThrowException:
+                        message = "no exception was thrown where one was expected";
+                        break;
+                    case ResultWas::ExplicitFailure:
+                        message = "explicit failure";
+                        break;
+
+                    // We shouldn't get here because of the isOk() test
+                    case ResultWas::Ok:
+                    case ResultWas::Info:
+                    case ResultWas::Warning:
+
+                    // These cases are here to prevent compiler warnings
+                    case ResultWas::Unknown:
+                    case ResultWas::FailureBit:
+                    case ResultWas::Exception:
+                        CATCH_NOT_IMPLEMENTED;
+                }
+                if( assertionStats.infoMessages.size() == 1 )
+                    message += " with message:";
+                if( assertionStats.infoMessages.size() > 1 )
+                    message += " with messages:";
+                for( std::vector<MessageInfo>::const_iterator
+                        it = assertionStats.infoMessages.begin(),
+                        itEnd = assertionStats.infoMessages.end();
+                    it != itEnd;
+                    ++it )
+                    message += "\n" + it->message;
+                
+                
+                std::string details =
+                    "  " + result.getExpressionInMacro() + "\n" +
+                    "with expansion:\n" +
+                    "  " + result.getExpandedExpression() + "\n";
+                
+                // !TBD: file/ line
+                
                 stream << "##teamcity[testFailed"
                     << " name='" << escape( currentTestCaseInfo->name )<< "'"
-                    << " message='message here'" // !TBD
-                    << " details='details?'" // !TBD
+                    << " message='" << escape( message ) << "'"
+                    << " details='" << escape( details ) << "'"
                     << "]\n";
             }
             return true;