xref: /aosp_15_r20/external/fmtlib/test/assert-test.cc (revision 5c90c05cd622c0a81b57953a4d343e0e489f2e08)
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 
12 #include "fmt/base.h"
13 #include "gtest/gtest.h"
14 
TEST(assert_test,fail)15 TEST(assert_test, fail) {
16 #if GTEST_HAS_DEATH_TEST
17   EXPECT_DEBUG_DEATH(FMT_ASSERT(false, "don't panic!"), "don't panic!");
18 #else
19   fmt::print("warning: death tests are not supported\n");
20 #endif
21 }
22 
TEST(assert_test,dangling_else)23 TEST(assert_test, dangling_else) {
24   bool test_condition = false;
25   bool executed_else = false;
26   if (test_condition)
27     FMT_ASSERT(true, "");
28   else
29     executed_else = true;
30   EXPECT_TRUE(executed_else);
31 }
32