main.ipp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #include <boost/beast/_experimental/unit_test/amount.hpp>
  10. #include <boost/beast/_experimental/unit_test/dstream.hpp>
  11. #include <boost/beast/_experimental/unit_test/global_suites.hpp>
  12. #include <boost/beast/_experimental/unit_test/match.hpp>
  13. #include <boost/beast/_experimental/unit_test/reporter.hpp>
  14. #include <boost/beast/_experimental/unit_test/suite.hpp>
  15. #include <boost/config.hpp>
  16. #include <cstdlib>
  17. #include <iostream>
  18. #include <vector>
  19. #ifdef BOOST_MSVC
  20. # ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
  21. # define WIN32_LEAN_AND_MEAN
  22. # include <windows.h>
  23. # undef WIN32_LEAN_AND_MEAN
  24. # else
  25. # include <windows.h>
  26. # endif
  27. #endif
  28. // Simple main used to produce stand
  29. // alone executables that run unit tests.
  30. int main(int ac, char const* av[])
  31. {
  32. using namespace std;
  33. using namespace boost::beast::unit_test;
  34. dstream log(std::cerr);
  35. std::unitbuf(log);
  36. #ifdef BOOST_MSVC
  37. {
  38. int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  39. flags |= _CRTDBG_LEAK_CHECK_DF;
  40. _CrtSetDbgFlag(flags);
  41. }
  42. #endif
  43. if(ac == 2)
  44. {
  45. std::string const s{av[1]};
  46. if(s == "-h" || s == "--help")
  47. {
  48. log <<
  49. "Usage:\n"
  50. " " << av[0] << ": { <suite-name>... }" <<
  51. std::endl;
  52. return EXIT_SUCCESS;
  53. }
  54. }
  55. reporter r(log);
  56. bool failed;
  57. if(ac > 1)
  58. {
  59. std::vector<selector> v;
  60. v.reserve(ac - 1);
  61. for(int i = 1; i < ac; ++i)
  62. v.emplace_back(selector::automatch, av[i]);
  63. auto pred =
  64. [&v](suite_info const& si) mutable
  65. {
  66. for(auto& p : v)
  67. if(p(si))
  68. return true;
  69. return false;
  70. };
  71. failed = r.run_each_if(global_suites(), pred);
  72. }
  73. else
  74. {
  75. failed = r.run_each(global_suites());
  76. }
  77. if(failed)
  78. return EXIT_FAILURE;
  79. return EXIT_SUCCESS;
  80. }