aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-04 20:30:17 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-04 20:30:17 +0000
commitbda262d789e12fc082b955ed0de4fe2a6607797e (patch)
treef4b91c8b4ca665cb384acc84592a14300f346bbd
parentf0cafc25ec73be105a04069f11375c39b24d897e (diff)
downloadpaludis-bda262d789e12fc082b955ed0de4fe2a6607797e.tar.gz
paludis-bda262d789e12fc082b955ed0de4fe2a6607797e.tar.xz
Tidy up the test extras and reduce compilation times. Use SingletonAsNeeded for Log to avoid initialisation order issues. Don't display Log messages when running tests.
-rw-r--r--paludis/Makefile.am.m47
-rw-r--r--paludis/exception_to_debug_string.cc39
-rw-r--r--paludis/log.hh4
-rw-r--r--paludis/test_extras.cc (renamed from paludis/exception_to_debug_string.hh)42
-rw-r--r--test/test_framework.cc53
-rw-r--r--test/test_framework.hh2
6 files changed, 79 insertions, 68 deletions
diff --git a/paludis/Makefile.am.m4 b/paludis/Makefile.am.m4
index ee9e0b0..0fe6dab 100644
--- a/paludis/Makefile.am.m4
+++ b/paludis/Makefile.am.m4
@@ -7,10 +7,9 @@ define(`filelist', `')dnl
define(`testlist', `')dnl
define(`testscriptlist', `')dnl
define(`addtest', `define(`testlist', testlist `$1_TEST')dnl
-$1_TEST_SOURCES = $1_TEST.cc exception_to_debug_string.cc exception_to_debug_string.hh
-$1_TEST_LDADD = $(top_builddir)/test/libtest.a libpaludis.a
+$1_TEST_SOURCES = $1_TEST.cc
+$1_TEST_LDADD = test_extras.o $(top_builddir)/test/libtest.a libpaludis.a
$1_TEST_CXXFLAGS = -I$(top_srcdir)
-$1_TEST_CPPFLAGS = -DPALUDIS_TEST_CASE=1
')dnl
define(`addtestscript', `define(`testscriptlist', testscriptlist `$1_TEST_setup.sh $1_TEST_cleanup.sh')')dnl
define(`addhh', `define(`filelist', filelist `$1.hh')')dnl
@@ -33,7 +32,7 @@ MAINTAINERCLEANFILES = Makefile.in Makefile.am about.hh paludis.hh smart_record.
AM_CXXFLAGS = -I$(top_srcdir)
DEFS=-DSYSCONFDIR=\"$(sysconfdir)\" -DLIBEXECDIR=\"$(libexecdir)\"
EXTRA_DIST = about.hh.in Makefile.am.m4 paludis.hh.m4 files.m4 smart_record.hh.m4 \
- comparison_policy.hh.m4 hashed_containers.hh.in testscriptlist
+ comparison_policy.hh.m4 hashed_containers.hh.in testscriptlist test_extras.cc
SUBDIRS = . args
libpaludis_a_SOURCES = filelist
diff --git a/paludis/exception_to_debug_string.cc b/paludis/exception_to_debug_string.cc
deleted file mode 100644
index 178e045..0000000
--- a/paludis/exception_to_debug_string.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * 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
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "exception_to_debug_string.hh"
-
-using namespace paludis;
-
-#ifdef PALUDIS_TEST_CASE
-#ifdef PALUDIS_CAN_USE_ATTRIBUTE
-
-std::string exception_to_debug_string(const std::exception & e)
-{
- const paludis::Exception * ee;
- if (0 != ((ee = dynamic_cast<const Exception *>(&e))))
- return stringify(ee->what()) + " (message " + ee->message() +
- (ee->empty() ? stringify("") : ", backtrace " + ee->backtrace(" -> ")) + ")";
- else
- return e.what();
-}
-
-#endif
-#endif
-
diff --git a/paludis/log.hh b/paludis/log.hh
index 30a9dd4..b3f2e2d 100644
--- a/paludis/log.hh
+++ b/paludis/log.hh
@@ -43,10 +43,10 @@ namespace paludis
};
class Log :
- public InstantiationPolicy<Log, instantiation_method::SingletonAtStartupTag>,
+ public InstantiationPolicy<Log, instantiation_method::SingletonAsNeededTag>,
private PrivateImplementationPattern<Log>
{
- friend class InstantiationPolicy<Log, instantiation_method::SingletonAtStartupTag>;
+ friend class InstantiationPolicy<Log, instantiation_method::SingletonAsNeededTag>;
private:
Log();
diff --git a/paludis/exception_to_debug_string.hh b/paludis/test_extras.cc
index cfae673..9332fe6 100644
--- a/paludis/exception_to_debug_string.hh
+++ b/paludis/test_extras.cc
@@ -17,22 +17,42 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_EXCEPTION_TO_DEBUG_STRING_HH
-#define PALUDIS_GUARD_PALUDIS_EXCEPTION_TO_DEBUG_STRING_HH 1
-
+#include <test/test_framework.hh>
#include <paludis/stringify.hh>
#include <paludis/exception.hh>
#include <paludis/attributes.hh>
+#include <paludis/log.hh>
#include <exception>
+#include <sstream>
+
+using namespace paludis;
+
+namespace
+{
+ std::string verbose_exception_to_debug_string(
+ const std::exception & e) PALUDIS_ATTRIBUTE((noinline));
+
+ struct C
+ {
+ std::stringstream s;
-#ifdef PALUDIS_TEST_CASE
-#ifdef PALUDIS_CAN_USE_ATTRIBUTE
+ C()
+ {
+ test::set_exception_to_debug_string(&verbose_exception_to_debug_string);
+ Log::get_instance()->set_log_stream(&s);
+ }
+ };
-std::string exception_to_debug_string(const std::exception & e) PALUDIS_ATTRIBUTE((noinline));
+ static const C my_c;
-#endif
-#else
-#error Missing -DPALUDIS_TEST_CASE=1?
-#endif
+ std::string verbose_exception_to_debug_string(const std::exception & e)
+ {
+ const paludis::Exception * ee;
+ if (0 != ((ee = dynamic_cast<const Exception *>(&e))))
+ return stringify(ee->what()) + " (message " + ee->message() +
+ (ee->empty() ? stringify("") : ", backtrace " + ee->backtrace(" -> ")) + ")";
+ else
+ return e.what();
+ }
+}
-#endif
diff --git a/test/test_framework.cc b/test/test_framework.cc
index c7e143a..8d249ef 100644
--- a/test/test_framework.cc
+++ b/test/test_framework.cc
@@ -31,21 +31,50 @@
using namespace test;
-/**
- * Default implementation of exception_to_debug_string, that can be overridden
- * by other libraries.
- *
- * \ingroup Test
- */
-std::string exception_to_debug_string(const std::exception &) PALUDIS_ATTRIBUTE((weak,noinline));
-
-std::string exception_to_debug_string(const std::exception & e)
+namespace
{
- return e.what() + std::string(" (no further information)");
+ std::string exception_to_debug_string(const std::exception & e)
+ {
+ return e.what() + std::string(" (no further information)");
+ }
+
+ class DebugStringHolder
+ {
+ private:
+ std::string (*_f) (const std::exception &);
+
+ DebugStringHolder() :
+ _f(&exception_to_debug_string)
+ {
+ }
+
+ public:
+ static DebugStringHolder * get_instance()
+ {
+ static DebugStringHolder _instance;
+ return &_instance;
+ }
+
+ void set(std::string (*f) (const std::exception &))
+ {
+ _f = f;
+ }
+
+ std::string (*get()) (const std::exception &) const
+ {
+ return _f;
+ }
+ };
}
#ifndef DOXYGEN
+void
+test::set_exception_to_debug_string(std::string (*f) (const std::exception &))
+{
+ DebugStringHolder::get_instance()->set(f);
+}
+
std::list<std::string>
TestMessageSuffix::_suffixes;
@@ -113,7 +142,7 @@ TestCase::call_run()
catch (std::exception &e)
{
throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__,
- "Test threw unexpected exception " + exception_to_debug_string(e));
+ "Test threw unexpected exception " + (DebugStringHolder::get_instance()->get())(e));
}
catch (...)
{
@@ -183,7 +212,7 @@ RunTest::operator() (TestCase * test_case) const
}
catch (std::exception &e)
{
- std::cout << "!{" << std::endl << exception_to_debug_string(e) <<
+ std::cout << "!{" << std::endl << (DebugStringHolder::get_instance()->get())(e) <<
std::endl << " } " << std::flush;
had_local_failure = true;
*_had_a_failure = true;
diff --git a/test/test_framework.hh b/test/test_framework.hh
index 710ff8d..c90e805 100644
--- a/test/test_framework.hh
+++ b/test/test_framework.hh
@@ -188,6 +188,8 @@ namespace test
*/
static bool run_tests();
};
+
+ void set_exception_to_debug_string(std::string (*) (const std::exception &));
}
/**