Coverage Report

Created: 2023-12-13 14:58

test/zserio/deprecated_attribute/DeprecatedAttributeTest.cpp
Line
Count
Source
1
#include "gtest/gtest.h"
2
3
#include <fstream>
4
#include <regex>
5
6
class DeprecatedAttributeTest : public ::testing::Test
7
{
8
protected:
9
    bool matchInFile(const std::string& fileName, const std::regex& lineRegex)
10
2
    {
11
2
        std::ifstream file(fileName.c_str());
12
13
2
        bool isPresent = false;
14
2
        std::string line;
15
12
        while (std::getline(file, line))
16
11
        {
17
11
            if (std::regex_search(line, lineRegex))
18
1
            {
19
1
                isPresent = true;
20
1
                break;
21
1
            }
22
11
        }
23
2
        file.close();
24
25
2
        return isPresent;
26
2
    }
27
28
    static const char* const ERROR_LOG_PATH;
29
};
30
31
const char* const DeprecatedAttributeTest::ERROR_LOG_PATH =
32
        "zserio/deprecated_attribute/src/DeprecatedAttribute-stamp/DeprecatedAttribute-build-"
33
#if defined(DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS) && DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS == 1
34
        "out"
35
#else
36
        "err"
37
#endif
38
        ".log";
39
40
TEST_F(DeprecatedAttributeTest, checkWarnings)
41
1
{
42
1
#if defined(DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS) && DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS != 0
43
1
    ASSERT_FALSE(matchInFile(ERROR_LOG_PATH, std::regex("Unknown warning to check matchInFile method!")));
44
2
    ASSERT_TRUE(matchInFile(ERROR_LOG_PATH,
45
2
            std::regex("DeprecatedAttribute\\.cpp.*15.*81.*warning.*FIVE.*deprecated"))) <<
46
2
            "Warning not found in '" << ERROR_LOG_PATH << "'!";
47
1
#endif
48
1
}