Skip to content

Commit

Permalink
Fix CI with MSVC and fix #70
Browse files Browse the repository at this point in the history
  • Loading branch information
cschreib committed Feb 2, 2023
1 parent f6fe927 commit 0af27ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
16 changes: 16 additions & 0 deletions include/snitch/snitch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,21 +1373,25 @@ bool operator==(const M& m, const T& value) noexcept {
# define SNITCH_WARNING_POP _Pragma("clang diagnostic pop")
# define SNITCH_WARNING_DISABLE_PARENTHESES _Pragma("clang diagnostic ignored \"-Wparentheses\"")
# define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON
# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
#elif defined(__GNUC__)
# define SNITCH_WARNING_PUSH _Pragma("GCC diagnostic push")
# define SNITCH_WARNING_POP _Pragma("GCC diagnostic pop")
# define SNITCH_WARNING_DISABLE_PARENTHESES _Pragma("GCC diagnostic ignored \"-Wparentheses\"")
# define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON
# define SNITCH_WARNING_DISABLE_UNREACHABLE
#elif defined(_MSC_VER)
# define SNITCH_WARNING_PUSH _Pragma("warning(push)")
# define SNITCH_WARNING_POP _Pragma("warning(pop)")
# define SNITCH_WARNING_DISABLE_PARENTHESES
# define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON _Pragma("warning(disable: 4127)")
# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("warning(disable: 4702)")
#else
# define SNITCH_WARNING_PUSH
# define SNITCH_WARNING_POP
# define SNITCH_WARNING_DISABLE_PARENTHESES
# define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON
# define SNITCH_WARNING_DISABLE_UNREACHABLE
#endif
// clang-format on

Expand Down Expand Up @@ -1692,6 +1696,8 @@ bool operator==(const M& m, const T& value) noexcept {

# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) \
do { \
SNITCH_WARNING_PUSH \
SNITCH_WARNING_DISABLE_UNREACHABLE \
auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \
try { \
++SNITCH_CURRENT_TEST.asserts; \
Expand All @@ -1717,10 +1723,13 @@ bool operator==(const M& m, const T& value) noexcept {
} \
SNITCH_TESTING_ABORT; \
} \
SNITCH_WARNING_POP \
} while (0)

# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) \
do { \
SNITCH_WARNING_PUSH \
SNITCH_WARNING_DISABLE_UNREACHABLE \
auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \
try { \
++SNITCH_CURRENT_TEST.asserts; \
Expand All @@ -1744,10 +1753,13 @@ bool operator==(const M& m, const T& value) noexcept {
#__VA_ARGS__ " expected but other unknown exception thrown"); \
} \
} \
SNITCH_WARNING_POP \
} while (0)

# define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \
do { \
SNITCH_WARNING_PUSH \
SNITCH_WARNING_DISABLE_UNREACHABLE \
auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \
try { \
++SNITCH_CURRENT_TEST.asserts; \
Expand Down Expand Up @@ -1781,10 +1793,13 @@ bool operator==(const M& m, const T& value) noexcept {
} \
SNITCH_TESTING_ABORT; \
} \
SNITCH_WARNING_POP \
} while (0)

# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \
do { \
SNITCH_WARNING_PUSH \
SNITCH_WARNING_DISABLE_UNREACHABLE \
auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \
try { \
++SNITCH_CURRENT_TEST.asserts; \
Expand Down Expand Up @@ -1815,6 +1830,7 @@ bool operator==(const M& m, const T& value) noexcept {
#EXCEPTION " expected but other unknown exception thrown"); \
} \
} \
SNITCH_WARNING_POP \
} while (0)

// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime_tests/macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct test_exception : std::exception {

template<std::size_t i, std::size_t j, std::size_t k>
int foo() {
if (i != j || i != k) {
if constexpr (i != j || i != k) {
return 0;
} else {
#if SNITCH_WITH_EXCEPTIONS
Expand Down
4 changes: 0 additions & 4 deletions tests/testing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,19 @@ struct filldata<T*> {
#endif

#if defined(__clang__)
# define SNITCH_WARNING_DISABLE_UNREACHABLE
# define SNITCH_WARNING_DISABLE_INT_BOOLEAN
# define SNITCH_WARNING_DISABLE_PRECEDENCE
# define SNITCH_WARNING_DISABLE_ASSIGNMENT
#elif defined(__GNUC__)
# define SNITCH_WARNING_DISABLE_UNREACHABLE
# define SNITCH_WARNING_DISABLE_INT_BOOLEAN \
_Pragma("GCC diagnostic ignored \"-Wint-in-bool-context\"")
# define SNITCH_WARNING_DISABLE_PRECEDENCE
# define SNITCH_WARNING_DISABLE_ASSIGNMENT
#elif defined(_MSC_VER)
# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("warning(disable: 4702)")
# define SNITCH_WARNING_DISABLE_INT_BOOLEAN
# define SNITCH_WARNING_DISABLE_PRECEDENCE _Pragma("warning(disable: 4554)")
# define SNITCH_WARNING_DISABLE_ASSIGNMENT _Pragma("warning(disable: 4706)")
#else
# define SNITCH_WARNING_DISABLE_UNREACHABLE
# define SNITCH_WARNING_DISABLE_INT_BOOLEAN
# define SNITCH_WARNING_DISABLE_PRECEDENCE
# define SNITCH_WARNING_DISABLE_ASSIGNMENT
Expand Down

0 comments on commit 0af27ac

Please sign in to comment.