expected-main.t.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "expected-main.t.hpp"
  8. #define expected_PRESENT( x ) \
  9. std::cout << #x << ": " << x << "\n"
  10. #define expected_ABSENT( x ) \
  11. std::cout << #x << ": (undefined)\n"
  12. // Suppress:
  13. // - unused parameter, for cases without assertions such as [.std...]
  14. #if defined(__clang__)
  15. # pragma clang diagnostic ignored "-Wunused-parameter"
  16. #elif defined __GNUC__
  17. # pragma GCC diagnostic ignored "-Wunused-parameter"
  18. #endif
  19. lest::tests & specification()
  20. {
  21. static lest::tests tests;
  22. return tests;
  23. }
  24. CASE( "expected-lite version" "[.expected][.version]" )
  25. {
  26. expected_PRESENT( expected_lite_MAJOR );
  27. expected_PRESENT( expected_lite_MINOR );
  28. expected_PRESENT( expected_lite_PATCH );
  29. expected_PRESENT( expected_lite_VERSION );
  30. }
  31. CASE( "any configuration" "[.expected][.config]" )
  32. {
  33. expected_PRESENT( nsel_HAVE_STD_EXPECTED );
  34. expected_PRESENT( nsel_USES_STD_EXPECTED );
  35. expected_PRESENT( nsel_EXPECTED_DEFAULT );
  36. expected_PRESENT( nsel_EXPECTED_NONSTD );
  37. expected_PRESENT( nsel_EXPECTED_STD );
  38. expected_PRESENT( nsel_CONFIG_SELECT_EXPECTED );
  39. expected_PRESENT( nsel_CONFIG_NO_EXCEPTIONS );
  40. expected_PRESENT( nsel_CPLUSPLUS );
  41. }
  42. CASE( "__cplusplus" "[.stdc++]" )
  43. {
  44. expected_PRESENT( __cplusplus );
  45. #ifdef _MSVC_LANG
  46. expected_PRESENT( _MSVC_LANG );
  47. #else
  48. expected_ABSENT( _MSVC_LANG );
  49. #endif
  50. }
  51. CASE( "Compiler version" "[.compiler]" )
  52. {
  53. #if nsel_USES_STD_EXPECTED
  54. std::cout << "(Compiler version not available: using std::expected)\n";
  55. #else
  56. expected_PRESENT( nsel_COMPILER_CLANG_VERSION );
  57. expected_PRESENT( nsel_COMPILER_GNUC_VERSION );
  58. expected_PRESENT( nsel_COMPILER_MSVC_VERSION );
  59. #endif
  60. }
  61. CASE( "presence of C++ language features" "[.stdlanguage]" )
  62. {
  63. #if nsel_USES_STD_EXPECTED
  64. std::cout << "(Presence of C++ language features not available: using std::expected)\n";
  65. #else
  66. std::cout << "[.stdlanguage]: none\n";
  67. #endif
  68. }
  69. CASE( "presence of C++ library features" "[.stdlibrary]" )
  70. {
  71. #if nsel_USES_STD_EXPECTED
  72. std::cout << "(Presence of C++ library features not available: using std::expected)\n";
  73. #else
  74. #ifdef __cpp_exceptions
  75. expected_PRESENT( __cpp_exceptions );
  76. #else
  77. expected_ABSENT( __cpp_exceptions );
  78. #endif
  79. #ifdef __EXCEPTIONS
  80. expected_PRESENT( __EXCEPTIONS );
  81. #else
  82. expected_ABSENT( __EXCEPTIONS );
  83. #endif
  84. #ifdef _HAS_EXCEPTIONS
  85. expected_PRESENT( _HAS_EXCEPTIONS );
  86. #else
  87. expected_ABSENT( _HAS_EXCEPTIONS );
  88. #endif
  89. #ifdef _CPPUNWIND
  90. expected_PRESENT( _CPPUNWIND );
  91. #else
  92. expected_ABSENT( _CPPUNWIND );
  93. #endif
  94. #endif
  95. }
  96. int main( int argc, char * argv[] )
  97. {
  98. return lest::run( specification(), argc, argv );
  99. }
  100. #if 0
  101. g++ -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  102. g++ -std=c++98 -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  103. g++ -std=c++03 -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  104. g++ -std=c++0x -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  105. g++ -std=c++11 -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  106. g++ -std=c++14 -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  107. g++ -std=c++17 -I../include -o expected-lite.t.exe expected-lite.t.cpp && expected-lite.t.exe --pass
  108. cl -EHsc -I../include expected-lite.t.cpp && expected-lite.t.exe --pass
  109. #endif
  110. // end of file