Skip to content

Commit c1af6e2

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

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-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: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ grpc::Status TestRunner::runTests(bool withCoverage, const std::optional<std::ch
130130
MEASURE_FUNCTION_EXECUTION_TIME
131131
ExecUtils::throwIfCancelled();
132132

133+
fs::remove(Paths::getGTestResultsJsonPath(projectContext));
133134
const auto buildRunCommands = coverageTool->getBuildRunCommands(testsToLaunch, withCoverage);
134135
ExecUtils::doWorkWithProgress(buildRunCommands, progressWriter, "Running tests",
135136
[this, testTimeout] (BuildRunCommand const &buildRunCommand) {
@@ -195,37 +196,41 @@ testsgen::TestResultObject TestRunner::runTest(const BuildRunCommand &command, c
195196
auto res = command.runCommand.run(projectContext.buildDir, true, true, testTimeout);
196197
GTestLogger::log(res.output);
197198

199+
testsgen::TestResultObject testRes;
200+
testRes.set_testfilepath(command.unitTest.testFilePath);
201+
testRes.set_testname(command.unitTest.testname);
198202
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 {
203+
204+
if (BaseForkTask::wasInterrupted(res.status)) {
205+
testRes.set_status(testsgen::TEST_INTERRUPTED);
205206
if (testTimeout.has_value()) {
206207
*executionTime = google::protobuf::util::TimeUtil::SecondsToDuration(testTimeout.value().count());
207208
} else {
208-
LOG_S(WARNING) << "Google test results are not generated, timeout not found";
209+
LOG_S(WARNING) << StringUtils::stringFormat("Test %s:%s execution was interrupted without timeout set",
210+
fs::relative(command.unitTest.testFilePath,
211+
projectContext.projectPath),
212+
command.unitTest.testname);
209213
}
214+
testRes.set_allocated_executiontime(executionTime);
215+
return testRes;
210216
}
211217

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);
218+
if (!fs::exists(Paths::getGTestResultsJsonPath(projectContext))) {
219+
testRes.set_status(testsgen::TEST_DEATH);
218220
return testRes;
219221
}
220-
if (StringUtils::contains(res.output, "[ FAILED ] 1 test")) {
221-
testRes.set_status(testsgen::TEST_FAILED);
222-
return testRes;
222+
223+
nlohmann::json gtestResultsJson = JsonUtils::getJsonFromFile(Paths::getGTestResultsJsonPath(projectContext));
224+
if (!google::protobuf::util::TimeUtil::FromString(gtestResultsJson["time"], executionTime)) {
225+
LOG_S(WARNING) << "Cannot parse duration of test execution";
223226
}
224-
if (BaseForkTask::wasInterrupted(res.status)) {
225-
testRes.set_status(testsgen::TEST_INTERRUPTED);
226-
return testRes;
227+
testRes.set_allocated_executiontime(executionTime);
228+
if (gtestResultsJson["failures"] != 0) {
229+
testRes.set_status(testsgen::TEST_FAILED);
230+
} else {
231+
testRes.set_status(testsgen::TEST_PASSED);
227232
}
228-
testRes.set_status(testsgen::TEST_DEATH);
233+
fs::remove(Paths::getGTestResultsJsonPath(projectContext));
229234
return testRes;
230235
}
231236

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)