37#include <boost/algorithm/string.hpp>
38#include <boost/core/ignore_unused.hpp>
39#include <boost/regex.hpp>
43using namespace boost::filesystem;
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 = boost::filesystem::current_path();
94 boost::regex r(it->first.c_str());
98 for (
auto &e : boost::make_iterator_range(directory_iterator(pwd), {}))
100 boost::cmatch matches;
101 if (boost::regex_match(e.path().string().c_str(), matches, r))
103 if (matches.size() == 1)
111 if (it->second != cnt)
113 std::cerr <<
"Failed test." << std::endl;
114 std::cerr <<
" Expected file matches: " << it->second << std::endl;
115 std::cerr <<
" Found file matches: " << cnt << std::endl;
125 boost::ignore_unused(pStdout, pStderr);
128 auto pwd = boost::filesystem::current_path();
133 boost::regex r(it->first.c_str());
134 for (
auto &e : boost::make_iterator_range(directory_iterator(pwd), {}))
136 boost::cmatch matches;
137 if (boost::regex_match(e.path().string().c_str(), matches, r))
139 if (matches.size() == 1)
149 TiXmlElement *file =
m_metric->FirstChildElement(
"file");
152 std::string pattern = file->Attribute(
"pattern");
157 " in list of calculated"
161 new TiXmlText(std::to_string(
m_fileCounts[pattern]).c_str()));
162 file = file->NextSiblingElement(
"file");
#define ASSERTL0(condition, msg)
std::string RegisterCreatorFunction(std::string key, CreatorFunction func)
std::map< std::string, int > m_fileCounts
static MetricSharedPtr create(TiXmlElement *metric, bool generate)
virtual bool v_Test(std::istream &pStdout, std::istream &pStderr)
Virtual function to test the metric. Should be redefined in derived classes.
MetricFileExists(TiXmlElement *metric, bool generate)
virtual void v_Generate(std::istream &pStdout, std::istream &pStderr)
Virtual function to generate 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.
The above copyright notice and this permission notice shall be included.
MetricFactory & GetMetricFactory()