aboutsummaryrefslogtreecommitdiff
path: root/0.4.0/paludis/test_extras.cc
diff options
context:
space:
mode:
Diffstat (limited to '0.4.0/paludis/test_extras.cc')
-rw-r--r--0.4.0/paludis/test_extras.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/0.4.0/paludis/test_extras.cc b/0.4.0/paludis/test_extras.cc
new file mode 100644
index 0000000..ec66d14
--- /dev/null
+++ b/0.4.0/paludis/test_extras.cc
@@ -0,0 +1,81 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/stringify.hh>
+#include <sstream>
+#include <test/test_framework.hh>
+
+/** \file
+ * Extra settings for test cases.
+ *
+ * \ingroup grptestcases
+ */
+
+using namespace paludis;
+
+namespace
+{
+ /**
+ * Convert an exception to a debug string.
+ *
+ * \ingroup grptestcases
+ */
+ std::string verbose_exception_to_debug_string(
+ const std::exception & e) PALUDIS_ATTRIBUTE((noinline));
+
+ /**
+ * Avoid logging visibly.
+ *
+ * \ingroup grptestcases
+ */
+ struct C
+ {
+ /// Dummy stream.
+ std::stringstream s;
+
+ /// Constructor.
+ C()
+ {
+ test::set_exception_to_debug_string(&verbose_exception_to_debug_string);
+ Log::get_instance()->set_log_stream(&s);
+ }
+ };
+
+ /**
+ * Avoid logging visibly.
+ *
+ * \ingroup grptestcases
+ */
+ static const C my_c;
+
+ 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();
+ }
+}
+