Skip to content

Commit b47c6d6

Browse files
committed
add status parsing from json
1 parent 5a2d0ec commit b47c6d6

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

server/src/coverage/CoverageAndResultsGenerator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ grpc::Status CoverageAndResultsGenerator::generate(bool withCoverage,
4949
return Status::CANCELLED;
5050
}
5151
showErrors();
52-
fs::remove(Paths::getGTestResultsJsonPath(projectContext));
5352
return Status::OK;
5453
}
5554

server/src/coverage/TestRunner.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,37 +195,41 @@ testsgen::TestResultObject TestRunner::runTest(const BuildRunCommand &command, c
195195
auto res = command.runCommand.run(projectContext.buildDir, true, true, testTimeout);
196196
GTestLogger::log(res.output);
197197

198+
testsgen::TestResultObject testRes;
199+
testRes.set_testfilepath(command.unitTest.testFilePath);
200+
testRes.set_testname(command.unitTest.testname);
198201
auto executionTime = new google::protobuf::Duration;
199-
if (fs::exists(Paths::getGTestResultsJsonPath(projectContext))) {
200-
nlohmann::json gtestResultsJson = JsonUtils::getJsonFromFile(Paths::getGTestResultsJsonPath(projectContext));
201-
if (!google::protobuf::util::TimeUtil::FromString(gtestResultsJson["time"], executionTime)) {
202-
LOG_S(WARNING) << "Cannot parse duration of test execution";
203-
}
204-
} else {
202+
203+
if (BaseForkTask::wasInterrupted(res.status)) {
204+
testRes.set_status(testsgen::TEST_INTERRUPTED);
205205
if (testTimeout.has_value()) {
206206
*executionTime = google::protobuf::util::TimeUtil::SecondsToDuration(testTimeout.value().count());
207207
} else {
208-
LOG_S(WARNING) << "Google test results are not generated, timeout not found";
208+
LOG_S(WARNING) << StringUtils::stringFormat("Test %s:%s execution was interrupted without timeout set",
209+
fs::relative(command.unitTest.testFilePath,
210+
projectContext.projectPath),
211+
command.unitTest.testname);
209212
}
213+
testRes.set_allocated_executiontime(executionTime);
214+
return testRes;
210215
}
211216

212-
testsgen::TestResultObject testRes;
213-
testRes.set_testfilepath(command.unitTest.testFilePath);
214-
testRes.set_testname(command.unitTest.testname);
215-
testRes.set_allocated_executiontime(executionTime);
216-
if (StringUtils::contains(res.output, "[ PASSED ] 1 test")) {
217-
testRes.set_status(testsgen::TEST_PASSED);
217+
if (!fs::exists(Paths::getGTestResultsJsonPath(projectContext))) {
218+
testRes.set_status(testsgen::TEST_DEATH);
218219
return testRes;
219220
}
220-
if (StringUtils::contains(res.output, "[ FAILED ] 1 test")) {
221-
testRes.set_status(testsgen::TEST_FAILED);
222-
return testRes;
221+
222+
nlohmann::json gtestResultsJson = JsonUtils::getJsonFromFile(Paths::getGTestResultsJsonPath(projectContext));
223+
if (!google::protobuf::util::TimeUtil::FromString(gtestResultsJson["time"], executionTime)) {
224+
LOG_S(WARNING) << "Cannot parse duration of test execution";
223225
}
224-
if (BaseForkTask::wasInterrupted(res.status)) {
225-
testRes.set_status(testsgen::TEST_INTERRUPTED);
226-
return testRes;
226+
testRes.set_allocated_executiontime(executionTime);
227+
if (gtestResultsJson["failures"] != 0) {
228+
testRes.set_status(testsgen::TEST_FAILED);
229+
} else {
230+
testRes.set_status(testsgen::TEST_PASSED);
227231
}
228-
testRes.set_status(testsgen::TEST_DEATH);
232+
fs::remove(Paths::getGTestResultsJsonPath(projectContext));
229233
return testRes;
230234
}
231235

server/src/printers/CoverageAndResultsStatisticsPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ namespace printer {
4949
insert({sourcePath, FileCoverageAndResultsStatistics(testsResult, fileCoverage)});
5050
}
5151
std::vector<std::string> metricNames = {
52-
"filename", "executionTime (s)",
53-
"totalTestsNumber", "passedTestsNumber", "failedTestsNumber", "deathTestsNumber",
54-
"interruptedTestsNumber",
55-
"totalLinesNumber", "coveredLinesNumber", "lineCoverageRatio (%)"
52+
"Filename", "Google Test Execution Time (s)",
53+
"Total Tests Number", "Passed Tests Number", "Failed Tests Number", "Death Tests Number",
54+
"Interrupted Tests Number",
55+
"Total Lines Number", "Covered Lines Number", "Line Coverage Ratio (%)"
5656
};
5757
std::string header = StringUtils::joinWith(metricNames, ",");
5858
std::stringstream ss;

server/src/printers/CoverageAndResultsStatisticsPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ namespace printer {
4545
};
4646
}
4747

48-
#endif //UNITTESTBOT_COVERAGEANDRESULTSSTATISTICSPRINTER_H
48+
#endif //UNITTESTBOT_COVERAGEANDRESULTSSTATISTICSPRINTER_H

0 commit comments

Comments
 (0)