expected-main.t.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2016-2018 Martin Moene
  2. //
  3. // https://github.com/martinmoene/expected-lite
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #pragma once
  8. #ifndef TEST_EXPECTED_LITE_H_INCLUDED
  9. #define TEST_EXPECTED_LITE_H_INCLUDED
  10. // Limit C++ Core Guidelines checking to expected-lite:
  11. #include "nonstd/expected.hpp"
  12. #if nsel_COMPILER_MSVC_VER >= 1910
  13. # include <CppCoreCheck/Warnings.h>
  14. # pragma warning(disable: ALL_CPPCORECHECK_WARNINGS)
  15. #endif
  16. #include <iosfwd>
  17. namespace lest {
  18. template< typename T, typename E >
  19. std::ostream & operator<<( std::ostream & os, nonstd::expected<T,E> const & );
  20. template< typename E >
  21. std::ostream & operator<<( std::ostream & os, nonstd::expected<void,E> const & );
  22. } // namespace lest
  23. // Compiler warning suppression for usage of lest:
  24. #ifdef __clang__
  25. # pragma clang diagnostic ignored "-Wstring-conversion"
  26. # pragma clang diagnostic ignored "-Wunused-parameter"
  27. # pragma clang diagnostic ignored "-Wunused-template"
  28. # pragma clang diagnostic ignored "-Wunused-function"
  29. # pragma clang diagnostic ignored "-Wunused-member-function"
  30. #elif defined __GNUC__
  31. # pragma GCC diagnostic ignored "-Wunused-parameter"
  32. # pragma GCC diagnostic ignored "-Wunused-function"
  33. #endif
  34. #include "lest.hpp"
  35. #define CASE( name ) lest_CASE( specification(), name )
  36. extern lest::tests & specification();
  37. namespace lest {
  38. // use oparator<< instead of to_string() overload;
  39. // see http://stackoverflow.com/a/10651752/437272
  40. template< typename T, typename E >
  41. inline std::ostream & operator<<( std::ostream & os, nonstd::expected<T,E> const & v )
  42. {
  43. using lest::to_string;
  44. return os << "[expected:" << (v ? to_string(*v) : "[empty]") << "]";
  45. }
  46. template< typename E >
  47. inline std::ostream & operator<<( std::ostream & os, nonstd::expected<void,E> const & v )
  48. {
  49. using lest::to_string;
  50. return os << "[expected<void>:" << (v ? "[non-empty]" : "[empty]") << "]";
  51. }
  52. } // namespace lest
  53. #endif // TEST_EXPECTED_LITE_H_INCLUDED
  54. // end of file