Skip to content

Commit

Permalink
Add clang-format to the C++ test project
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Jan 9, 2024
1 parent 9f8ebde commit 3365f61
Show file tree
Hide file tree
Showing 352 changed files with 2,115 additions and 2,787 deletions.
22 changes: 20 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enable_testing()
set(CPPCHECK_HOME "" CACHE PATH "Home directory of cppcheck tool. If empty, cppcheck tool is not called.")
set(SANITIZERS_ENABLED OFF CACHE BOOL "Whether the compiler sanitizers are enabled.")
set(CLANG_TIDY_BIN "" CACHE STRING "Name of clang-tidy binary. If empty, clang-tidy tool is not called.")
set(CLANG_FORMAT_BIN "" CACHE STRING "Name of clang-format binary. If empty, clang-format tool is not called.")

set(ZSERIO_PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(ZSERIO_RELEASE_ROOT "${ZSERIO_PROJECT_ROOT}/distr" CACHE PATH "Root directory of Zserio release binaries.")
Expand All @@ -25,6 +26,7 @@ set(CMAKE_MODULE_PATH ${ZSERIO_PROJECT_ROOT}/cmake)
# cmake helpers
include(cmake_utils)
include(clang_tidy_utils)
include(clang_format_utils)
include(cppcheck_utils)

# setup compiler
Expand All @@ -36,6 +38,10 @@ compiler_set_static_clibs()
if (SANITIZERS_ENABLED)
compiler_set_address_sanitizer()
endif ()

# add test utility library
add_subdirectory(utils/cpp/test_utils test_utils)

# add gtest library
include(gtest_utils)
gtest_add_library(${ZSERIO_PROJECT_ROOT}/3rdparty/cpp/googletest)
Expand Down Expand Up @@ -93,6 +99,18 @@ function(add_custom_test TEST_NAME)
HEADER_FILTER
"${CMAKE_CURRENT_SOURCE_DIR}/.*|${CMAKE_CURRENT_BINARY_DIR}/.*")

if (DEFINED TEST_ARG_SOURCES)
clang_format_add_custom_target(${TEST_NAME}-clang-format
DEPENDS
${TEST_NAME}
SOURCES
"${TEST_ARG_SOURCES}"
CONFIG_FILE
"${ZSERIO_PROJECT_ROOT}/.clang-format"
WERROR
ON)
endif ()

get_generated_dirs("${TEST_ARG_GENERATED_SOURCES}" GENERATED_DIRS)
cppcheck_add_custom_command(TARGET ${TEST_NAME}
SOURCE_DIR
Expand Down Expand Up @@ -137,8 +155,8 @@ endif ()

# add_executable requieres at least a single source file
add_executable(${PROJECT_NAME} ${TEST_SOURCES_LIST})
target_link_libraries(${PROJECT_NAME} ${TEST_DEPENDENCIES_LIST} gtest_main ZserioCppRuntime ${SQLITE_LIBRARY})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/utils/cpp)
target_link_libraries(${PROJECT_NAME} ${TEST_DEPENDENCIES_LIST} gtest_main ZserioCppTestUtils ZserioCppRuntime
${SQLITE_LIBRARY})
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${SQLITE_INCDIR})

# add tests - test are labeled by file names (i.e. grouped)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/implicit_array_bit8/ImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/SerializeUtil.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/implicit_array_float16/ImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/SerializeUtil.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/implicit_array_int24/ImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/SerializeUtil.h"

Expand Down Expand Up @@ -113,5 +111,5 @@ TEST_F(ImplicitArrayInt24Test, writeReadFile)
ASSERT_EQ(static_cast<int32_t>(i), readArray[i]);
}

} // namespace implicit_array_bit8
} // namespace implicit_array_int24
} // namespace allow_implicit_arrays
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/implicit_array_uint64/ImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/SerializeUtil.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/implicit_array_uint8/ImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/SerializeUtil.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "gtest/gtest.h"

#include "allow_implicit_arrays/lengthof_with_implicit_array/LengthOfWithImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"

namespace allow_implicit_arrays
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include <cstdio>
#include <string>
#include <fstream>

#include "gtest/gtest.h"
#include <string>

#include "allow_implicit_arrays/table_with_implicit_array/DbWithImplicitArray.h"

#include "gtest/gtest.h"
#include "zserio/RebindAlloc.h"
#include "zserio/StringConvertUtil.h"

Expand Down
Loading

0 comments on commit 3365f61

Please sign in to comment.