xaizek / uncov (License: AGPLv3+) (since 2018-12-07)
Uncov(er) is a tool that collects and processes code coverage reports.
Commit 68397dc05a5ba208fad46a86e987d4ef87116f5d

Extract two methods out of GcovImporter::parseGcov
Author: xaizek
Author date (UTC): 2021-06-05 13:50
Committer name: xaizek
Committer date (UTC): 2021-06-05 13:50
Parent(s): a9dbe113fe6e25fb3a0eafa9eb1933e900ee95ff
Signing key: 99DC5E4DB05F6BE2
Tree: 7ee5defacd557a9b9a55ca646a593abfa6cb4780
File Lines added Lines deleted
src/GcovImporter.cpp 30 22
src/GcovImporter.hpp 18 0
File src/GcovImporter.cpp changed (mode: 100644) (index 1581526..7eb03e3)
... ... GcovImporter::parseGcov(const std::string &path)
274 274 std::string type, value; std::string type, value;
275 275 std::tie(type, value) = splitAt(line, ':'); std::tie(type, value) = splitAt(line, ':');
276 276 if (type == "file") { if (type == "file") {
277 coverage = nullptr;
278
279 fs::path filePath = value;
280 if (!filePath.is_absolute()) {
281 filePath = prefix / filePath;
282 }
283
284 fs::path sourcePath = normalizePath(fs::absolute(filePath,
285 rootDir));
286 if (!pathIsInSubtree(rootDir, sourcePath) ||
287 isExcluded(sourcePath)) {
288 continue;
289 }
290
291 sourcePath = makeRelativePath(rootDir, sourcePath);
292 coverage = &mapping[sourcePath.string()];
277 const std::string sourcePath = resolveSourcePath(value);
278 coverage = (sourcePath.empty() ? nullptr : &mapping[sourcePath]);
293 279 } else if (coverage != nullptr && type == "lcount") { } else if (coverage != nullptr && type == "lcount") {
294 280 std::vector<std::string> fields = split(value, ','); std::vector<std::string> fields = split(value, ',');
295 281 if (fields.size() < 2U) { if (fields.size() < 2U) {
 
... ... GcovImporter::parseGcov(const std::string &path)
299 285
300 286 unsigned int lineNo = std::stoi(fields[0]); unsigned int lineNo = std::stoi(fields[0]);
301 287 int count = std::stoi(fields[1]); int count = std::stoi(fields[1]);
288 updateCoverage(*coverage, lineNo, count);
289 }
290 }
291 }
302 292
303 if (coverage->size() < lineNo) {
304 coverage->resize(lineNo, -1);
305 }
293 std::string
294 GcovImporter::resolveSourcePath(fs::path unresolved)
295 {
296 if (!unresolved.is_absolute()) {
297 unresolved = prefix / unresolved;
298 }
306 299
307 int &entry = (*coverage)[lineNo - 1U];
308 entry = (entry == -1 ? count : entry + count);
309 }
300 fs::path sourcePath = normalizePath(fs::absolute(unresolved,
301 rootDir));
302 if (!pathIsInSubtree(rootDir, sourcePath) || isExcluded(sourcePath)) {
303 return std::string();
304 }
305
306 return makeRelativePath(rootDir, sourcePath).string();
307 }
308
309 void
310 GcovImporter::updateCoverage(std::vector<int> &coverage, unsigned int lineNo,
311 int count)
312 {
313 if (coverage.size() < lineNo) {
314 coverage.resize(lineNo, -1);
310 315 } }
316
317 int &entry = coverage[lineNo - 1U];
318 entry = (entry == -1 ? count : entry + count);
311 319 } }
312 320
313 321 bool bool
File src/GcovImporter.hpp changed (mode: 100644) (index 13a22e7..26b5bdf)
... ... private:
104 104 * @param path Path of the file. * @param path Path of the file.
105 105 */ */
106 106 void parseGcov(const std::string &path); void parseGcov(const std::string &path);
107 /**
108 * @brief Converts path from coverage data into relative form.
109 *
110 * @param unresolved Possibly absolute path.
111 *
112 * @returns Relative path or empty string if it's not in the tree or
113 * excluded.
114 */
115 std::string resolveSourcePath(boost::filesystem::path unresolved);
116 /**
117 * @brief Updates coverage information of single line.
118 *
119 * @param coverage Coverage data.
120 * @param lineNo Line number.
121 * @param count Number of times the line was executed.
122 */
123 void updateCoverage(std::vector<int> &coverage, unsigned int lineNo,
124 int count);
107 125 /** /**
108 126 * @brief Checks whether specified path is excluded. * @brief Checks whether specified path is excluded.
109 127 * *
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/uncov

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/uncov

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master