NCBI C++ ToolKit
teamcity_messages.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* Copyright 2011 JetBrains s.r.o.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * $Revision: 79928 $
16 */
17 
18 #include <ncbi_pch.hpp>
19 
21 
22 #include <cstdlib>
23 #include <sstream>
24 
25 namespace jetbrains {
26 namespace teamcity {
27 
29 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && 0
30  char *flowId = NULL;
31  size_t sz = 0;
33  if(!_dupenv_s(&flowId, &sz,"TEAMCITY_PROCESS_FLOW_ID")) {
34  result = flowId != NULL ? flowId : "";
35  free(flowId);
36  }
37 
38  return result;
39 #else
40  const char *flowId = getenv("TEAMCITY_PROCESS_FLOW_ID");
41  return flowId == NULL ? "" : flowId;
42 #endif
43 }
44 
45 bool underTeamcity() {
46 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && 0
47  char *teamCityProjectName = 0;
48  size_t sz = 0;
49  bool result = false;
50  if(!_dupenv_s(&teamCityProjectName, &sz, "TEAMCITY_PROJECT_NAME")) {
51  result = teamCityProjectName != NULL;
52  free(teamCityProjectName);
53  }
54 
55  return result;
56 #else
57  return getenv("TEAMCITY_PROJECT_NAME") != NULL;
58 #endif
59 }
60 
62 : m_out(&std::cout)
63 {}
64 
65 void TeamcityMessages::setOutput(std::ostream &out) {
66  m_out = &out;
67 }
68 
71  result.reserve(s.length());
72 
73  for (size_t i = 0; i < s.length(); i++) {
74  char c = s[i];
75 
76  switch (c) {
77  case '\n': result.append("|n"); break;
78  case '\r': result.append("|r"); break;
79  case '\'': result.append("|'"); break;
80  case '|': result.append("||"); break;
81  case ']': result.append("|]"); break;
82  default: result.append(&c, 1);
83  }
84  }
85 
86  return result;
87 }
88 
90  *m_out << "##teamcity[" << name;
91 }
92 
94  *m_out << "]";
95  // endl for http://jetbrains.net/tracker/issue/TW-4412
96  *m_out << std::endl;
97 }
98 
100  *m_out << " " << name << "='" << escape(value) << "'";
101 }
102 
103 void TeamcityMessages::suiteStarted(const std::string &name, const std::string &flowid) {
104  openMsg("testSuiteStarted");
105  writeProperty("name", name);
106  if(flowid.length() > 0) {
107  writeProperty("flowId", flowid);
108  }
109 
110  closeMsg();
111 }
112 
113 void TeamcityMessages::suiteFinished(const std::string &name, const std::string &flowid) {
114  openMsg("testSuiteFinished");
115  writeProperty("name", name);
116  if(flowid.length() > 0) {
117  writeProperty("flowId", flowid);
118  }
119 
120  closeMsg();
121 }
122 
123 void TeamcityMessages::testStarted(const std::string &name, const std::string &flowid, bool captureStandardOutput) {
124  openMsg("testStarted");
125  writeProperty("name", name);
126  if(flowid.length() > 0) {
127  writeProperty("flowId", flowid);
128  }
129 
130  if(captureStandardOutput) {
131  writeProperty("captureStandardOutput", "true"); // false by default
132  }
133 
134  closeMsg();
135 }
136 
137 void TeamcityMessages::testFinished(const std::string &name, int durationMs, const std::string &flowid) {
138  openMsg("testFinished");
139 
140  writeProperty("name", name);
141 
142  if(flowid.length() > 0) {
143  writeProperty("flowId", flowid);
144  }
145 
146  if(durationMs >= 0) {
147  std::stringstream out(std::ios_base::out);
148  out << durationMs;
149  writeProperty("duration", out.str());
150  }
151 
152  closeMsg();
153 }
154 
155 void TeamcityMessages::testFailed(const std::string &name, const std::string &message, const std::string &details, const std::string &flowid) {
156  openMsg("testFailed");
157  writeProperty("name", name);
158  writeProperty("message", message);
159  writeProperty("details", details);
160  if(flowid.length() > 0) {
161  writeProperty("flowId", flowid);
162  }
163 
164  closeMsg();
165 }
166 
167 void TeamcityMessages::testIgnored(const std::string &name, const std::string &message, const std::string &flowid) {
168  openMsg("testIgnored");
169  writeProperty("name", name);
170  writeProperty("message", message);
171  if(flowid.length() > 0) {
172  writeProperty("flowId", flowid);
173  }
174 
175  closeMsg();
176 }
177 
178 void TeamcityMessages::testOutput(const std::string &name, const std::string &output, const std::string &flowid, bool isStdError) {
179  openMsg(isStdError ? "testStdErr" : "testStdOut");
180  writeProperty("name", name);
181  writeProperty("out", output);
182  if(flowid.length() > 0) {
183  writeProperty("flowId", flowid);
184  }
185 
186  closeMsg();
187 }
188 
189 }
190 }
void testFailed(const std::string &name, const std::string &message, const std::string &details, const std::string &flowid=std::string())
void suiteStarted(const std::string &name, const std::string &flowid=std::string())
void openMsg(const std::string &name)
void writeProperty(const std::string &name, const std::string &value)
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())
std::string escape(const std::string &s)
void suiteFinished(const std::string &name, const std::string &flowid=std::string())
void testIgnored(const std::string &name, const std::string &message, const std::string &flowid=std::string())
void testStarted(const std::string &name, const std::string &flowid=std::string(), bool captureStandardOutput=false)
std::ofstream out("events_result.xml")
main entry point for tests
static SQLCHAR output[256]
Definition: print.c:5
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
int i
std::string getFlowIdFromEnvironment()
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
else result
Definition: token2.c:20
void free(voidpf ptr)
Modified on Mon Jun 24 05:22:22 2024 by modify_doxy.py rev. 669887