X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fmain.cc;h=2ceeac92cf0bdba962a035e4e240a38e4409ab79;hb=b036e172e5839d530bce7c3831a8eaf36d68eca7;hp=363c2a2ff614c58d2188c3addf4d13ce97e6b7d2;hpb=a0a194ba0789e0650329d81a5ed12620360789eb;p=awesomized%2Flibmemcached diff --git a/libtest/main.cc b/libtest/main.cc index 363c2a2f..2ceeac92 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -34,7 +34,7 @@ * */ -#include +#include "libtest/yatlcon.h" #include #include @@ -83,7 +83,6 @@ static void stats_print(libtest::Framework *frame) int main(int argc, char *argv[]) { - Out << "BEGIN:" << argv[0]; bool opt_massive= false; unsigned long int opt_repeat= 1; // Run all tests once bool opt_quiet= false; @@ -133,7 +132,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 }, @@ -159,7 +158,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: @@ -187,9 +192,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) @@ -221,22 +233,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; } @@ -283,6 +297,7 @@ int main(int argc, char *argv[]) std::auto_ptr frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); // Run create(), bail on error. + try { switch (frame->create()) { @@ -293,10 +308,14 @@ int main(int argc, char *argv[]) return EXIT_SKIP; case TEST_FAILURE: - std::cerr << __FILE__ << ":" << __LINE__ << ": " << "frame->create()" << std::endl; + std::cerr << "Could not call frame->create()" << std::endl; return EXIT_FAILURE; } } + catch (const libtest::__skipped& e) + { + return EXIT_SKIP; + } frame->exec(); @@ -330,7 +349,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); @@ -339,33 +358,40 @@ 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) { - std::cerr << __FILE__ << ":" << __LINE__ << ": " << "FATAL:" << e.what() << std::endl; + 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 << __FILE__ << ":" << __LINE__ << ": " << "Unhandled disconnection occurred:" << e.what() << std::endl; + std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (std::exception& e) + catch (const std::exception& e) { - std::cerr << __FILE__ << ":" << __LINE__ << ": " << "std::exception:" << e.what() << std::endl; + std::cerr << "std::exception:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (char const*) + catch (char const* s) { - std::cerr << __FILE__ << ":" << __LINE__ << ": " << "Exception:" << std::endl; + std::cerr << "Exception:" << s << std::endl; exit_code= EXIT_FAILURE; } catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ << ": " << "Unknown exception halted execution." << std::endl; + std::cerr << "Unknown exception halted execution." << std::endl; exit_code= EXIT_FAILURE; } - Out << "END:" << argv[0]; - return exit_code; }