• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-adc / 56

31 Jul 2026 10:38AM UTC coverage: 56.281% (-1.1%) from 57.332%
56

push

github

web-flow
Use exported vars instead of MAKEFLAGS for coverage options (#51)

282 of 466 branches covered (60.52%)

457 of 812 relevant lines covered (56.28%)

4.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.18
/src/file_utils.cpp
1
#include "file_utils.h"
2
#include <filesystem>
3
#include <set>
4

5
TNoDirError::TNoDirError(const std::string& msg): std::runtime_error(msg)
7✔
6
{}
7✔
7

8
bool TryOpen(const std::vector<std::string>& fnames, std::ifstream& file)
4✔
9
{
10
    for (auto& fname: fnames) {
12✔
11
        file.open(fname);
10✔
12
        if (file.is_open()) {
10✔
13
            return true;
2✔
14
        }
15
        file.clear();
8✔
16
    }
17
    return false;
2✔
18
}
19

20
void WriteToFile(const std::string& fileName, const std::string& value)
×
21
{
22
    std::ofstream f;
×
23
    OpenWithException(f, fileName);
×
24
    f << value;
×
25
}
×
26

27
void IterateDir(const std::string& dirName, std::function<bool(const std::string&)> fn)
23✔
28
{
29
    try {
30
        const std::filesystem::path dirPath{dirName};
23✔
31
        std::set<std::filesystem::path> sortedByPath;
23✔
32

33
        for (auto& entry: std::filesystem::directory_iterator(dirPath))
59✔
34
            sortedByPath.insert(entry.path());
52✔
35

36
        for (auto& filePath: sortedByPath) {
46✔
37
            const auto filenameStr = filePath.filename().string();
32✔
38
            if (fn(filenameStr)) {
32✔
39
                return;
2✔
40
            }
41
        }
32✔
42
    } catch (std::filesystem::filesystem_error const& ex) {
39✔
43
        throw TNoDirError(ex.what());
21✔
44
    }
7✔
45
}
46

47
std::string IterateDirByPattern(const std::string& dirName,
23✔
48
                                const std::string& pattern,
49
                                std::function<bool(const std::string&)> fn)
50
{
51
    std::string res;
23✔
52
    IterateDir(dirName, [&](const auto& name) {
30✔
53
        if (name.find(pattern) != std::string::npos) {
32✔
54
            std::string d(dirName + "/" + name);
16✔
55
            if (fn(d)) {
16✔
56
                res = d;
2✔
57
                return true;
2✔
58
            }
59
        }
16✔
60
        return false;
30✔
61
    });
62
    return res;
16✔
63
}
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc