yassert_ut.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #undef NDEBUG
  2. // yassert.h must be included before all headers
  3. #include "yassert.h"
  4. #include <library/cpp/testing/unittest/registar.h>
  5. Y_UNIT_TEST_SUITE(YassertTest) {
  6. Y_UNIT_TEST(TestAcsLikeFunctionCall) {
  7. if (true) {
  8. Y_ASSERT(true); // this cannot be compiled if Y_ASSERT is "if (!cond) { ... }"
  9. } else {
  10. Y_ASSERT(false);
  11. }
  12. bool var = false;
  13. if (false) {
  14. Y_ASSERT(false);
  15. } else {
  16. var = true; // this is unreachable if Y_ASSERT is "if (!cond) { ... }"
  17. }
  18. UNIT_ASSERT(var);
  19. }
  20. Y_UNIT_TEST(TestFailCompiles) {
  21. if (false) {
  22. Y_ABORT("%d is a lucky number", 7);
  23. Y_ABORT();
  24. }
  25. }
  26. Y_UNIT_TEST(TestVerify) {
  27. Y_ABORT_UNLESS(true, "hi %s", "there");
  28. Y_ABORT_UNLESS(true);
  29. }
  30. Y_UNIT_TEST(TestExceptionVerify) {
  31. UNIT_ASSERT_EXCEPTION(
  32. []() { Y_ABORT_UNLESS([]() {throw yexception{} << "check"; return false; }(), "hi %s", "there"); }(),
  33. yexception);
  34. }
  35. } // Y_UNIT_TEST_SUITE(YassertTest)