1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include "GUITestTeamcityLogger.h"
23
24 #include <U2Core/Log.h>
25
26 #define ULOG_CAT_TEAMCITY "Teamcity Integration"
27
28 namespace U2 {
29 static Logger teamcityLog(ULOG_CAT_TEAMCITY);
30
31 const QString GUITestTeamcityLogger::successResult = "Success";
32
testStarted(const QString & testName)33 void GUITestTeamcityLogger::testStarted(const QString &testName) {
34 teamcityLog.trace(QString("##teamcity[testStarted name='%1']").arg(escaped(testName)));
35 }
36
testIgnored(const QString & testName,const QString & ignoreReason)37 void GUITestTeamcityLogger::testIgnored(const QString &testName, const QString &ignoreReason) {
38 teamcityLog.trace(QString("##teamcity[testIgnored name='%1' message='%2']").arg(escaped(testName), escaped(ignoreReason)));
39 }
40
teamCityLogResult(const QString & testName,const QString & testResult,qint64 testTimeMicros)41 void GUITestTeamcityLogger::teamCityLogResult(const QString &testName, const QString &testResult, qint64 testTimeMicros) {
42 if (isTestFailed(testResult)) {
43 teamcityLog.trace(QString("##teamcity[testFailed name='%1' message='%2' details='%2' duration='%3']").arg(escaped(testName), escaped(testResult), QString::number(testTimeMicros)));
44 }
45 teamcityLog.trace(QString("##teamcity[testFinished name='%1' duration='%2']").arg(escaped(testName), QString::number(testTimeMicros)));
46 }
47
escaped(const QString & s)48 QString GUITestTeamcityLogger::escaped(const QString &s) {
49 QString esc = s;
50 esc = esc.replace("|", "||");
51 esc = esc.replace("]", "|]");
52 esc = esc.replace("\r", "|r");
53 esc = esc.replace("\n", "|n");
54 esc = esc.replace("'", "|'");
55 return esc;
56 }
57
isTestFailed(const QString & testOutput)58 bool GUITestTeamcityLogger::isTestFailed(const QString &testOutput) {
59 return !testOutput.contains(successResult);
60 }
61
62 } // namespace U2
63