8000 First commit of (in progress) TeamCity reporter · log4cplus/Catch@db0421e · GitHub
[go: up one dir, main page]

Skip to content

Commit db0421e

Browse files
committed
First commit of (in progress) TeamCity reporter
Should run but is not complete
1 parent acf638f commit db0421e

File tree

6 files changed

+133
-5
lines changed

6 files changed

+133
-5
lines changed

include/catch.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
#include "internal/catch_suppress_warnings.h"
1313

14-
#ifdef CATCH_CONFIG_MAIN
15-
# define CATCH_CONFIG_RUNNER
14+
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
15+
# define CATCH_IMPL
1616
#endif
1717

18-
#ifdef CATCH_CONFIG_RUNNER
18+
#ifdef CATCH_IMPL
1919
# ifndef CLARA_CONFIG_MAIN
2020
# define CLARA_CONFIG_MAIN_NOT_DEFINED
2121
# define CLARA_CONFIG_MAIN
@@ -43,7 +43,7 @@
4343
#include "internal/catch_objc.hpp"
4444
#endif
4545

46-
#ifdef CATCH_CONFIG_RUNNER
46+
#ifdef CATCH_IMPL
4747
#include "internal/catch_impl.hpp"
4848
#endif
4949

include/internal/catch_interfaces_reporter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ namespace Catch
238238

239239
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
240240

241+
// The return value indicates if the messages buffer should be cleared:
241242
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
242243
virtual void sectionEnded( SectionStats const& sectionSta 8000 ts ) = 0;
243244
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;

include/internal/catch_list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace Catch {
139139
}
140140

141141
inline std::size_t listReporters( Config const& /*config*/ ) {
142-
Catch::cout() << "Available reports:\n";
142+
Catch::cout() << "Available reporters:\n";
143143
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
144144
IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
145145
std::size_t maxNameLen = 0;
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Created by Phil Nash on 19th December 2014
3+
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
4+
*
5+
* Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
*/
8+
#ifndef TWOBLUECUBES_CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
9+
#define TWOBLUECUBES_CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
10+
11+
#include "catch_reporter_bases.hpp"
12+
13+
#include "../internal/catch_reporter_registrars.hpp"
14+
15+
#include <cstring>
16+
17+
namespace Catch {
18+
19+
struct TeamCityReporter : StreamingReporterBase {
20+
TeamCityReporter( ReporterConfig const& _config )
21+
: StreamingReporterBase( _config )
22+
{}
23+
24+
static bool replace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
25+
std::size_t i = str.find( replaceThis );
26+
if( i != std::string::npos ) {
27+
str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
28+
return true;
29+
}
30+
return false;
31+
}
32+
static std::string escape( std::string const& str ) {
33+
std::string escaped = str;
34+
while( replace( escaped, "\'", "|\'" ) ||
35+
replace( escaped, "\n", "|n" ) ||
36+
replace( escaped, "\r", "|r" ) ||
37+
replace( escaped, "|", "||" ) ||
38+
replace( escaped, "[", "|[" ) ||
39+
replace( escaped, "]", "|]" ) );
40+
return escaped;
41+
}
42+
virtual ~TeamCityReporter();
43+
44+
static std::string getDescription() {
45+
return "Reports test results as TeamCity service messages";
46+
}
47+
virtual ReporterPreferences getPreferences() const {
48+
ReporterPreferences prefs;
49+
prefs.shouldRedirectStdOut = true;
50+
return prefs;
51+
}
52+
53+
// !TBD: ignored tests
54+
55+
virtual void noMatchingTestCases( std::string const& /* spec */ ) {}
56+
57+
virtual void testGroupStarting( GroupInfo const& groupInfo ) {
58+
StreamingReporterBase::testGroupStarting( groupInfo );
59+
stream << "##teamcity[testSuiteStarted name='"
60+
<< escape( groupInfo.name ) << "']\n";
61+
}
62+
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) {
63+
StreamingReporterBase::testGroupEnded( testGroupStats );
64+
stream << "##teamcity[testSuiteFinished name='"
65+
<< escape( testGroupStats.groupInfo.name ) << "']\n";
66+
}
67+
68+
69+
virtual void assertionStarting( AssertionInfo const& ) {
70+
}
71+
72+
virtual bool assertionEnded( AssertionStats const& assertionStats ) {
73+
if( !assertionStats.assertionResult.isOk() ) {
74+
stream << "##teamcity[testFailed"
75+
<< " name='" << escape( currentTestCaseInfo->name )<< "'"
76+
<< " message='message here'" // !TBD
77+
<< " details='details?'" // !TBD
78+
<< "]\n";
79+
}
80+
return true;
81+
}
82+
83+
// virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
84+
// // !TBD
85+
// }
86+
// virtual void sectionEnded( SectionStats const& _sectionStats ) {
87+
// // !TBD
88+
// }
89+
90+
virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
91+
StreamingReporterBase::testCaseStarting( testInfo );
92+
stream << "##teamcity[testStarted name='"
93+
<< escape( testInfo.name ) << "']\n";
94+
}
95+
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
96+
StreamingReporterBase::testCaseEnded( testCaseStats );
97+
if( !testCaseStats.stdOut.empty() )
98+
stream << "##teamcity[testStdOut name='"
99+
<< escape( testCaseStats.testInfo.name )
100+
<< "' out='" << escape( testCaseStats.stdOut ) << "']\n";
101+
if( !testCaseStats.stdErr.empty() )
102+
stream << "##teamcity[testStdErr name='"
103+
<< escape( testCaseStats.testInfo.name )
104+
<< "' out='" << escape( testCaseStats.stdErr ) << "']\n";
105+
stream << "##teamcity[testFinished name='"
106+
<< escape( testCaseStats.testInfo.name ) << "']\n";
107+
}
108+
// virtual void testRunEnded( TestRunStats const& _testRunStats ) {
109+
// // !TBD
110+
// }
111+
112+
private:
113+
114+
};
115+
116+
#ifdef CATCH_IMPL
117+
TeamCityReporter::~TeamCityReporter() {}
118+
#endif
119+
120+
INTERNAL_CATCH_REGISTER_REPORTER( "teamcity", TeamCityReporter )
121+
122+
} // end namespace Catch
123+
124+
#endif // TWOBLUECUBES_CATCH_REPORTER_TEAMCITY_HPP_INCLUDED

