35 #include <boost/filesystem/detail/utf8_codecvt_facet.hpp> 55 std::ostringstream oss;
56 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: " << expression;
60 inline std::string
unit_assert_equal_message(
const char* filename,
int line,
const std::string&
x,
const std::string&
y,
const char* expression)
62 std::ostringstream oss;
63 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: expected \"" << x <<
"\" but got \"" << y <<
"\" (" << expression <<
")";
69 std::ostringstream oss;
71 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: |" << x <<
" - " << y <<
"| < " <<
epsilon;
77 std::ostringstream oss;
78 oss <<
"[" << filename <<
":" << line <<
"] Assertion \"" << expression <<
"\" failed to throw " << exception;
82 inline std::string
quote_string(
const string& str) {
return "\"" + str +
"\"";}
85 #define unit_assert(x) \ 86 (!(x) ? throw std::runtime_error(unit_assert_message(__FILE__, __LINE__, #x)) : 0) 88 #define unit_assert_to_stream(x, os) \ 89 ((os) << (!(x) ? unit_assert_message(__FILE__, __LINE__, #x) + "\n" : "")) 92 #define unit_assert_operator_equal(expected, actual) \ 93 (!((expected) == (actual)) ? throw std::runtime_error(unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual)) : 0) 95 #define unit_assert_operator_equal_to_stream(expected, actual, os) \ 96 ((os) << (!((expected) == (actual)) ? unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual) + "\n" : "")) 99 #define unit_assert_equal(x, y, epsilon) \ 100 (!(fabs((x)-(y)) <= (epsilon)) ? throw std::runtime_error(unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon))) : 0) 102 #define unit_assert_equal_to_stream(x, y, epsilon, os) \ 103 ((os) << (!(fabs((x)-(y)) <= (epsilon)) ? unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon)) + "\n" : "")) 106 #define unit_assert_throws(x, exception) \ 108 bool threw = false; \ 115 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, #exception)); \ 119 #define unit_assert_throws_what(x, exception, whatStr) \ 121 bool threw = false; \ 123 catch (exception& e) \ 125 if (e.what() == std::string(whatStr)) \ 128 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr)+"\nBut a different exception was thrown: ")+quote_string(e.what())); \ 131 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr))); \ 135 #define unit_assert_matrices_equal(A, B, epsilon) \ 136 unit_assert(boost::numeric::ublas::norm_frobenius((A)-(B)) < (epsilon)) 139 #define unit_assert_vectors_equal(A, B, epsilon) \ 140 unit_assert(boost::numeric::ublas::norm_2((A)-(B)) < (epsilon)) 148 bal::replace_all(result,
"'",
"|'");
149 bal::replace_all(result,
"\n",
"|n");
150 bal::replace_all(result,
"\r",
"|r");
151 bal::replace_all(result,
"|",
"||");
152 bal::replace_all(result,
"[",
"|[");
153 bal::replace_all(result,
"]",
"|]");
157 #define TEST_PROLOG_EX(argc, argv, suffix) \ 158 bnw::args args(argc, argv); \ 159 std::locale global_loc = std::locale(); \ 160 std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); \ 161 bfs::path::imbue(loc); \ 162 bfs::path testName = bfs::change_extension(bfs::basename(argv[0]), (suffix)); \ 163 string teamcityTestName = pwiz::util::escape_teamcity_string(testName.string()); \ 164 bpt::ptime testStartTime; \ 165 vector<string> testArgs(argv, argv+argc); \ 166 bool teamcityTestDecoration = find(testArgs.begin(), testArgs.end(), "--teamcity-test-decoration") != testArgs.end(); \ 167 if (teamcityTestDecoration) \ 169 testStartTime = bpt::microsec_clock::local_time(); \ 170 cout << "##teamcity[testStarted name='" << teamcityTestName << "']" << endl; \ 172 int testExitStatus = 0; 175 #define TEST_PROLOG(argc, argv) TEST_PROLOG_EX(argc, argv, "") 177 #define TEST_FAILED(x) \ 178 if (teamcityTestDecoration) \ 179 cout << "##teamcity[testFailed name='" << teamcityTestName << "' message='" << pwiz::util::escape_teamcity_string((x)) << "']\n"; \ 180 cerr << (x) << endl; \ 183 #define TEST_EPILOG \ 184 if (teamcityTestDecoration) \ 185 cout << "##teamcity[testFinished name='" << teamcityTestName << \ 186 "' duration='" << round((bpt::microsec_clock::local_time() - testStartTime).total_microseconds() / 1000.0) << "']" << endl; \ 187 return testExitStatus; 195 #if !defined(PWIZ_DOCTEST) && !defined(PWIZ_DOCTEST_NO_MAIN) 196 #ifndef __cplusplus_cli 197 #define DOCTEST_CONFIG_DISABLE 198 #include "libraries/doctest.h" 201 #define DOCTEST_CONFIG_IMPLEMENT 202 #include "libraries/doctest.h" 204 #ifndef PWIZ_DOCTEST_NO_MAIN 205 int main(
int argc,
char* argv[])
211 doctest::Context context;
212 testExitStatus = context.run();
229 template <
typename T>
230 vector<doctest::Approx> operator~(
const vector<T>& lhs)
232 vector<doctest::Approx> result(lhs.size(), doctest::Approx(0));
233 for (
size_t i = 0; i < lhs.size(); ++i)
234 result[i] = doctest::Approx(lhs[i]);
238 inline ostream&
operator<< (ostream& o,
const doctest::Approx& rhs)
244 template <
typename T>
245 bool operator==(
const vector<T>& lhs,
const vector<doctest::Approx>& rhs)
247 if (doctest::isRunningInTest())
248 REQUIRE(lhs.size() == rhs.size());
249 else if (lhs.size() != rhs.size())
252 for (
size_t i = 0; i < lhs.size(); ++i)
253 if (lhs[i] != rhs[i])
return false;
257 template <
typename T>
258 bool operator==(
const vector<doctest::Approx>& rhs,
const vector<T>& lhs)
std::string escape_teamcity_string(const std::string &str)
std::string unit_assert_numeric_equal_message(const char *filename, int line, double x, double y, double epsilon)
int main(int argc, char *argv[])
std::string quote_string(const string &str)
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, const PeakDetectorMatchedFilter::Score &a)
std::string unit_assert_message(const char *filename, int line, const char *expression)
std::string unit_assert_exception_message(const char *filename, int line, const char *expression, const std::string &exception)
std::string unit_assert_equal_message(const char *filename, int line, const std::string &x, const std::string &y, const char *expression)
PWIZ_API_DECL bool operator==(const TruncatedLorentzianParameters &t, const TruncatedLorentzianParameters &u)
#define TEST_PROLOG(argc, argv)
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y