mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 11:27:15 +02:00
Move test state + functions into single class
This commit is contained in:
@ -16,7 +16,7 @@
|
|||||||
BOOST_PP_CAT(x, _type) \
|
BOOST_PP_CAT(x, _type) \
|
||||||
() : ::test::registered_test_base(BOOST_PP_STRINGIZE(x)) \
|
() : ::test::registered_test_base(BOOST_PP_STRINGIZE(x)) \
|
||||||
{ \
|
{ \
|
||||||
::test::test_list::add_test(this); \
|
::test::get_state().add_test(this); \
|
||||||
} \
|
} \
|
||||||
void run(); \
|
void run(); \
|
||||||
}; \
|
}; \
|
||||||
@ -27,7 +27,7 @@
|
|||||||
int main(int, char**) \
|
int main(int, char**) \
|
||||||
{ \
|
{ \
|
||||||
BOOST_UNORDERED_TEST_COMPILER_INFO() \
|
BOOST_UNORDERED_TEST_COMPILER_INFO() \
|
||||||
::test::test_list::run_tests(); \
|
::test::get_state().run_tests(); \
|
||||||
return boost::report_errors(); \
|
return boost::report_errors(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,43 +35,18 @@
|
|||||||
int main(int, char**) \
|
int main(int, char**) \
|
||||||
{ \
|
{ \
|
||||||
BOOST_UNORDERED_TEST_COMPILER_INFO() \
|
BOOST_UNORDERED_TEST_COMPILER_INFO() \
|
||||||
::test::test_list::run_tests(true); \
|
::test::get_state().run_tests(true); \
|
||||||
return boost::report_errors(); \
|
return boost::report_errors(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNORDERED_SUB_TEST(x) \
|
#define UNORDERED_SUB_TEST(x) \
|
||||||
for (int UNORDERED_SUB_TEST_VALUE = ::test::start_sub_test(x); \
|
for (int UNORDERED_SUB_TEST_VALUE = ::test::get_state().start_sub_test(x); \
|
||||||
UNORDERED_SUB_TEST_VALUE; \
|
UNORDERED_SUB_TEST_VALUE; \
|
||||||
UNORDERED_SUB_TEST_VALUE = \
|
UNORDERED_SUB_TEST_VALUE = \
|
||||||
::test::end_sub_test(x, UNORDERED_SUB_TEST_VALUE))
|
::test::get_state().end_sub_test(x, UNORDERED_SUB_TEST_VALUE))
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
static inline bool& is_quiet()
|
|
||||||
{
|
|
||||||
static bool value = false;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int start_sub_test(char const* name)
|
|
||||||
{
|
|
||||||
if (!is_quiet()) {
|
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Sub-test: " << name << "\n"
|
|
||||||
<< std::flush;
|
|
||||||
}
|
|
||||||
// Add one because it's used as a loop condition.
|
|
||||||
return boost::detail::test_errors() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int end_sub_test(char const* name, int value)
|
|
||||||
{
|
|
||||||
if (is_quiet() && value != boost::detail::test_errors() + 1) {
|
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Error in sub-test: " << name << "\n"
|
|
||||||
<< std::flush;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct registered_test_base
|
struct registered_test_base
|
||||||
{
|
{
|
||||||
registered_test_base* next;
|
registered_test_base* next;
|
||||||
@ -81,48 +56,70 @@ struct registered_test_base
|
|||||||
virtual ~registered_test_base() {}
|
virtual ~registered_test_base() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace test_list {
|
struct state
|
||||||
static inline registered_test_base*& first()
|
|
||||||
{
|
{
|
||||||
static registered_test_base* ptr = 0;
|
bool is_quiet;
|
||||||
return ptr;
|
registered_test_base* first_test;
|
||||||
}
|
registered_test_base* last_test;
|
||||||
|
|
||||||
static inline registered_test_base*& last()
|
state() : is_quiet(false), first_test(0), last_test(0) {}
|
||||||
{
|
|
||||||
static registered_test_base* ptr = 0;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void add_test(registered_test_base* test)
|
void add_test(registered_test_base* test)
|
||||||
{
|
{
|
||||||
if (last()) {
|
if (last_test) {
|
||||||
last()->next = test;
|
last_test->next = test;
|
||||||
} else {
|
} else {
|
||||||
first() = test;
|
first_test = test;
|
||||||
|
}
|
||||||
|
last_test = test;
|
||||||
}
|
}
|
||||||
|
|
||||||
last() = test;
|
void run_tests(bool quiet = false)
|
||||||
}
|
{
|
||||||
|
is_quiet = quiet;
|
||||||
|
|
||||||
static inline void run_tests(bool quiet = false)
|
for (registered_test_base* i = first_test; i; i = i->next) {
|
||||||
{
|
int error_count = boost::detail::test_errors();
|
||||||
test::is_quiet() = quiet;
|
if (!quiet) {
|
||||||
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Running " << i->name << "\n"
|
||||||
for (registered_test_base* i = first(); i; i = i->next) {
|
<< std::flush;
|
||||||
int error_count = boost::detail::test_errors();
|
}
|
||||||
if (!quiet) {
|
i->run();
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Running " << i->name << "\n"
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << std::flush;
|
||||||
<< std::flush;
|
if (quiet && error_count != boost::detail::test_errors()) {
|
||||||
}
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Error in: " << i->name
|
||||||
i->run();
|
<< "\n"
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM << std::flush;
|
<< std::flush;
|
||||||
if (quiet && error_count != boost::detail::test_errors()) {
|
}
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Error in: " << i->name << "\n"
|
|
||||||
<< std::flush;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
int start_sub_test(char const* name)
|
||||||
|
{
|
||||||
|
if (!is_quiet) {
|
||||||
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Sub-test: " << name << "\n"
|
||||||
|
<< std::flush;
|
||||||
|
}
|
||||||
|
// Add one because it's used as a loop condition.
|
||||||
|
return boost::detail::test_errors() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int end_sub_test(char const* name, int value)
|
||||||
|
{
|
||||||
|
if (is_quiet && value != boost::detail::test_errors() + 1) {
|
||||||
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Error in sub-test: " << name
|
||||||
|
<< "\n"
|
||||||
|
<< std::flush;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the currnet translation unit's test state.
|
||||||
|
static inline state& get_state()
|
||||||
|
{
|
||||||
|
static state instance;
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user