forked from cpputest/cpputest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamCityTestOutput.cpp
More file actions
100 lines (88 loc) · 2.54 KB
/
Copy pathTeamCityTestOutput.cpp
File metadata and controls
100 lines (88 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "CppUTest/TestHarness.h"
#include "CppUTest/TeamCityTestOutput.h"
TeamCityTestOutput::TeamCityTestOutput() : currtest_(NULLPTR), currGroup_()
{
}
TeamCityTestOutput::~TeamCityTestOutput()
{
}
void TeamCityTestOutput::printCurrentTestStarted(const UtestShell& test)
{
print("##teamcity[testStarted name='");
printEscaped(test.getName().asCharString());
print("']\n");
if (!test.willRun()) {
print("##teamcity[testIgnored name='");
printEscaped(test.getName().asCharString());
print("']\n");
}
currtest_ = &test;
}
void TeamCityTestOutput::printCurrentTestEnded(const TestResult& res)
{
if (!currtest_)
return;
print("##teamcity[testFinished name='");
printEscaped(currtest_->getName().asCharString());
print("' duration='");
print(res.getCurrentTestTotalExecutionTime());
print("']\n");
}
void TeamCityTestOutput::printCurrentGroupStarted(const UtestShell& test)
{
currGroup_ = test.getGroup();
print("##teamcity[testSuiteStarted name='");
printEscaped(currGroup_.asCharString());
print("']\n");
}
void TeamCityTestOutput::printCurrentGroupEnded(const TestResult& /*res*/)
{
if (currGroup_ == "")
return;
print("##teamcity[testSuiteFinished name='");
printEscaped(currGroup_.asCharString());
print("']\n");
}
void TeamCityTestOutput::printEscaped(const char* s)
{
while (*s) {
char str[3];
if ((*s == '\'') || (*s == '|') || (*s == '[') || (*s == ']')) {
str[0] = '|';
str[1] = *s;
str[2] = 0;
} else if (*s == '\r') {
str[0] = '|';
str[1] = 'r';
str[2] = 0;
} else if (*s == '\n') {
str[0] = '|';
str[1] = 'n';
str[2] = 0;
} else {
str[0] = *s;
str[1] = 0;
}
printBuffer(str);
s++;
}
}
void TeamCityTestOutput::printFailure(const TestFailure& failure)
{
print("##teamcity[testFailed name='");
printEscaped(failure.getTestNameOnly().asCharString());
print("' message='");
if (failure.isOutsideTestFile() || failure.isInHelperFunction()) {
print("TEST failed (");
print(failure.getTestFileName().asCharString());
print(":");
print(failure.getTestLineNumber());
print("): ");
}
printEscaped(failure.getFileName().asCharString());
print(":");
print(failure.getFailureLineNumber());
print("' details='");
printEscaped(failure.getMessage().asCharString());
print("']\n");
}