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

Move makeGcovJsonGz() to TestUtils unit and rename
makeGz() is a better name actually.
Author: xaizek
Author date (UTC): 2021-06-06 16:25
Committer name: xaizek
Committer date (UTC): 2021-06-06 16:25
Parent(s): 1470230c9e749a5ca4b3f684d8a378858b981e8d
Signing key: 99DC5E4DB05F6BE2
Tree: f9458439bb3cfce3e42f925e56b870222ca0aa71
File Lines added Lines deleted
tests/TestUtils.cpp 17 0
tests/TestUtils.hpp 8 0
tests/sub_commands.cpp 2 19
File tests/TestUtils.cpp changed (mode: 100644) (index 23ac1e6..c7b7032)
17 17 #include "TestUtils.hpp" #include "TestUtils.hpp"
18 18
19 19 #include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
20 #include <boost/iostreams/filter/gzip.hpp>
21 #include <boost/iostreams/filtering_streambuf.hpp>
20 22 #include <boost/range.hpp> #include <boost/range.hpp>
21 23
24 #include <fstream>
25 #include <ostream>
26
22 27 #include "Settings.hpp" #include "Settings.hpp"
23 28
24 29 namespace fs = boost::filesystem; namespace fs = boost::filesystem;
 
... ... getSettings()
78 83 static TestSettings settings; static TestSettings settings;
79 84 return settings; return settings;
80 85 } }
86
87 void
88 makeGz(const std::string &path, const std::string &contents)
89 {
90 std::ofstream file(path, std::ios_base::out | std::ios_base::binary);
91
92 boost::iostreams::filtering_ostreambuf out;
93 out.push(boost::iostreams::gzip_compressor());
94 out.push(file);
95
96 std::basic_ostream<char>(&out) << contents;
97 }
File tests/TestUtils.hpp changed (mode: 100644) (index de266f0..9c2e677)
... ... vi(std::vector<int> v)
142 142 */ */
143 143 Settings & getSettings(); Settings & getSettings();
144 144
145 /**
146 * @brief Creates a compressed file in gzip format.
147 *
148 * @param path Path of the file.
149 * @param contents Contents of the file.
150 */
151 void makeGz(const std::string &path, const std::string &contents);
152
145 153 #endif // UNCOV__TESTS__TESTUTILS_HPP__ #endif // UNCOV__TESTS__TESTUTILS_HPP__
File tests/sub_commands.cpp changed (mode: 100644) (index 0727a8b..04b0165)
18 18
19 19 #include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
20 20 #include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
21 #include <boost/iostreams/filter/gzip.hpp>
22 #include <boost/iostreams/filtering_streambuf.hpp>
23 21 #include <boost/optional.hpp> #include <boost/optional.hpp>
24 22 #include <boost/scope_exit.hpp> #include <boost/scope_exit.hpp>
25 23
 
27 25
28 26 #include <fstream> #include <fstream>
29 27 #include <iostream> #include <iostream>
30 #include <ostream>
31 28 #include <stdexcept> #include <stdexcept>
32 29 #include <string> #include <string>
33 30
 
... ... private:
104 101 }; };
105 102
106 103 static SubCommand * getCmd(const std::string &name); static SubCommand * getCmd(const std::string &name);
107 static void makeGcovJsonGz(const std::string &path,
108 const std::string &contents);
109 104
110 105 const std::string build3info = const std::string build3info =
111 106 R"(Id: #3 R"(Id: #3
 
... ... TEST_CASE("Gcov file is found and parsed",
1225 1220 const std::string &dir) { const std::string &dir) {
1226 1221 GcovInfo gcovInfo; GcovInfo gcovInfo;
1227 1222 if (gcovInfo.hasJsonFormat()) { if (gcovInfo.hasJsonFormat()) {
1228 makeGcovJsonGz(dir + "/test-file1.gcno.gcov.json.gz", R"({
1223 makeGz(dir + "/test-file1.gcno.gcov.json.gz", R"({
1229 1224 "files": [{ "files": [{
1230 1225 "file": "test-file1.cpp", "file": "test-file1.cpp",
1231 1226 "lines": [ "lines": [
 
... ... TEST_CASE("Gcov file with broken format causes an exception",
1267 1262 const std::string &dir) { const std::string &dir) {
1268 1263 GcovInfo gcovInfo; GcovInfo gcovInfo;
1269 1264 if (gcovInfo.hasJsonFormat()) { if (gcovInfo.hasJsonFormat()) {
1270 makeGcovJsonGz(dir + "/test-file1.gcno.gcov.json.gz", R"({
1265 makeGz(dir + "/test-file1.gcno.gcov.json.gz", R"({
1271 1266 "files": [{ "files": [{
1272 1267 "file": "test-file1.cpp", "file": "test-file1.cpp",
1273 1268 "lines": [ { "line_number": 2, "count": 0 }, ] "lines": [ { "line_number": 2, "count": 0 }, ]
 
... ... getCmd(const std::string &name)
1599 1594 } }
1600 1595 throw std::invalid_argument("No such command: " + name); throw std::invalid_argument("No such command: " + name);
1601 1596 } }
1602
1603 static void
1604 makeGcovJsonGz(const std::string &path, const std::string &contents)
1605 {
1606 std::ofstream file(path, std::ios_base::out | std::ios_base::binary);
1607
1608 boost::iostreams::filtering_ostreambuf out;
1609 out.push(boost::iostreams::gzip_compressor());
1610 out.push(file);
1611
1612 std::basic_ostream<char>(&out) << contents;
1613 }
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