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

wirenboard / wb-mqtt-gpio / 93

31 Jul 2026 10:43AM UTC coverage: 44.281% (+4.5%) from 39.772%
93

push

github

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

493 of 1086 branches covered (45.4%)

875 of 1976 relevant lines covered (44.28%)

3.96 hits per line

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

61.54
/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)
12✔
6
{}
12✔
7

8
bool TryOpen(const std::vector<std::string>& fnames, std::ifstream& file)
×
9
{
10
    for (auto& fname: fnames) {
×
11
        file.open(fname);
×
12
        if (file.is_open()) {
×
13
            return true;
×
14
        }
15
        file.clear();
×
16
    }
17
    return false;
×
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)
14✔
28
{
29
    try {
30
        const std::filesystem::path dirPath{dirName};
14✔
31
        std::set<std::filesystem::path> sortedByPath;
14✔
32

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

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

47
std::string IterateDirByPattern(const std::string& dirName,
14✔
48
                                const std::string& pattern,
49
                                std::function<bool(const std::string&)> fn)
50
{
51
    std::string res;
14✔
52
    IterateDir(dirName, [&](const auto& name) {
26✔
53
        if (name.find(pattern) != std::string::npos) {
2✔
54
            std::string d(dirName + "/" + name);
2✔
55
            if (fn(d)) {
2✔
56
                res = d;
×
57
                return true;
×
58
            }
59
        }
2✔
60
        return false;
2✔
61
    });
62
    return res;
2✔
63
}
12✔
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