Update source files for bracket style

This commit is contained in:
Marshall Greenblatt
2023-01-02 17:59:03 -05:00
parent d84b07a5cb
commit 3af3eab3e4
366 changed files with 7275 additions and 3834 deletions

View File

@@ -25,30 +25,31 @@
namespace jetbrains {
namespace teamcity {
class TeamcityGoogleTestEventListener: public ::testing::EmptyTestEventListener {
public:
TeamcityGoogleTestEventListener(const std::string& flowid);
TeamcityGoogleTestEventListener();
class TeamcityGoogleTestEventListener
: public ::testing::EmptyTestEventListener {
public:
TeamcityGoogleTestEventListener(const std::string& flowid);
TeamcityGoogleTestEventListener();
// Fired before the test case starts.
virtual void OnTestCaseStart(const ::testing::TestCase& test_case);
// Fired before the test starts.
virtual void OnTestStart(const ::testing::TestInfo& test_info);
// Fired after the test ends.
virtual void OnTestEnd(const ::testing::TestInfo& test_info);
// Fired after the test case ends.
virtual void OnTestCaseEnd(const ::testing::TestCase& test_case);
// Fired before the test case starts.
virtual void OnTestCaseStart(const ::testing::TestCase& test_case);
// Fired before the test starts.
virtual void OnTestStart(const ::testing::TestInfo& test_info);
// Fired after the test ends.
virtual void OnTestEnd(const ::testing::TestInfo& test_info);
// Fired after the test case ends.
virtual void OnTestCaseEnd(const ::testing::TestCase& test_case);
private:
TeamcityMessages messages;
std::string flowid;
private:
TeamcityMessages messages;
std::string flowid;
// Prevent copying.
TeamcityGoogleTestEventListener(const TeamcityGoogleTestEventListener&);
void operator =(const TeamcityGoogleTestEventListener&);
// Prevent copying.
TeamcityGoogleTestEventListener(const TeamcityGoogleTestEventListener&);
void operator=(const TeamcityGoogleTestEventListener&);
};
}
}
} // namespace teamcity
} // namespace jetbrains
#endif /* H_TEAMCITY_GTEST */

View File

@@ -22,65 +22,64 @@ namespace teamcity {
using namespace testing;
TeamcityGoogleTestEventListener::TeamcityGoogleTestEventListener() {
flowid = getFlowIdFromEnvironment();
flowid = getFlowIdFromEnvironment();
}
TeamcityGoogleTestEventListener::TeamcityGoogleTestEventListener(const std::string& flowid_)
: flowid(flowid_) {
}
TeamcityGoogleTestEventListener::TeamcityGoogleTestEventListener(
const std::string& flowid_)
: flowid(flowid_) {}
// Fired before the test case starts.
void TeamcityGoogleTestEventListener::OnTestCaseStart(const TestCase& test_case) {
messages.suiteStarted(test_case.name(), flowid);
void TeamcityGoogleTestEventListener::OnTestCaseStart(
const TestCase& test_case) {
messages.suiteStarted(test_case.name(), flowid);
}
// Fired before the test starts.
void TeamcityGoogleTestEventListener::OnTestStart(const TestInfo& test_info) {
messages.testStarted(test_info.name(), flowid);
messages.testStarted(test_info.name(), flowid);
}
// Fired after the test ends.
void TeamcityGoogleTestEventListener::OnTestEnd(const TestInfo& test_info) {
const TestResult* result = test_info.result();
if (result->Failed()) {
std::string message;
std::string details;
for (int i = 0; i < result->total_part_count(); ++i) {
const TestPartResult& partResult = result->GetTestPartResult(i);
if (partResult.passed()) {
continue;
}
const TestResult* result = test_info.result();
if (result->Failed()) {
std::string message;
std::string details;
for (int i = 0; i < result->total_part_count(); ++i) {
const TestPartResult& partResult = result->GetTestPartResult(i);
if (partResult.passed()) {
continue;
}
if (message.empty()) {
message = partResult.summary();
}
if (message.empty()) {
message = partResult.summary();
}
if (!details.empty()) {
details.append("\n");
}
details.append(partResult.message());
if (!details.empty()) {
details.append("\n");
}
details.append(partResult.message());
if (partResult.file_name() && partResult.line_number() >= 0) {
std::stringstream ss;
ss << "\n at " << partResult.file_name() << ":" << partResult.line_number();
details.append(ss.str());
}
}
messages.testFailed(
test_info.name(),
!message.empty() ? message : "failed",
details,
flowid
);
if (partResult.file_name() && partResult.line_number() >= 0) {
std::stringstream ss;
ss << "\n at " << partResult.file_name() << ":"
<< partResult.line_number();
details.append(ss.str());
}
}
messages.testFinished(test_info.name(), static_cast<int>(result->elapsed_time()), flowid);
messages.testFailed(test_info.name(), !message.empty() ? message : "failed",
details, flowid);
}
messages.testFinished(test_info.name(),
static_cast<int>(result->elapsed_time()), flowid);
}
// Fired after the test case ends.
void TeamcityGoogleTestEventListener::OnTestCaseEnd(const TestCase& test_case) {
messages.suiteFinished(test_case.name(), flowid);
messages.suiteFinished(test_case.name(), flowid);
}
}
}
} // namespace teamcity
} // namespace jetbrains

View File

@@ -1,11 +1,11 @@
/* Copyright 2011 JetBrains s.r.o.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,7 +13,7 @@
* limitations under the License.
*
* $Revision: 88625 $
*/
*/
#include "tests/gtest/teamcity/src/teamcity_messages.h"
@@ -24,166 +24,192 @@ namespace jetbrains {
namespace teamcity {
std::string getFlowIdFromEnvironment() {
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) && !defined(__MINGW32__)
char *flowId = NULL;
size_t sz = 0;
std::string result;
if(!_dupenv_s(&flowId, &sz,"TEAMCITY_PROCESS_FLOW_ID")) {
result = flowId != NULL ? flowId : "";
free(flowId);
}
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && \
!defined(__CYGWIN__) && !defined(__MINGW32__)
char* flowId = NULL;
size_t sz = 0;
std::string result;
if (!_dupenv_s(&flowId, &sz, "TEAMCITY_PROCESS_FLOW_ID")) {
result = flowId != NULL ? flowId : "";
free(flowId);
}
return result;
return result;
#else
const char *flowId = getenv("TEAMCITY_PROCESS_FLOW_ID");
return flowId == NULL ? "" : flowId;
const char* flowId = getenv("TEAMCITY_PROCESS_FLOW_ID");
return flowId == NULL ? "" : flowId;
#endif
}
bool underTeamcity() {
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) && !defined(__MINGW32__)
char *teamCityProjectName = 0;
size_t sz = 0;
bool result = false;
if(!_dupenv_s(&teamCityProjectName, &sz, "TEAMCITY_PROJECT_NAME")) {
result = teamCityProjectName != NULL;
free(teamCityProjectName);
}
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && \
!defined(__CYGWIN__) && !defined(__MINGW32__)
char* teamCityProjectName = 0;
size_t sz = 0;
bool result = false;
if (!_dupenv_s(&teamCityProjectName, &sz, "TEAMCITY_PROJECT_NAME")) {
result = teamCityProjectName != NULL;
free(teamCityProjectName);
}
return result;
return result;
#else
return getenv("TEAMCITY_PROJECT_NAME") != NULL;
return getenv("TEAMCITY_PROJECT_NAME") != NULL;
#endif
}
TeamcityMessages::TeamcityMessages()
: m_out(&std::cout)
{}
TeamcityMessages::TeamcityMessages() : m_out(&std::cout) {}
void TeamcityMessages::setOutput(std::ostream &out) {
m_out = &out;
void TeamcityMessages::setOutput(std::ostream& out) {
m_out = &out;
}
std::string TeamcityMessages::escape(const std::string &s) {
std::string result;
result.reserve(s.length());
std::string TeamcityMessages::escape(const std::string& s) {
std::string result;
result.reserve(s.length());
for (size_t i = 0; i < s.length(); i++) {
char c = s[i];
for (size_t i = 0; i < s.length(); i++) {
char c = s[i];
switch (c) {
case '\n': result.append("|n"); break;
case '\r': result.append("|r"); break;
case '\'': result.append("|'"); break;
case '|': result.append("||"); break;
case ']': result.append("|]"); break;
default: result.append(&c, 1);
}
switch (c) {
case '\n':
result.append("|n");
break;
case '\r':
result.append("|r");
break;
case '\'':
result.append("|'");
break;
case '|':
result.append("||");
break;
case ']':
result.append("|]");
break;
default:
result.append(&c, 1);
}
}
return result;
return result;
}
void TeamcityMessages::openMsg(const std::string &name) {
// endl for http://jetbrains.net/tracker/issue/TW-4412
*m_out << std::endl << "##teamcity[" << name;
void TeamcityMessages::openMsg(const std::string& name) {
// endl for http://jetbrains.net/tracker/issue/TW-4412
*m_out << std::endl << "##teamcity[" << name;
}
void TeamcityMessages::closeMsg() {
*m_out << "]";
// endl for http://jetbrains.net/tracker/issue/TW-4412
*m_out << std::endl;
*m_out << "]";
// endl for http://jetbrains.net/tracker/issue/TW-4412
*m_out << std::endl;
}
void TeamcityMessages::writeProperty(const std::string &name, const std::string &value) {
*m_out << " " << name << "='" << escape(value) << "'";
void TeamcityMessages::writeProperty(const std::string& name,
const std::string& value) {
*m_out << " " << name << "='" << escape(value) << "'";
}
void TeamcityMessages::suiteStarted(const std::string &name, const std::string &flowid) {
openMsg("testSuiteStarted");
writeProperty("name", name);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::suiteStarted(const std::string& name,
const std::string& flowid) {
openMsg("testSuiteStarted");
writeProperty("name", name);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
closeMsg();
closeMsg();
}
void TeamcityMessages::suiteFinished(const std::string &name, const std::string &flowid) {
openMsg("testSuiteFinished");
writeProperty("name", name);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::suiteFinished(const std::string& name,
const std::string& flowid) {
openMsg("testSuiteFinished");
writeProperty("name", name);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
closeMsg();
closeMsg();
}
void TeamcityMessages::testStarted(const std::string &name, const std::string &flowid, bool captureStandardOutput) {
openMsg("testStarted");
writeProperty("name", name);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::testStarted(const std::string& name,
const std::string& flowid,
bool captureStandardOutput) {
openMsg("testStarted");
writeProperty("name", name);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
if(captureStandardOutput) {
writeProperty("captureStandardOutput", "true"); // false by default
}
if (captureStandardOutput) {
writeProperty("captureStandardOutput", "true"); // false by default
}
closeMsg();
closeMsg();
}
void TeamcityMessages::testFinished(const std::string &name, int durationMs, const std::string &flowid) {
openMsg("testFinished");
void TeamcityMessages::testFinished(const std::string& name,
int durationMs,
const std::string& flowid) {
openMsg("testFinished");
writeProperty("name", name);
writeProperty("name", name);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
if(durationMs >= 0) {
std::stringstream out(std::ios_base::out);
out << durationMs;
writeProperty("duration", out.str());
}
if (durationMs >= 0) {
std::stringstream out(std::ios_base::out);
out << durationMs;
writeProperty("duration", out.str());
}
closeMsg();
closeMsg();
}
void TeamcityMessages::testFailed(const std::string &name, const std::string &message, const std::string &details, const std::string &flowid) {
openMsg("testFailed");
writeProperty("name", name);
writeProperty("message", message);
writeProperty("details", details);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::testFailed(const std::string& name,
const std::string& message,
const std::string& details,
const std::string& flowid) {
openMsg("testFailed");
writeProperty("name", name);
writeProperty("message", message);
writeProperty("details", details);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
closeMsg();
closeMsg();
}
void TeamcityMessages::testIgnored(const std::string &name, const std::string &message, const std::string &flowid) {
openMsg("testIgnored");
writeProperty("name", name);
writeProperty("message", message);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::testIgnored(const std::string& name,
const std::string& message,
const std::string& flowid) {
openMsg("testIgnored");
writeProperty("name", name);
writeProperty("message", message);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
closeMsg();
closeMsg();
}
void TeamcityMessages::testOutput(const std::string &name, const std::string &output, const std::string &flowid, bool isStdError) {
openMsg(isStdError ? "testStdErr" : "testStdOut");
writeProperty("name", name);
writeProperty("out", output);
if(flowid.length() > 0) {
writeProperty("flowId", flowid);
}
void TeamcityMessages::testOutput(const std::string& name,
const std::string& output,
const std::string& flowid,
bool isStdError) {
openMsg(isStdError ? "testStdErr" : "testStdOut");
writeProperty("name", name);
writeProperty("out", output);
if (flowid.length() > 0) {
writeProperty("flowId", flowid);
}
closeMsg();
closeMsg();
}
}
}
} // namespace teamcity
} // namespace jetbrains

View File

@@ -1,11 +1,11 @@
/* Copyright 2011 JetBrains s.r.o.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,7 +13,7 @@
* limitations under the License.
*
* $Revision: 88625 $
*/
*/
#ifndef H_TEAMCITY_MESSAGES
#define H_TEAMCITY_MESSAGES
@@ -28,34 +28,48 @@ std::string getFlowIdFromEnvironment();
bool underTeamcity();
class TeamcityMessages {
std::ostream *m_out;
std::ostream* m_out;
protected:
std::string escape(const std::string &s);
protected:
std::string escape(const std::string& s);
void openMsg(const std::string &name);
void writeProperty(const std::string &name, const std::string &value);
void closeMsg();
void openMsg(const std::string& name);
void writeProperty(const std::string& name, const std::string& value);
void closeMsg();
public:
static const bool StdErr = true;
static const bool StdOut = false;
public:
static const bool StdErr = true;
static const bool StdOut = false;
TeamcityMessages();
TeamcityMessages();
void setOutput(std::ostream &);
void setOutput(std::ostream&);
void suiteStarted(const std::string &name, const std::string &flowid = std::string());
void suiteFinished(const std::string &name, const std::string &flowid = std::string());
void suiteStarted(const std::string& name,
const std::string& flowid = std::string());
void suiteFinished(const std::string& name,
const std::string& flowid = std::string());
void testStarted(const std::string &name, const std::string &flowid = std::string(), bool captureStandardOutput = false);
void testFailed(const std::string &name, const std::string &message, const std::string &details, const std::string &flowid = std::string());
void testIgnored(const std::string &name, const std::string &message, const std::string &flowid = std::string());
void testOutput(const std::string &name, const std::string &output, const std::string &flowid, bool isStdErr = StdOut);
void testFinished(const std::string &name, int durationMs = -1, const std::string &flowid = std::string());
void testStarted(const std::string& name,
const std::string& flowid = std::string(),
bool captureStandardOutput = false);
void testFailed(const std::string& name,
const std::string& message,
const std::string& details,
const std::string& flowid = std::string());
void testIgnored(const std::string& name,
const std::string& message,
const std::string& flowid = std::string());
void testOutput(const std::string& name,
const std::string& output,
const std::string& flowid,
bool isStdErr = StdOut);
void testFinished(const std::string& name,
int durationMs = -1,
const std::string& flowid = std::string());
};
}
}
} // namespace teamcity
} // namespace jetbrains
#endif /* H_TEAMCITY_MESSAGES */