-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#486] Implement deprecated attribute test in C++ runtime
- Loading branch information
Showing
7 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
compiler/extensions/cpp/runtime/test/zserio/deprecated_attribute/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
cmake_minimum_required(VERSION 3.6.0) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_add(DeprecatedAttribute | ||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}" | ||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" | ||
LOG_CONFIGURE 1 | ||
LOG_BUILD 1 | ||
INSTALL_COMMAND "" | ||
CMAKE_ARGS | ||
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} | ||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
) | ||
|
||
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
# 0 - don't check | ||
# 1 - check in stdout | ||
# 2 - check in stderr | ||
set(ENABLE_CHECK_WARNINGS 0) | ||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") | ||
set(ENABLE_CHECK_WARNINGS 2) | ||
endif () | ||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") | ||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0.0") | ||
set(ENABLE_CHECK_WARNINGS 2) | ||
endif () | ||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") | ||
if (NOT MSVC_VERSION LESS 1920) # at least MSVC 2019, toolset v142 | ||
set(ENABLE_CHECK_WARNINGS 1) | ||
endif () | ||
endif () | ||
set(DEPRECATED_ATTRIBUTE_COMPILE_DEFINITIONS | ||
"DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS=${ENABLE_CHECK_WARNINGS}" PARENT_SCOPE) |
47 changes: 47 additions & 0 deletions
47
compiler/extensions/cpp/runtime/test/zserio/deprecated_attribute/DeprecatedAttributeTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include <fstream> | ||
#include <regex> | ||
|
||
class DeprecatedAttributeTest : public ::testing::Test | ||
{ | ||
protected: | ||
bool matchInFile(const std::string& fileName, const std::regex& lineRegex) | ||
{ | ||
std::ifstream file(fileName.c_str()); | ||
|
||
bool isPresent = false; | ||
std::string line; | ||
while (std::getline(file, line)) | ||
{ | ||
if (std::regex_search(line, lineRegex)) | ||
{ | ||
isPresent = true; | ||
break; | ||
} | ||
} | ||
file.close(); | ||
|
||
return isPresent; | ||
} | ||
|
||
static const char* ERROR_LOG_PATH; | ||
}; | ||
|
||
const char* DeprecatedAttributeTest::ERROR_LOG_PATH = | ||
"zserio/deprecated_attribute/src/DeprecatedAttribute-stamp/DeprecatedAttribute-build-" | ||
#if defined(DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS) && DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS == 1 | ||
"out" | ||
#else | ||
"err" | ||
#endif | ||
".log"; | ||
|
||
TEST_F(DeprecatedAttributeTest, checkWarnings) | ||
{ | ||
#if defined(DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS) && DEPRECATED_ATTRIBUTE_TEST_CHECK_WARNINGS != 0 | ||
ASSERT_TRUE(matchInFile(ERROR_LOG_PATH, | ||
std::regex("DeprecatedAttribute\\.cpp.*15.*81.*warning.*FIVE.*deprecated"))) << | ||
"Warning not found in '" << ERROR_LOG_PATH << "'!"; | ||
#endif | ||
} |
15 changes: 15 additions & 0 deletions
15
compiler/extensions/cpp/runtime/test/zserio/deprecated_attribute/src/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.6.0) | ||
|
||
project(DeprecatedAttribute) | ||
|
||
set(ZSERIO_PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../..") | ||
set(CMAKE_MODULE_PATH "${ZSERIO_PROJECT_ROOT}/cmake") | ||
|
||
include(cmake_utils) | ||
include(compiler_utils) | ||
|
||
compiler_set_warnings() | ||
|
||
add_executable(${PROJECT_NAME} DeprecatedAttribute.cpp) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ../../../../src) |
16 changes: 16 additions & 0 deletions
16
compiler/extensions/cpp/runtime/test/zserio/deprecated_attribute/src/DeprecatedAttribute.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <type_traits> | ||
|
||
#include "zserio/DeprecatedAttribute.h" | ||
|
||
enum TestEnum | ||
{ | ||
ONE = 1, | ||
TWO, | ||
THREE ZSERIO_DEPRECATED, | ||
FIVE ZSERIO_DEPRECATED = 5 | ||
}; | ||
|
||
int main(int, char*[]) | ||
{ | ||
return static_cast<typename std::underlying_type<TestEnum>::type>(TestEnum::FIVE) - 5; | ||
} |