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

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

namespace NYT::NLogging {
namespace {

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

const TLogger Logger{};

TEST(TStaticAnalysisTest, ValidFormats)
{
    YT_LOG_INFO("Hello");
    YT_LOG_INFO("Hello %v", "World!");
    YT_LOG_INFO("Hello %qv", "World!");
    YT_LOG_INFO(42);
    YT_LOG_INFO("Hello %%");
    YT_LOG_INFO("Hello %" PRIu64, 42);

    TStringBuf msg = "Hello";
    YT_LOG_INFO(msg);
}

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

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

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