Skip to content

Commit

Permalink
minor changes to noarr-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jiriklepl committed Jul 20, 2024
1 parent 5f6431f commit 6280101
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions tests/noarr-test/include/noarr_test/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool test_case_failed = false;

#define REQUIRE(...) \
do if (!(__VA_ARGS__)) { \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: REQUIRE(" #__VA_ARGS__ ") failed" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: REQUIRE(" #__VA_ARGS__ ") failed\n"; \
noarr_test::assertion_failed(); \
noarr_test::test_case_failed = true; \
throw noarr_test::requirement_failed{}; \
Expand All @@ -36,7 +36,7 @@ bool test_case_failed = false;
do { \
const bool cond = [](auto cond) constexpr { return std::is_constant_evaluated() ? cond : true; }(!(__VA_ARGS__)); \
if (cond) { \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: STATIC_REQUIRE(" #__VA_ARGS__ ") failed" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: STATIC_REQUIRE(" #__VA_ARGS__ ") failed\n"; \
noarr_test::assertion_failed(); \
noarr_test::test_case_failed = true; \
throw noarr_test::requirement_failed{}; \
Expand All @@ -47,7 +47,7 @@ bool test_case_failed = false;

#define CHECK(...) \
do if (!(__VA_ARGS__)) { \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: CHECK(" #__VA_ARGS__ ") failed" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: CHECK(" #__VA_ARGS__ ") failed\n"; \
noarr_test::assertion_failed(); \
noarr_test::test_case_failed = true; \
} else { \
Expand All @@ -58,24 +58,24 @@ bool test_case_failed = false;
if (struct CONCATENATE(test_case_section_, __LINE__) { \
~CONCATENATE(test_case_section_, __LINE__)() { \
if (noarr_test::test_case_failed) \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": message: in SECTION(" #__VA_ARGS__ ")" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": message: in SECTION(" #__VA_ARGS__ ")\n"; \
} \
} CONCATENATE(test_case_section_instance_, __LINE__); false) ; else

#define TEST_CASE(...) \
static void CONCATENATE(test_case_function_, __LINE__)(); \
namespace { \
struct CONCATENATE(test_case_struct_, __LINE__) { \
const struct CONCATENATE(test_case_struct_, __LINE__) { \
CONCATENATE(test_case_struct_, __LINE__)() { \
noarr_test::test_case_failed = false; \
try { CONCATENATE(test_case_function_, __LINE__)(); } \
catch (const noarr_test::requirement_failed&) { noarr_test::test_case_failed = true; } \
catch (...) { \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: unexpected exception" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": error: unexpected exception\n"; \
noarr_test::test_case_failed = true; \
} \
if (noarr_test::test_case_failed) { \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": message: in TEST_CASE(" #__VA_ARGS__ ")" << std::endl; \
std::cerr << __FILE__ ":" TO_STRING(__LINE__) ": message: in TEST_CASE(" #__VA_ARGS__ ")\n"; \
noarr_test::test_failed(); \
} else { \
noarr_test::test_passed(); \
Expand Down
10 changes: 4 additions & 6 deletions tests/noarr-test/src/noarr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using namespace noarr_test;

int main() {
std::cerr << "Tests: " << test_counter_t::test_success << std::endl;
std::cerr << "Failures: " << test_counter_t::test_failure << std::endl;
std::cerr << "Tests: " << test_counter_t::test_success << "\n";
std::cerr << "Failures: " << test_counter_t::test_failure << "\n";

std::cerr << std::endl;

std::cerr << "Assertions: " << test_counter_t::assertion_success << std::endl;
std::cerr << "Failures: " << test_counter_t::assertion_failure << std::endl;
std::cerr << "Assertions: " << test_counter_t::assertion_success << "\n";
std::cerr << "Failures: " << test_counter_t::assertion_failure << "\n";

if (test_counter_t::test_failure > 0) {
return 1;
Expand Down

0 comments on commit 6280101

Please sign in to comment.