38#include <boost/algorithm/string.hpp>
39#include <boost/core/ignore_unused.hpp>
53 TiXmlElement *file = metric->FirstChildElement(
"file");
54 ASSERTL0(file,
"Missing file tag for FileExists metric!");
59 std::string pattern, count;
62 ASSERTL0(file->Attribute(
"pattern"),
"Missing filename for file tag!");
63 pattern = file->Attribute(
"pattern");
69 count = file->GetText();
79 file = file->NextSiblingElement(
"file");
85 boost::ignore_unused(pStdout, pStderr);
88 auto pwd = fs::current_path();
94 std::regex r(it->first.c_str());
98 for (
auto &e : fs::directory_iterator(pwd))
101 std::string filename = e.path().string();
102 if (std::regex_match(filename, matches, r))
104 if (matches.size() == 1)
112 if (it->second != cnt)
114 std::cerr <<
"Failed test." << std::endl;
115 std::cerr <<
" Expected file matches: " << it->second << std::endl;
116 std::cerr <<
" Found file matches: " << cnt << std::endl;
126 boost::ignore_unused(pStdout, pStderr);
129 auto pwd = fs::current_path();
134 std::regex r(it->first.c_str());
135 for (
auto &e : fs::directory_iterator(pwd))
138 std::string filename = e.path().string();
139 if (std::regex_match(filename, matches, r))
141 if (matches.size() == 1)
151 TiXmlElement *file =
m_metric->FirstChildElement(
"file");
154 std::string pattern = file->Attribute(
"pattern");
159 " in list of calculated"
163 new TiXmlText(std::to_string(
m_fileCounts[pattern]).c_str()));
164 file = file->NextSiblingElement(
"file");
#define ASSERTL0(condition, msg)
std::string RegisterCreatorFunction(std::string key, CreatorFunction func)
std::map< std::string, int > m_fileCounts
void v_Generate(std::istream &pStdout, std::istream &pStderr) override
Virtual function to generate the metric. Should be redefined in derived classes.
static MetricSharedPtr create(TiXmlElement *metric, bool generate)
MetricFileExists(TiXmlElement *metric, bool generate)
bool v_Test(std::istream &pStdout, std::istream &pStderr) override
Virtual function to test the metric. Should be redefined in derived classes.
Base class for all metrics. Metric represents a test metric that can be used to evaluate the function...
TiXmlElement * m_metric
Pointer to XML structure containing metric definition.
bool m_generate
Determines whether to generate this metric or not.
MetricFactory & GetMetricFactory()