diff options
author | 2008-11-10 19:52:19 +0000 | |
---|---|---|
committer | 2008-11-11 17:38:44 +0000 | |
commit | 79d5e4761d20b6c790e6f32b69f3f5da48039360 (patch) | |
tree | 760549bf227d57e8817b56de68fcba731d4071b0 | |
parent | 83594fbc6dba4893701b5b30397bdbaedd36f6d7 (diff) | |
download | paludis-79d5e4761d20b6c790e6f32b69f3f5da48039360.tar.gz paludis-79d5e4761d20b6c790e6f32b69f3f5da48039360.tar.xz |
Catch exceptions escaping tests
-rw-r--r-- | test/test_runner.cc | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/test/test_runner.cc b/test/test_runner.cc index 9effc7c..107c5a6 100644 --- a/test/test_runner.cc +++ b/test/test_runner.cc @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2006, 2007 Ciaran McCreesh + * 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 @@ -24,6 +24,7 @@ #include <iostream> #include <fstream> #include <cstdlib> +#include <exception> #include <signal.h> #if defined(__GLIBC__) #include <execinfo.h> @@ -98,26 +99,34 @@ void segfault_handler(int) 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") + std::ifstream ppid(("/proc/" + paludis::stringify(getppid()) + "/cmdline").c_str()); + if (ppid) { - signal(SIGALRM, &timeout_handler); - signal(SIGSEGV, &segfault_handler); + 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; } - else - TestCaseList::use_alarm = false; } - } - std::cout << "Test program " << argv[0] << ":" << std::endl; - return TestCaseList::run_tests() ? EXIT_SUCCESS : EXIT_FAILURE; + 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; + } } |