assert-test.cc 852 B

12345678910111213141516171819202122232425262728293031
  1. // Formatting library for C++ - FMT_ASSERT test
  2. //
  3. // It is a separate test to minimize the number of EXPECT_DEBUG_DEATH checks
  4. // which are slow on some platforms. In other tests FMT_ASSERT is made to throw
  5. // an exception which is much faster and easier to check.
  6. //
  7. // Copyright (c) 2012 - present, Victor Zverovich
  8. // All rights reserved.
  9. //
  10. // For the license information refer to format.h.
  11. #include "fmt/core.h"
  12. #include "gtest/gtest.h"
  13. TEST(assert_test, fail) {
  14. #if GTEST_HAS_DEATH_TEST
  15. EXPECT_DEBUG_DEATH(FMT_ASSERT(false, "don't panic!"), "don't panic!");
  16. #else
  17. fmt::print("warning: death tests are not supported\n");
  18. #endif
  19. }
  20. TEST(assert_test, dangling_else) {
  21. bool test_condition = false;
  22. bool executed_else = false;
  23. if (test_condition)
  24. FMT_ASSERT(true, "");
  25. else
  26. executed_else = true;
  27. EXPECT_TRUE(executed_else);
  28. }