diff options
Diffstat (limited to 'contrib/atf/atf-c++/tests.cpp')
| -rw-r--r-- | contrib/atf/atf-c++/tests.cpp | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/contrib/atf/atf-c++/tests.cpp b/contrib/atf/atf-c++/tests.cpp index a9f5d4a5fe2c..cb0d735f5a06 100644 --- a/contrib/atf/atf-c++/tests.cpp +++ b/contrib/atf/atf-c++/tests.cpp @@ -58,7 +58,6 @@ extern "C" { } #include "atf-c++/detail/application.hpp" -#include "atf-c++/detail/auto_array.hpp" #include "atf-c++/detail/env.hpp" #include "atf-c++/detail/exceptions.hpp" #include "atf-c++/detail/fs.hpp" @@ -123,13 +122,7 @@ static void set_program_name(const char* argv0) { const std::string program_name = atf::fs::path(argv0).leaf_name(); - // Libtool workaround: if running from within the source tree (binaries - // that are not installed yet), skip the "lt-" prefix added to files in - // the ".libs" directory to show the real (not temporary) name. - if (program_name.substr(0, 3) == "lt-") - Program_Name = program_name.substr(3); - else - Program_Name = program_name; + Program_Name = program_name; } bool @@ -207,22 +200,22 @@ impl::tc::init(const vars_map& config) { atf_error_t err; - auto_array< const char * > array(new const char*[(config.size() * 2) + 1]); - const char **ptr = array.get(); + std::vector< const char * > array; + array.reserve((config.size() * 2) + 1); + for (vars_map::const_iterator iter = config.begin(); iter != config.end(); iter++) { - *ptr = (*iter).first.c_str(); - *(ptr + 1) = (*iter).second.c_str(); - ptr += 2; + array.push_back((*iter).first.c_str()); + array.push_back((*iter).second.c_str()); } - *ptr = NULL; + array.push_back(nullptr); wraps[&pimpl->m_tc] = this; cwraps[&pimpl->m_tc] = this; err = atf_tc_init(&pimpl->m_tc, pimpl->m_ident.c_str(), pimpl->wrap_head, pimpl->wrap_body, pimpl->m_has_cleanup ? pimpl->wrap_cleanup : NULL, - array.get()); + array.data()); if (atf_is_error(err)) throw_atf_error(err); } @@ -273,6 +266,7 @@ impl::tc::get_md_vars(void) char **ptr; for (ptr = array; *ptr != NULL; ptr += 2) vars[*ptr] = *(ptr + 1); + atf_utils_free_charpp(array); } catch (...) { atf_utils_free_charpp(array); throw; @@ -461,9 +455,7 @@ init_tcs(void (*add_tcs)(tc_vector&), tc_vector& tcs, const atf::tests::vars_map& vars) { add_tcs(tcs); - for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { - impl::tc* tc = *iter; - + for (auto& tc : tcs) { tc->init(vars); } } @@ -616,27 +608,25 @@ safe_main(int argc, char** argv, void (*add_tcs)(tc_vector&)) int errcode; - tc_vector tcs; if (lflag) { if (argc > 0) throw usage_error("Cannot provide test case names with -l"); - - init_tcs(add_tcs, tcs, vars); - errcode = list_tcs(tcs); } else { if (argc == 0) throw usage_error("Must provide a test case name"); else if (argc > 1) throw usage_error("Cannot provide more than one test case name"); INV(argc == 1); - - init_tcs(add_tcs, tcs, vars); - errcode = run_tc(tcs, argv[0], resfile); } - for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { - impl::tc* tc = *iter; - - delete tc; + tc_vector tcs; + try { + init_tcs(add_tcs, tcs, vars); + errcode = lflag ? list_tcs(tcs) : run_tc(tcs, argv[0], resfile); + } catch (...) { + for (auto& tc: tcs) { + delete tc; + } + throw; } return errcode; |
