aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 16:45:54 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 16:45:54 +0100
commit6b1f92a04fd2b6cfae9fd6a7df4204e4a21d7966 (patch)
tree7ebcd7235b7daf406d7b7cf0e2e6a7fa0a168e42
parent58b0c87ae639014fdb70ed6d8b9c4af2f83b92ae (diff)
downloadpaludis-6b1f92a04fd2b6cfae9fd6a7df4204e4a21d7966.tar.gz
paludis-6b1f92a04fd2b6cfae9fd6a7df4204e4a21d7966.tar.xz
Kill old test framework
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac1
-rw-r--r--misc/common-makefile.am2
-rw-r--r--paludis/util/run_test.sh60
-rw-r--r--test/Makefile.am33
-rwxr-xr-xtest/run_test.sh69
-rw-r--r--test/test_concepts.hh56
-rw-r--r--test/test_fail_TEST.cc47
-rw-r--r--test/test_framework.cc374
-rw-r--r--test/test_framework.hh318
-rw-r--r--test/test_pass_TEST.cc51
-rw-r--r--test/test_runner.cc132
-rw-r--r--test/test_runner.hh38
13 files changed, 62 insertions, 1121 deletions
diff --git a/Makefile.am b/Makefile.am
index 24b533c..87c779c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ MAINTAINERCLEANFILES = Makefile.in configure config/* aclocal.m4 \
config.h config.h.in INSTALL
AUTOMAKE_OPTIONS = 1.11 dist-bzip2 no-dist-gzip foreign parallel-tests
EXTRA_DIST = autogen.bash automake-deps-dist-hack.tmp
-SUBDIRS = . misc test paludis python ruby src doc hooks vim bash-completion zsh-completion pkg-config
+SUBDIRS = . misc paludis python ruby src doc hooks vim bash-completion zsh-completion pkg-config
DISTCHECK_CONFIGURE_FLAGS = --enable-ruby --enable-ruby-doc --enable-vim \
--enable-python --enable-python-doc --enable-xml \
diff --git a/configure.ac b/configure.ac
index 6f7e9bb..f47a872 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1863,7 +1863,6 @@ AC_CONFIG_FILES([
src/clients/cave/Makefile
src/clients/instruo/Makefile
src/output/Makefile
- test/Makefile
vim/Makefile
vim/ftdetect/Makefile
vim/syntax/Makefile
diff --git a/misc/common-makefile.am b/misc/common-makefile.am
index a6d41ce..41b1627 100644
--- a/misc/common-makefile.am
+++ b/misc/common-makefile.am
@@ -98,7 +98,7 @@ LOG_COMPILER = \
TOP_SRCDIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_srcdir)`" \
TOP_BUILDDIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)`" \
$(LOG_COMPILER_EXTRA) \
- bash $(top_srcdir)/test/run_test.sh $(LOG_COMPILER_INTERP)
+ bash $(top_srcdir)/paludis/util/run_test.sh $(LOG_COMPILER_INTERP)
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/paludis/util/run_test.sh b/paludis/util/run_test.sh
new file mode 100644
index 0000000..4a428ad
--- /dev/null
+++ b/paludis/util/run_test.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+testname=${2:-${1}}
+interp=
+[[ ${testname%.py} != ${testname} ]] && interp="${PYTHON}"
+[[ ${testname%.rb} != ${testname} ]] && interp="${RUBY} -I ./.libs/"
+
+testname=${testname%.rb}
+testname=${testname%.py}
+testname=${testname%.bash}
+
+export PALUDIS_TEST_PROGRAM=$testname
+
+if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${testname}"
+ if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> exiting with error for test ${testname}"
+ exit 255
+ fi
+else
+ echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run"
+fi
+
+if test -f "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
+ echo ">>> setup for test ${testname}"
+ if ! "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
+ echo ">>> exiting with error for test ${testname}"
+ exit 255
+ fi
+else
+ echo ">>> No $TEST_SCRIPT_DIR${testname}_setup.sh to run"
+fi
+
+now=$(date +'%s' )
+echo ">>> test ${testname}"
+$interp ${@}
+code=$?
+duration=$(( $(date +'%s' ) - ${now} ))
+
+if [[ 0 != ${code} ]] ; then
+ echo ">>> test ${testname} returned ${code} [${duration}s]"
+ echo ">>> exiting with error for test ${testname}"
+ exit 255
+fi
+
+if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${testname}"
+ if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> exiting with error for test ${testname}"
+ exit 255
+ fi
+else
+ echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run"
+fi
+
+echo ">>> exiting with success for test ${testname} [${duration}s]"
+exit 0
+
+
diff --git a/test/Makefile.am b/test/Makefile.am
deleted file mode 100644
index a1137b7..0000000
--- a/test/Makefile.am
+++ /dev/null
@@ -1,33 +0,0 @@
-include $(top_srcdir)/misc/common-makefile.am
-
-AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@ @PALUDIS_CXXFLAGS_VISIBILITY@
-EXTRA_DIST = run_test.sh
-
-libtest_a_SOURCES = \
- test_framework.cc \
- test_framework.hh \
- test_runner.cc \
- test_runner.hh \
- test_concepts.hh
-
-libtestnomain_a_SOURCES = \
- test_framework.cc \
- test_framework.hh \
- test_concepts.hh
-
-my_XFAIL_TESTS = test_fail_TEST
-XFAIL_TESTS = $(my_XFAIL_TESTS)
-TESTS = test_pass_TEST $(my_XFAIL_TESTS)
-
-check_LIBRARIES = libtest.a libtestnomain.a
-check_PROGRAMS = $(TESTS) $(XFAIL_TESTS)
-check_SCRIPTS = run_test.sh
-
-test_pass_TEST_SOURCES = test_pass_TEST.cc
-test_pass_TEST_LDADD = libtest.a
-test_pass_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
-
-test_fail_TEST_SOURCES = test_fail_TEST.cc
-test_fail_TEST_LDADD = libtest.a
-test_fail_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
-
diff --git a/test/run_test.sh b/test/run_test.sh
deleted file mode 100755
index 056beec..0000000
--- a/test/run_test.sh
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env bash
-# vim: set ft=sh sw=4 sts=4 et :
-
-testname=${2:-${1}}
-interp=
-[[ ${testname%.py} != ${testname} ]] && interp="${PYTHON}"
-[[ ${testname%.rb} != ${testname} ]] && interp="${RUBY} -I ./.libs/"
-
-testname=${testname%.rb}
-testname=${testname%.py}
-testname=${testname%.bash}
-
-export PALUDIS_TEST_PROGRAM=$testname
-
-[[ -z "PALUDIS_TESTS_REAL_STDOUT_FD" ]] && export PALUDIS_TESTS_REAL_STDOUT_FD=1
-
-if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
- echo ">>> cleanup for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
- echo ">>> exiting with error for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- exit 255
- fi
-else
- echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
-fi
-
-if test -f "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
- echo ">>> setup for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- if ! "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
- echo ">>> exiting with error for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- exit 255
- fi
-else
- echo ">>> No $TEST_SCRIPT_DIR${testname}_setup.sh to run" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
-fi
-
-now=$(date +'%s' )
-echo ">>> test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
-$interp ${@}
-code=$?
-duration=$(( $(date +'%s' ) - ${now} ))
-
-if [[ 0 != ${code} ]] ; then
- echo ">>> test ${testname} returned ${code} [${duration}s]" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- if [[ -z "${PALUDIS_TESTS_RERUN_VERBOSELY}" ]] && [[ "${testname#./}" != "test_fail_TEST" ]] ; then
- out=`pwd`/${testname#./}.epicfail
- echo ">>> rerunning test ${testname} verbosely redirected to ${out}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- env PALUDIS_TESTS_RERUN_VERBOSELY=no PALUDIS_TESTS_KEEP_STDERR=yes \
- PALUDIS_TESTS_KEEP_LOG=yes TEST_OUTPUT_WRAPPER= $0 $@ > $out 2>&1
- echo ">>> saved output of verbose ${testname} rerun to ${out}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- fi
- echo ">>> exiting with error for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- exit 255
-fi
-
-if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
- echo ">>> cleanup for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
- echo ">>> exiting with error for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
- exit 255
- fi
-else
- echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
-fi
-
-echo ">>> exiting with success for test ${testname} [${duration}s]" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
-exit 0
-
-
diff --git a/test/test_concepts.hh b/test/test_concepts.hh
deleted file mode 100644
index c9190ed..0000000
--- a/test/test_concepts.hh
+++ /dev/null
@@ -1,56 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2008 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
- * 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
- */
-
-#ifndef PALUDIS_GUARD_TEST_TEST_CONCEPTS_HH
-#define PALUDIS_GUARD_TEST_TEST_CONCEPTS_HH 1
-
-namespace test
-{
-}
-
-#define TEST_XSTRINGIFY(x) #x
-#define TEST_STRINGIFY(x) TEST_XSTRINGIFY(x)
-
-#define TESTCASE_SEMIREGULAR(Type, initial_instance) \
- struct Type ## IsSemiRegularTest : TestCase \
- { \
- Type ## IsSemiRegularTest() : TestCase(TEST_STRINGIFY(Type) " is semi regular") { } \
- \
- void run() \
- { \
- Type copy(initial_instance); \
- Type assigned = initial_instance; \
- assigned = initial_instance; \
- Type * free_store = new Type(initial_instance); \
- delete free_store; \
- } \
- } Type ## _is_semi_regular_test
-
-#define TESTCASE_STRINGIFYABLE(Type, initial_instance, str) \
- struct Type ## IsStringifiableTest : TestCase \
- { \
- Type ## IsStringifiableTest() : TestCase(TEST_STRINGIFY(Type) " is stringifiable") { } \
- \
- void run() \
- { \
- TEST_CHECK_STRINGIFY_EQUAL(stringify(initial_instance), str); \
- } \
- } Type ## _is_stringifiable_test
-
-#endif
diff --git a/test/test_fail_TEST.cc b/test/test_fail_TEST.cc
deleted file mode 100644
index ec609a6..0000000
--- a/test/test_fail_TEST.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 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
- * 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 <string>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-
-using namespace test;
-
-/** \file
- * This test should fail.
- *
- * \ingroup grptestframework
- */
-
-namespace test_cases
-{
- /**
- * \test This test should fail.
- */
- struct FailTest : TestCase
- {
- FailTest() : TestCase("test the test code: this should fail") { }
-
- void run()
- {
- TEST_CHECK_STRINGIFY_EQUAL("this comparison", "should fail");
- }
- } test_fail;
-}
-
diff --git a/test/test_framework.cc b/test/test_framework.cc
deleted file mode 100644
index a6c6ae0..0000000
--- a/test/test_framework.cc
+++ /dev/null
@@ -1,374 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006, 2007, 2009, 2010, 2011 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
- * 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 "test_framework.hh"
-#include <algorithm>
-#include <iostream>
-#include <list>
-#include <paludis/util/attributes.hh>
-#include <paludis/util/pimp-impl.hh>
-#include <unistd.h>
-#include <cstdlib>
-#include <sys/time.h>
-
-/** \file
- * Imp for test framework classes.
- *
- * \ingroup grptestframework
- */
-
-using namespace test;
-
-#ifndef DOXYGEN
-namespace
-{
- 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) (const std::exception &)
- {
- return _f;
- }
- };
-}
-
-void
-test::set_exception_to_debug_string(std::string (*f) (const std::exception &))
-{
- DebugStringHolder::get_instance()->set(f);
-}
-
-std::string (* test::get_exception_to_debug_string()) (const std::exception &)
-{
- return DebugStringHolder::get_instance()->get();
-}
-
-namespace paludis
-{
- template<>
- struct Imp<TestMessageSuffix>
- {
- static std::list<std::string> suffixes;
- };
-
- std::list<std::string> Imp<TestMessageSuffix>::suffixes;
-}
-
-std::string
-TestMessageSuffix::suffixes()
-{
- std::string result;
- std::list<std::string>::const_iterator i(paludis::Imp<TestMessageSuffix>::suffixes.begin()),
- end(paludis::Imp<TestMessageSuffix>::suffixes.end());
-
- while (i != end)
- {
- result += *i++;
- if (end != i)
- result += ", ";
- }
- return result;
-}
-
-TestMessageSuffix::TestMessageSuffix(const std::string & s, bool write) :
- _imp()
-{
- paludis::Imp<TestMessageSuffix>::suffixes.push_back(s);
- if (write)
- std::cout << "[" << s << "]" << std::flush;
-}
-
-TestMessageSuffix::~TestMessageSuffix()
-{
- paludis::Imp<TestMessageSuffix>::suffixes.pop_back();
-}
-
-namespace paludis
-{
- template<>
- struct Imp<TestCase>
- {
- const std::string name;
- mutable const char * reached_file;
- mutable const char * reached_function;
- mutable long reached_line;
-
- Imp(const std::string & the_name) :
- name(the_name),
- reached_file(NULL),
- reached_function(NULL),
- reached_line(0)
- {
- }
- };
-}
-
-TestCase::TestCase(const std::string & our_name) :
- _imp(our_name)
-{
- TestCaseList::register_test_case(this);
-}
-
-TestCase::~TestCase()
-{
-}
-
-void
-TestCase::check(const char * const function, const char * const file,
- const long line, bool was_ok, const std::string & message) const
-{
- std::cout << "." << std::flush;
- if (! was_ok)
- throw TestFailedException(function, file, line, message);
-}
-
-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)
- {
- throw;
- }
- catch (std::exception &e)
- {
- 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(_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");
- }
-}
-
-std::string
-TestCase::name() const
-{
- return _imp->name;
-}
-
-TestFailedException::TestFailedException(const char * const function, const char * const file,
- const long line, const std::string & message) throw () :
- _message(paludis::stringify(file) + ":" + paludis::stringify(line) + ": in " +
- paludis::stringify(function) + ": " + message + (
- TestMessageSuffix::suffixes().empty() ? std::string("") : " [context: " +
- TestMessageSuffix::suffixes() + "]"))
-{
-}
-
-TestFailedException::~TestFailedException() throw ()
-{
-}
-
-namespace
-{
- std::list<TestCase *> *
- get_test_case_list()
- {
- static std::list<TestCase *> l;
- return &l;
- }
-}
-
-TestCaseList::TestCaseList()
-{
-}
-
-TestCaseList::~TestCaseList()
-{
-}
-
-void
-TestCaseList::register_test_case(TestCase * const t)
-{
- get_test_case_list()->push_back(t);
-}
-
-class RunTest
-{
- private:
- bool * const _had_a_failure;
- const std::string _named_test;
-
- public:
- RunTest(bool * had_a_failure, const std::string & named_test) :
- _had_a_failure(had_a_failure),
- _named_test(named_test)
- {
- }
-
- void operator() (TestCase * test_case) const;
-};
-
-void
-RunTest::operator() (TestCase * test_case) const
-{
- bool had_local_failure(false);
-
- if ((! _named_test.empty()) && (_named_test != test_case->name()))
- {
- std::cout << "* \"" << test_case->name() << "\": (skip due to NAMED_TEST_ONLY)" << std::endl;
- return;
- }
-
- std::cout << "* \"" << test_case->name() << "\": " << std::flush;
-
- int extra_fd = -1;
- if (getenv("PALUDIS_TESTS_REAL_STDOUT_FD"))
- {
- std::stringstream s;
- s << getenv("PALUDIS_TESTS_REAL_STDOUT_FD");
- s >> extra_fd;
-
- std::stringstream t;
- t << ">>> ";
- if (getenv("PALUDIS_TEST_PROGRAM"))
- t << getenv("PALUDIS_TEST_PROGRAM");
- else
- t << "Unknown Test Program";
- t << " test " << test_case->name() << "..." << std::endl;
-
- std::string buf(t.str());
- while (! buf.empty())
- {
- int n(write(extra_fd, buf.c_str(), buf.length()));
- if (-1 == n)
- break;
- buf.erase(0, n);
- }
- }
-
- for (int repeat = 0 ; repeat < 2 ; ++repeat)
- {
- if (test_case->skip())
- {
- std::cout << "(skip)" << std::endl;
- break;
- }
-
- if (0 != repeat)
- std::cout << " (repeat): " << std::flush;
-
- struct timeval start_tv;
- ::gettimeofday(&start_tv, 0);
-
- try
- {
- if (TestCaseList::use_alarm)
- alarm(test_case->max_run_time());
- test_case->call_run();
- if (TestCaseList::use_alarm)
- alarm(0);
- }
- catch (std::exception &e)
- {
- std::cout << "!{" << std::endl << (DebugStringHolder::get_instance()->get())(e) <<
- std::endl << " } " << std::flush;
- had_local_failure = true;
- *_had_a_failure = true;
- }
- catch (...)
- {
- std::cout << "!{Unknown exception type} ";
- had_local_failure = true;
- *_had_a_failure = true;
- }
-
- if (had_local_failure)
- std::cout << " NOT OK";
- else
- {
- struct timeval tv;
- ::gettimeofday(&tv, 0);
- const unsigned long delta(((tv.tv_sec - start_tv.tv_sec) * 1000) + ((tv.tv_usec - start_tv.tv_usec) / 1000));
- std::cout << " OK (" << delta << "ms)";
- }
-
- std::cout << std::endl;
-
- if (! test_case->repeatable())
- break;
- }
-}
-
-bool
-TestCaseList::run_tests()
-{
- bool had_a_failure(get_test_case_list()->empty());
-
- std::string named_test;
- if (getenv("NAMED_TEST_ONLY"))
- named_test = getenv("NAMED_TEST_ONLY");
-
- std::for_each(
- get_test_case_list()->begin(),
- get_test_case_list()->end(),
- RunTest(&had_a_failure, named_test));
-
- return ! had_a_failure;
-}
-
-bool
-TestCaseList::use_alarm(true);
-
-#endif
-
diff --git a/test/test_framework.hh b/test/test_framework.hh
deleted file mode 100644
index 14569c1..0000000
--- a/test/test_framework.hh
+++ /dev/null
@@ -1,318 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 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
- * 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
- */
-
-#ifndef PALUDIS_GUARD_TEST_TEST_FRAMEWORK_HH
-#define PALUDIS_GUARD_TEST_TEST_FRAMEWORK_HH 1
-
-#include <paludis/util/stringify.hh>
-#include <paludis/util/pimp.hh>
-#include <string>
-
-/** \file
- * Test framework class definitions.
- *
- * \ingroup grptestframework
- */
-
-namespace test
-{
- /**
- * RAII suffix marker for TestCase context.
- *
- * \ingroup grptestframework
- */
- class TestMessageSuffix
- {
- private:
- paludis::Pimp<TestMessageSuffix> _imp;
-
- public:
- /**
- * Constructor.
- */
- explicit TestMessageSuffix(const std::string & s, bool write = false);
-
- /**
- * Destructor.
- */
- ~TestMessageSuffix();
-
- /**
- * Our suffixes.
- */
- static std::string suffixes();
- };
-
- /**
- * Base TestCase class.
- *
- * \ingroup grptestframework
- */
- class TestCase
- {
- private:
- paludis::Pimp<TestCase> _imp;
-
- protected:
- /**
- * Check that a given assertion is true.
- */
- void check(const char * const function, const char * const file,
- 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;
-
- public:
- /**
- * Constructor.
- */
- TestCase(const std::string & name);
-
- /**
- * Destructor.
- */
- virtual ~TestCase();
-
- /**
- * Call our run() function, and normalise exceptions.
- */
- void call_run();
-
- /**
- * Return our name.
- */
- std::string name() const;
-
- /**
- * Are we repeatable? Override if not.
- */
- virtual bool repeatable() const
- {
- return true;
- }
-
- /**
- * Should we be skipped?
- */
- virtual bool skip() const
- {
- return false;
- }
-
- /**
- * After how many seconds should we timeout?
- */
- virtual unsigned max_run_time() const
- {
- return 300;
- }
- };
-
- /**
- * Thrown if a TestCase failed.
- *
- * \ingroup grptestframework
- * \ingroup grpexceptions
- */
- class TestFailedException : public std::exception
- {
- private:
- const std::string _message;
-
- public:
- /**
- * Constructor.
- */
- TestFailedException(const char * const function, const char * const file,
- const long line, const std::string & message) throw ();
-
- /**
- * Destructor.
- */
- virtual ~TestFailedException() throw ();
-
- /**
- * Description.
- */
- const char * what() const throw ()
- {
- return _message.c_str();
- }
- };
-
- /**
- * A list of TestCase instances.
- *
- * \ingroup grptestframework
- */
- class TestCaseList
- {
- private:
- TestCaseList();
- ~TestCaseList();
-
- public:
- /**
- * Register a TestCase instance.
- */
- static void register_test_case(TestCase * const test_case);
-
- /**
- * Run all tests.
- */
- static bool run_tests();
-
- /**
- * Should we use alarm?
- */
- static bool use_alarm;
- };
-
- /**
- * Change the function used to get a string description of an exception.
- */
- void set_exception_to_debug_string(std::string (*) (const std::exception &));
-
- /**
- * Fetch the function used to get a string description of an exception.
- */
- std::string (* get_exception_to_debug_string()) (const std::exception &);
-
- /**
- * Utility class used by TEST_CHECK_EQUAL.
- */
- struct TwoVarHolder
- {
- bool result;
- std::string s_a;
- std::string s_b;
- std::string s_d;
-
- template <typename T1_, typename T2_>
- TwoVarHolder(T1_ a, T2_ b) :
- result(a == b),
- s_a(paludis::stringify(a)),
- s_b(paludis::stringify(b))
- {
- if (! result)
- {
- if (0 == s_a.compare(0, std::min(s_a.length(), s_b.length()), s_b,
- 0, std::min(s_a.length(), s_b.length())))
- {
- if (s_a.length() < s_b.length())
- s_d = " (trailing '" + s_b.substr(s_a.length()) + "' missing)";
- else
- s_d = " (trailing '" + s_a.substr(s_b.length()) + "' found)";
- }
- else
- {
- std::string::size_type p(0);
- for (std::string::size_type p_end(std::min(s_a.length(), s_b.length())) ; p < p_end ; ++p)
- if (s_a.at(p) != s_b.at(p))
- {
- s_d = " (difference starts at offset " + paludis::stringify(p) + ", got '" +
- s_b.substr(p, 10) + "', expected '" + s_a.substr(p, 10) + "')";
- break;
- }
- }
- }
- }
- };
-}
-
-/**
- * Check that a == b.
- */
-#define TEST_CHECK_EQUAL(a, b) \
- do { \
- 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)
-
-/**
- * Check that stringify(a) == stringify(b).
- */
-#define TEST_CHECK_STRINGIFY_EQUAL(a, b) \
- do { \
- 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)
-
-/**
- * Check that a is true.
- */
-#define TEST_CHECK(a) \
- do { \
- reached(__PRETTY_FUNCTION__, __FILE__, __LINE__); \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, a, \
- "Check '" #a "' failed"); \
- } while (false)
-
-/**
- * Check that a is true, with a custom message.
- */
-#define TEST_CHECK_MESSAGE(a, b) \
- do { \
- reached(__PRETTY_FUNCTION__, __FILE__, __LINE__); \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, a, \
- b); \
- } while (false)
-
-/**
- * Check that a throws an exception of type b.
- */
-#define TEST_CHECK_THROWS(a, b) \
- do { \
- try { \
- try { \
- a; \
- check(__PRETTY_FUNCTION__, __FILE__, __LINE__, false, \
- "Expected exception of type '" #b "' not thrown"); \
- } catch (b &) { \
- TEST_CHECK(true); \
- } \
- } 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_THROWS block"); \
- } catch (...) { \
- throw TestFailedException(__PRETTY_FUNCTION__, __FILE__, __LINE__, \
- "Test threw unexpected unknown exception inside a TEST_CHECK_THROWS block"); \
- } \
- } while (false)
-
-#endif
-
diff --git a/test/test_pass_TEST.cc b/test/test_pass_TEST.cc
deleted file mode 100644
index 552bc76..0000000
--- a/test/test_pass_TEST.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 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
- * 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 <string>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-
-using namespace test;
-
-/** \file
- * This test should pass.
- *
- * \ingroup grptestframework
- */
-
-namespace test_cases
-{
- /**
- * \test This test should pass.
- *
- * \ingroup grptestframework
- */
- struct PassTest : TestCase
- {
- PassTest() : TestCase("test the test code: this should pass") { }
-
- void run()
- {
- TEST_CHECK_EQUAL(1, 1);
- TEST_CHECK(true);
- TEST_CHECK_THROWS(std::string("1").at(10), std::exception);
- }
- } test_pass;
-}
-
diff --git a/test/test_runner.cc b/test/test_runner.cc
deleted file mode 100644
index 802bf89..0000000
--- a/test/test_runner.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006, 2007, 2008 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
- * 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 "test_framework.hh"
-#include "test_runner.hh"
-#include <paludis/util/stringify.hh>
-
-#include <iostream>
-#include <fstream>
-#include <cstdlib>
-#include <exception>
-#include <signal.h>
-#if defined(__GLIBC__)
-#include <execinfo.h>
-#endif
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "config.h"
-#ifdef HAVE_CXA_DEMANGLE
-# include <cxxabi.h>
-#endif
-
-/** \file
- * Imp of the default test runner.
- *
- * \ingroup grptestframework
- */
-
-using namespace test;
-
-namespace
-{
- void do_backtrace()
- {
-#if defined(__GLIBC__)
- void * bt[50];
- int sz = backtrace(bt, 50);
- char * * symbols = backtrace_symbols(bt, sz);
-
- std::cerr << "Stack dump:" << std::endl;
- for (int n(0) ; n < sz ; ++n)
- {
- std::string sym(symbols[n]);
-
-#ifdef HAVE_CXA_DEMANGLE
- std::string::size_type p, q;
- if (std::string::npos != ((p = sym.find("(_Z"))) && std::string::npos != ((q = sym.find("+0x", p))))
- {
- ++p;
- int status(0);
- char * const name(abi::__cxa_demangle(sym.substr(p, q - p).c_str(), 0, 0, &status));
- if (0 == status)
- {
- sym = sym.substr(0, p) + name + sym.substr(q);
- std::free(name);
- }
- }
-#endif
-
- std::cerr << " * " << sym << std::endl;
- }
-
- std::free(symbols);
-#endif
- }
-}
-
-void timeout_handler(int)
-{
- std::cerr << std::endl << "Test aborted due to timeout!" << std::endl;
- do_backtrace();
- std::exit(EXIT_FAILURE);
-}
-
-void segfault_handler(int)
-{
- std::cerr << std::endl << "Test aborted due to segmentation fault!" << std::endl;
- do_backtrace();
- std::exit(EXIT_FAILURE);
-}
-
-int
-main(int, char * argv[])
-{
- try
- {
- {
- std::ifstream ppid(("/proc/" + paludis::stringify(getppid()) + "/cmdline").c_str());
- if (ppid)
- {
- std::string cmd;
- std::getline(ppid, cmd, '\0');
- std::string::size_type slash_pos(cmd.rfind('/'));
- if (std::string::npos != slash_pos)
- cmd.erase(0, slash_pos);
- if (cmd != "gdb")
- {
- signal(SIGALRM, &timeout_handler);
- signal(SIGSEGV, &segfault_handler);
- }
- else
- TestCaseList::use_alarm = false;
- }
- }
-
- std::cout << "Test program " << argv[0] << ":" << std::endl;
- return TestCaseList::run_tests() ? EXIT_SUCCESS : EXIT_FAILURE;
- }
- catch (const std::exception & e)
- {
- std::cout << "Uncaught exception " << e.what() << std::endl;
- return EXIT_FAILURE;
- }
-}
-
diff --git a/test/test_runner.hh b/test/test_runner.hh
deleted file mode 100644
index ca1d018..0000000
--- a/test/test_runner.hh
+++ /dev/null
@@ -1,38 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 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
- * 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
- */
-
-#ifndef PALUDIS_GUARD_TEST_TEST_RUNNER_HH
-#define PALUDIS_GUARD_TEST_TEST_RUNNER_HH 1
-
-#include <paludis/util/attributes.hh>
-
-/** \file
- * Declarations for the default test runner.
- */
-
-/// Main program.
-int main(int, char *[]);
-
-/// Called if we take too long.
-void timeout_handler(int) PALUDIS_ATTRIBUTE((noreturn));
-
-/// Called if we get a segfault.
-void segfault_handler(int) PALUDIS_ATTRIBUTE((noreturn));
-
-#endif