X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fmain.cc;h=b93f75708c1f7b12e6d45c430e0201af70420bee;hb=74d60e0cbacf53e996e9a72b644e30ed7efa3835;hp=967ec71a21f319b1cd5602d262167bd4f7f7d334;hpb=23dca174eef8d846e3d4402729b57f6ded035e64;p=awesomized%2Flibmemcached diff --git a/libtest/main.cc b/libtest/main.cc index 967ec71a..b93f7570 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include @@ -43,6 +43,9 @@ #include #include #include +#ifdef HAVE_STRINGS_H +# include +#endif #include #include #include @@ -57,6 +60,12 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #endif +#if __cplusplus >= 201103L +# define UNIQUE_PTR std::unique_ptr +#else +# define UNIQUE_PTR std::auto_ptr +#endif + using namespace libtest; static void stats_print(libtest::Framework *frame) @@ -110,7 +119,7 @@ int main(int argc, char *argv[]) Valgrind does not currently work reliably, or sometimes at all, on OSX - Fri Jun 15 11:24:07 EDT 2012 */ -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX +#if defined(__APPLE__) && __APPLE__ if (valgrind_is_caller()) { return EXIT_SKIP; @@ -132,7 +141,7 @@ int main(int argc, char *argv[]) { { "version", no_argument, NULL, OPT_LIBYATL_VERSION }, { "quiet", no_argument, NULL, OPT_LIBYATL_QUIET }, - { "repeat", no_argument, NULL, OPT_LIBYATL_REPEAT }, + { "repeat", required_argument, NULL, OPT_LIBYATL_REPEAT }, { "collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION }, { "wildcard", required_argument, NULL, OPT_LIBYATL_MATCH_WILDCARD }, { "massive", no_argument, NULL, OPT_LIBYATL_MASSIVE }, @@ -158,7 +167,13 @@ int main(int argc, char *argv[]) break; case OPT_LIBYATL_REPEAT: + errno= 0; opt_repeat= strtoul(optarg, (char **) NULL, 10); + if (errno != 0) + { + Error << "unknown value passed to --repeat: `" << optarg << "`"; + exit(EXIT_FAILURE); + } break; case OPT_LIBYATL_MATCH_COLLECTION: @@ -186,9 +201,16 @@ int main(int argc, char *argv[]) srandom((unsigned int)time(NULL)); - if (bool(getenv("YATL_REPEAT")) and (strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10) > 1)) + errno= 0; + if (bool(getenv("YATL_REPEAT"))) { + errno= 0; opt_repeat= strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10); + if (errno != 0) + { + Error << "ENV YATL_REPEAT passed an invalid value: `" << getenv("YATL_REPEAT") << "`"; + exit(EXIT_FAILURE); + } } if ((bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "0") == 0)) or opt_quiet) @@ -220,22 +242,24 @@ int main(int argc, char *argv[]) is_massive(opt_massive); } - char tmp_directory[1024]; + libtest::vchar_t tmp_directory; + tmp_directory.resize(1024); if (getenv("LIBTEST_TMP")) { - snprintf(tmp_directory, sizeof(tmp_directory), "%s", getenv("LIBTEST_TMP")); + snprintf(&tmp_directory[0], tmp_directory.size(), "%s", getenv("LIBTEST_TMP")); } else { - snprintf(tmp_directory, sizeof(tmp_directory), "%s", LIBTEST_TEMP); + snprintf(&tmp_directory[0], tmp_directory.size(), "%s", LIBTEST_TEMP); } - if (chdir(tmp_directory) == -1) + if (chdir(&tmp_directory[0]) == -1) { - char getcwd_buffer[1024]; - char *dir= getcwd(getcwd_buffer, sizeof(getcwd_buffer)); + libtest::vchar_t getcwd_buffer; + getcwd_buffer.resize(1024); + char *dir= getcwd(&getcwd_buffer[0], getcwd_buffer.size()); - Error << "Unable to chdir() from " << dir << " to " << tmp_directory << " errno:" << strerror(errno); + Error << "Unable to chdir() from " << dir << " to " << &tmp_directory[0] << " errno:" << strerror(errno); return EXIT_FAILURE; } @@ -279,7 +303,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - std::auto_ptr frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); + UNIQUE_PTR frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); // Run create(), bail on error. { @@ -289,10 +313,11 @@ int main(int argc, char *argv[]) break; case TEST_SKIPPED: - return EXIT_SKIP; + SKIP("SKIP was returned from framework create()"); + break; case TEST_FAILURE: - std::cerr << "frame->create()" << std::endl; + std::cerr << "Could not call frame->create()" << std::endl; return EXIT_FAILURE; } } @@ -329,7 +354,7 @@ int main(int argc, char *argv[]) std::ofstream xml_file; std::string file_name; - file_name.append(tmp_directory); + file_name.append(&tmp_directory[0]); file_name.append(frame->name()); file_name.append(".xml"); xml_file.open(file_name.c_str(), std::ios::trunc); @@ -338,24 +363,33 @@ int main(int argc, char *argv[]) Outn(); // Generate a blank to break up the messages if make check/test has been run } while (exit_code == EXIT_SUCCESS and --opt_repeat); } - catch (libtest::fatal& e) + catch (const libtest::__skipped& e) + { + return EXIT_SKIP; + } + catch (const libtest::__failure& e) + { + libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); + exit_code= EXIT_FAILURE; + } + catch (const libtest::fatal& e) { std::cerr << "FATAL:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (libtest::disconnected& e) + catch (const libtest::disconnected& e) { std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (std::exception& e) + catch (const std::exception& e) { std::cerr << "std::exception:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (char const*) + catch (char const* s) { - std::cerr << "Exception:" << std::endl; + std::cerr << "Exception:" << s << std::endl; exit_code= EXIT_FAILURE; } catch (...)