projects/SelfTest/TestMain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define CATCH_CONFIG_MAIN
1010
#include "catch.hpp"
11+
#include "reporters/catch_reporter_teamcity.hpp"
1112

1213
// Some example tag aliases
1314
CATCH_REGISTER_TAG_ALIAS( "[@nhf]", "[failing]~[.]" )

projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = "<group>"; };
9797
26847E5D16BBADB40043B9C1 /* catch_message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_message.cpp; path = ../../../SelfTest/SurrogateCpps/catch_message.cpp; sourceTree = "<group>"; };
9898
268F47B018A93F7800D8C14F /* catch_clara.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_clara.h; sourceTree = "<group>"; };
99+
2691574A1A4480C50054F1ED /* catch_reporter_teamcity.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_teamcity.hpp; sourceTree = "<group>"; };
99100
26926E8318D7777D004E10F2 /* clara.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = clara.h; path = ../../../../include/external/clara.h; sourceTree = "<group>"; };
100101
26926E8418D77809004E10F2 /* tbc_text_format.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tbc_text_format.h; path = ../../../../include/external/tbc_text_format.h; sourceTree = "<group>"; };
101102
26948284179A9AB900ED166E /* SectionTrackerTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SectionTrackerTests.cpp; path = ../../../SelfTest/SectionTrackerTests.cpp; sourceTree = "<group>"; };
@@ -313,6 +314,7 @@
313314
4A6D0C67149B3E3D00DB3EAA /* catch_reporter_junit.hpp */,
314315
4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */,
315316
4AB42F84166F3E1A0099F2C8 /* catch_reporter_console.hpp */,
317+
2691574A1A4480C50054F1ED /* catch_reporter_teamcity.hpp */,
316318
);
317319
name = reporters;
318320
path = ../../../../include/reporters;

0 commit comments

Comments
 (0)
0