aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-03-25 18:48:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-03-25 02:00:17 +0000
commitd2c0eb0cc8b6d7a3482778d68599285123e3700b (patch)
tree129e4c1565b44576900a2ba4f8c993bacf19b28e
parent741547fa6af344884f8b0a0ed19301ff4ee112d3 (diff)
downloadpaludis-d2c0eb0cc8b6d7a3482778d68599285123e3700b.tar.gz
paludis-d2c0eb0cc8b6d7a3482778d68599285123e3700b.tar.xz
Make test framework less compiler-hungry
-rw-r--r--test/test_framework.cc29
-rw-r--r--test/test_framework.hh64
2 files changed, 45 insertions, 48 deletions
diff --git a/test/test_framework.cc b/test/test_framework.cc
index 752fb02..a72dee2 100644
--- a/test/test_framework.cc
+++ b/test/test_framework.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -129,9 +129,15 @@ namespace paludis
struct Implementation<TestCase>
{
const std::string name;
+ mutable const char * reached_file;
+ mutable const char * reached_function;
+ mutable long reached_line;
Implementation(const std::string & the_name) :
- name(the_name)
+ name(the_name),
+ reached_file(NULL),
+ reached_function(NULL),
+ reached_line(0)
{
}
};
@@ -157,10 +163,23 @@ TestCase::check(const char * const function, const char * const file,
}
void
+TestCase::reached(const char * const file, const char * const function,
+ const long line) const
+{
+ _imp->reached_file = file;
+ _imp->reached_function = function;
+ _imp->reached_line = line;
+}
+
+void
TestCase::call_run()
{
try
{
+ _imp->reached_file = NULL;
+ _imp->reached_function = NULL;
+ _imp->reached_line = 0;
+
run();
}
catch (TestFailedException)
@@ -169,12 +188,14 @@ TestCase::call_run()
}
catch (std::exception &e)
{
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__,
+ throw TestFailedException(_imp->reached_function ? _imp->reached_file : __PRETTY_FUNCTION__,
+ _imp->reached_file ? _imp->reached_file : __FILE__, _imp->reached_line ? _imp->reached_line : __LINE__,
"Test threw unexpected exception " + (DebugStringHolder::get_instance()->get())(e));
}
catch (...)
{
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__,
+ throw TestFailedException(_imp->reached_function ? _imp->reached_file : __PRETTY_FUNCTION__,
+ _imp->reached_file ? _imp->reached_file : __FILE__, _imp->reached_line ? _imp->reached_line : __LINE__,
"Test threw unexpected unknown exception");
}
}
diff --git a/test/test_framework.hh b/test/test_framework.hh
index e490af7..2af2da7 100644
--- a/test/test_framework.hh
+++ b/test/test_framework.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -73,6 +73,12 @@ namespace test
const long line, bool was_ok, const std::string & message) const;
/**
+ * Indicate that we reached a certain point.
+ */
+ void reached(const char * const function, const char * const file,
+ const long line) const;
+
+ /**
* Run the tests (override this in descendents).
*/
virtual void run() = 0;
@@ -240,21 +246,11 @@ namespace test
*/
#define TEST_CHECK_EQUAL(a, b) \
do { \
- try { \
- test::TwoVarHolder test_h(a, b); \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, test_h.result, \
- "Expected '" #a "' to equal '" + test_h.s_b + \
- "' but got '" + test_h.s_a + "'" + test_h.s_d); \
- } catch (const TestFailedException &) { \
- throw; \
- } catch (const std::exception & test_e) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected exception " + test::get_exception_to_debug_string()(test_e) + \
- " inside a TEST_CHECK_EQUAL block"); \
- } catch (...) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected unknown exception inside a TEST_CHECK_EQUAL block"); \
- } \
+ reached(__PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ test::TwoVarHolder test_h(a, b); \
+ check(__PRETTY_FUNCTION__, __FILE__, __LINE__, test_h.result, \
+ "Expected '" #a "' to equal '" + test_h.s_b + \
+ "' but got '" + test_h.s_a + "'" + test_h.s_d); \
} while (false)
/**
@@ -262,21 +258,11 @@ namespace test
*/
#define TEST_CHECK_STRINGIFY_EQUAL(a, b) \
do { \
- try { \
- test::TwoVarHolder test_h(paludis::stringify(a), paludis::stringify(b)); \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, test_h.result, \
- "Expected 'stringify(" #a ")' = '" + test_h.s_a + "' to equal 'stringify(" #b \
- ")' = '" + test_h.s_b + "'" + test_h.s_d); \
- } catch (const TestFailedException &) { \
- throw; \
- } catch (const std::exception & test_e) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected exception " + test::get_exception_to_debug_string()(test_e) + \
- " inside a TEST_CHECK_STRINGIFY_EQUAL block"); \
- } catch (...) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected unknown exception inside a TEST_CHECK_STRINGIFY_EQUAL block"); \
- } \
+ reached(__PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ test::TwoVarHolder test_h(paludis::stringify(a), paludis::stringify(b)); \
+ check(__PRETTY_FUNCTION__, __FILE__, __LINE__, test_h.result, \
+ "Expected 'stringify(" #a ")' = '" + test_h.s_a + "' to equal 'stringify(" #b \
+ ")' = '" + test_h.s_b + "'" + test_h.s_d); \
} while (false)
/**
@@ -284,19 +270,9 @@ namespace test
*/
#define TEST_CHECK(a) \
do { \
- try { \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, a, \
- "Check '" #a "' failed"); \
- } catch (const TestFailedException &) { \
- throw; \
- } catch (const std::exception & test_e) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected exception " + test::get_exception_to_debug_string()(test_e) + \
- " inside a TEST_CHECK block"); \
- } catch (...) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected unknown exception inside a TEST_CHECK block"); \
- } \
+ reached(__PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ check(__PRETTY_FUNCTION__, __FILE__, __LINE__, a, \
+ "Check '" #a "' failed"); \
} while (false)
/**