Commit 2c8b5f47 authored by Davis King's avatar Davis King

Fixed a bug in the DLIB_TEST_MSG macro for the unit testing suite. This

bug was introduced a few days ago.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404284
parent 7ebc1f96
...@@ -27,36 +27,21 @@ namespace test ...@@ -27,36 +27,21 @@ namespace test
return test_count; return test_count;
} }
// ----------------------------------------------------------------------------- void increment_test_count (
void check_test (
bool _exp,
long line,
const char* file,
const char* _exp_str
) )
{ {
test_count_mutex.lock(); test_count_mutex.lock();
++test_count; ++test_count;
test_count_mutex.unlock(); test_count_mutex.unlock();
if ( !(_exp) ) }
{
std::ostringstream dlib__out;
dlib__out << "\n\nError occurred at line " << line << ".\n";
dlib__out << "Error occurred in file " << file << ".\n";
dlib__out << "Failing expression was " << _exp_str << ".\n";
throw dlib::error(dlib__out.str());
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void check_test_msg ( void check_test (
bool _exp, bool _exp,
long line, long line,
const char* file, const char* file,
const char* _exp_str, const char* _exp_str
const char* _msg
) )
{ {
test_count_mutex.lock(); test_count_mutex.lock();
...@@ -68,7 +53,6 @@ namespace test ...@@ -68,7 +53,6 @@ namespace test
dlib__out << "\n\nError occurred at line " << line << ".\n"; dlib__out << "\n\nError occurred at line " << line << ".\n";
dlib__out << "Error occurred in file " << file << ".\n"; dlib__out << "Error occurred in file " << file << ".\n";
dlib__out << "Failing expression was " << _exp_str << ".\n"; dlib__out << "Failing expression was " << _exp_str << ".\n";
dlib__out << _msg << "\n";
throw dlib::error(dlib__out.str()); throw dlib::error(dlib__out.str());
} }
} }
......
...@@ -18,7 +18,17 @@ ...@@ -18,7 +18,17 @@
#define DLIB_TEST(_exp) check_test(_exp, __LINE__, __FILE__, #_exp); #define DLIB_TEST(_exp) check_test(_exp, __LINE__, __FILE__, #_exp);
#define DLIB_TEST_MSG(_exp,_message) check_test_msg(_exp, __LINE__, __FILE__, #_exp, #_message);
#define DLIB_TEST_MSG(_exp,_message) \
{increment_test_count(); if ( !(_exp) ) \
{ \
std::ostringstream dlib__out; \
dlib__out << "\n\nError occurred at line " << __LINE__ << ".\n"; \
dlib__out << "Error occurred in file " << __FILE__ << ".\n"; \
dlib__out << "Failing expression was " << #_exp << ".\n"; \
dlib__out << _message << "\n"; \
throw dlib::error(dlib__out.str()); \
}}
namespace test namespace test
{ {
...@@ -37,14 +47,6 @@ namespace test ...@@ -37,14 +47,6 @@ namespace test
const char* _exp_str const char* _exp_str
); );
void check_test_msg (
bool _exp,
long line,
const char* file,
const char* _exp_str,
const char* _msg
);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// This bool controls any cout statements in this program. Only print to // This bool controls any cout statements in this program. Only print to
...@@ -61,6 +63,13 @@ namespace test ...@@ -61,6 +63,13 @@ namespace test
statements executed since program startup. statements executed since program startup.
!*/ !*/
void increment_test_count (
);
/*!
ensures
- increments number_of_testing_statements_executed()
!*/
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void print_spinner ( void print_spinner (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment