aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/logging/unittests/static_analysis_ut.cpp
blob: e1bef7aaa9748e2481d29da6cfb34e79ae330c1e (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
#include <library/cpp/testing/gtest/gtest.h>

#include <library/cpp/yt/logging/logger.h>

namespace NYT::NLogging {
namespace {

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

TEST(TStaticAnalysisTest, ValidFormats)
{
    // Mock for actual error -- we only care that
    // it is some runtime object.
    [[maybe_unused]] struct TError
    { } error;

    YT_LOG_CHECK_FORMAT("Hello");
    YT_LOG_CHECK_FORMAT("Hello %v", "World!");
    YT_LOG_CHECK_FORMAT("Hello %qv", "World!");
    YT_LOG_CHECK_FORMAT(error);
    YT_LOG_CHECK_FORMAT(error, "Hello");
    YT_LOG_CHECK_FORMAT(error, "Hello %Qhs", "World!");
    YT_LOG_CHECK_FORMAT("Hello %%");
    YT_LOG_CHECK_FORMAT("Hello %" PRIu64, 42);
}

// Uncomment this test to see that we don't have false negatives!
// TEST(TStaticAnalysisTest, InvalidFormats)
// {
//     YT_LOG_CHECK_FORMAT("Hello", 1);
//     YT_LOG_CHECK_FORMAT("Hello %");
//     YT_LOG_CHECK_FORMAT("Hello %false");
//     YT_LOG_CHECK_FORMAT("Hello ", "World");
//     YT_LOG_CHECK_FORMAT("Hello ", "(World: %v)", 42);
//     YT_LOG_CHECK_FORMAT("Hello %lbov", 42); // There is no 'b' flag.
// }

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

} // namespace
} // namespace NYT::NLogging