diff --git a/.travis.yml b/.travis.yml index 7c4b84ce..06b93822 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: cpp compiler: - gcc +before_install: + - sudo apt-get install libboost-regex1.48-dev +env: + - CXXFLAGS='-D USE_BOOST_REGEX' LDFLAGS='-lboost_regex' install: script/configure.sh script: script/test.sh diff --git a/spec/runtime/helpers/read_test_entries.cc b/spec/runtime/helpers/read_test_entries.cc index d5c0301b..663ebfd9 100644 --- a/spec/runtime/helpers/read_test_entries.cc +++ b/spec/runtime/helpers/read_test_entries.cc @@ -2,36 +2,52 @@ #include #include #include -#include #include +#ifdef USE_BOOST_REGEX + +#include "boost/regex.hpp" +using boost::regex; +using boost::regex_search; +using boost::regex_replace; +using boost::smatch; +using boost::regex_constants::extended; + +#else + +#include +using std::regex; +using std::regex_search; +using std::regex_replace; +using std::smatch; +using std::regex_constants::extended; + +#endif + using std::string; using std::vector; using std::ifstream; using std::istreambuf_iterator; -using std::regex; -using std::regex_search; -using std::regex_replace; static string trim_output(const string &input) { string result(input); - result = regex_replace(result, regex("[\n\t ]+", std::regex_constants::extended), string(" ")); - result = regex_replace(result, regex("^ ", std::regex_constants::extended), string("")); - result = regex_replace(result, regex(" $", std::regex_constants::extended), string("")); - result = regex_replace(result, regex("\\) \\)", std::regex_constants::extended), string("))")); + result = regex_replace(result, regex("[\n\t ]+", extended), string(" ")); + result = regex_replace(result, regex("^ ", extended), string("")); + result = regex_replace(result, regex(" $", extended), string("")); + result = regex_replace(result, regex("\\) \\)", extended), string("))")); return result; } static vector get_test_entries_from_string(string content) { - regex header_pattern("===+\n" "([^=]+)\n" "===+", std::regex_constants::extended); - regex separator_pattern("---+", std::regex_constants::extended); + regex header_pattern("===+\n" "([^=]+)\n" "===+", extended); + regex separator_pattern("---+", extended); vector descriptions; vector bodies; for (;;) { - std::smatch matches; - regex_search(content, matches, header_pattern); - if (matches.empty()) break; + smatch matches; + if (!regex_search(content, matches, header_pattern) || matches.empty()) + break; string description = matches[1].str(); descriptions.push_back(description); @@ -45,13 +61,14 @@ static vector get_test_entries_from_string(string content) { vector result; for (size_t i = 0; i < descriptions.size(); i++) { string body = bodies[i]; - std::smatch matches; - regex_search(body, matches, separator_pattern); - result.push_back({ - descriptions[i], - body.substr(0, matches.position()), - trim_output(body.substr(matches.position() + matches[0].length())) - }); + smatch matches; + if (regex_search(body, matches, separator_pattern)) { + result.push_back({ + descriptions[i], + body.substr(0, matches.position()), + trim_output(body.substr(matches.position() + matches[0].length())) + }); + } } return result;