summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/assert/unittests/assert_ut.cpp
blob: 102f82618b1bef211778e5712353e7e840a153ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <yt/yt/core/test_framework/framework.h>

#include <library/cpp/yt/assert/assert.h>

namespace NYT {
namespace {

////////////////////////////////////////////////////////////////////////////////

TEST(TAssertTest, Abort)
{
    EXPECT_DEATH(
        {
            YT_ABORT();
        },
        "YT_ABORT");

    EXPECT_DEATH(
        {
            YT_ABORT("MY_PROBLEM");
        },
        "MY_PROBLEM");
}

TEST(TAssertTest, Verify)
{
    YT_VERIFY(true);
    YT_VERIFY(true, "12345");
    YT_VERIFY(true, [] {
        YT_ABORT();
        return "NEVER_PRINTED";
    } ());
    EXPECT_DEATH(
        {
            YT_VERIFY(false);
        },
        "YT_VERIFY");
    EXPECT_DEATH(
        {
            YT_VERIFY(false, "MY_MESSAGE");
        },
        "YT_VERIFY.*MY_MESSAGE");
    EXPECT_DEATH(
        {
            YT_VERIFY(false && "my_specific_expression_part", "MY_MESSAGE");
        },
        "false && \"my_specific_expression_part\"");
}

TEST(TAssertTest, Assert)
{
    YT_ASSERT(true);
    YT_ASSERT(true, [] {
        YT_ABORT();
        return "NEVER_PRINTED";
    } ());
    #ifndef NDEBUG
    EXPECT_DEATH(
        {
            YT_ASSERT(false);
        },
        "YT_ASSERT");
    EXPECT_DEATH(
        {
            YT_ASSERT(false, "MY_MESSAGE");
        },
        "MY_MESSAGE");
    EXPECT_DEATH(
        {
            YT_ASSERT(false && "my_specific_expression_part", "MY_MESSAGE");
        },
        "my_specific_expression_part");
    #endif
}

TEST(TAssertTest, Unimplemented)
{
    EXPECT_DEATH(
        {
            YT_UNIMPLEMENTED();
        },
        "YT_UNIMPLEMENTED");
}

TEST(TAssertTest, AcceptString)
{
    EXPECT_DEATH(
        {
            YT_ABORT(std::string("MY_PROBLEM"));
        },
        "MY_PROBLEM");
}


////////////////////////////////////////////////////////////////////////////////

} // namespace
} // namespace NYT