yassert_ut.cpp 847 B

1234567891011121314151617181920212223242526272829303132333435
  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_FAIL("%d is a lucky number", 7);
  23. Y_FAIL();
  24. }
  25. }
  26. Y_UNIT_TEST(TestVerify) {
  27. Y_VERIFY(true, "hi %s", "there");
  28. Y_VERIFY(true);
  29. }
  30. }