catch_session.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. #ifndef CATCH_SESSION_HPP_INCLUDED
  7. #define CATCH_SESSION_HPP_INCLUDED
  8. #include <catch2/internal/catch_commandline.hpp>
  9. #include <catch2/internal/catch_noncopyable.hpp>
  10. #include <catch2/catch_config.hpp>
  11. #include <catch2/internal/catch_unique_ptr.hpp>
  12. #include <catch2/internal/catch_config_wchar.hpp>
  13. namespace Catch {
  14. class Session : Detail::NonCopyable {
  15. public:
  16. Session();
  17. ~Session();
  18. void showHelp() const;
  19. void libIdentify();
  20. int applyCommandLine( int argc, char const * const * argv );
  21. #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
  22. int applyCommandLine( int argc, wchar_t const * const * argv );
  23. #endif
  24. void useConfigData( ConfigData const& configData );
  25. template<typename CharT>
  26. int run(int argc, CharT const * const argv[]) {
  27. if (m_startupExceptions)
  28. return 1;
  29. int returnCode = applyCommandLine(argc, argv);
  30. if (returnCode == 0)
  31. returnCode = run();
  32. return returnCode;
  33. }
  34. int run();
  35. Clara::Parser const& cli() const;
  36. void cli( Clara::Parser const& newParser );
  37. ConfigData& configData();
  38. Config& config();
  39. private:
  40. int runInternal();
  41. Clara::Parser m_cli;
  42. ConfigData m_configData;
  43. Detail::unique_ptr<Config> m_config;
  44. bool m_startupExceptions = false;
  45. };
  46. } // end namespace Catch
  47. #endif // CATCH_SESSION_HPP_INCLUDED