Move boost::tests to Google Tests. [#CLICKHOUSE-2]

This commit is contained in:
Vitaliy Lyudvichenko 2017-03-22 19:59:02 +03:00 committed by alexey-milovidov
parent a1e27e2b84
commit 2ab25099cd
9 changed files with 48 additions and 73 deletions

View File

@ -130,14 +130,10 @@ if (TEST_COVERAGE)
set (CMAKE_CXX_FLAGS_DEBUG "${COMPILER_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage -fPIC -DIS_DEBUG")
endif (TEST_COVERAGE)
# Run tests with "make check"
if (ENABLE_TESTS)
message (STATUS "Tests are enabled")
if (TARGET check)
message (STATUS "Target check already exists")
else ()
include (cmake/add_check.cmake)
endif ()
enable_testing()
add_subdirectory (dbms/tests)
endif (ENABLE_TESTS)
# Installation prefix
@ -148,7 +144,6 @@ else ()
set (CLICKHOUSE_ETC_DIR ${CMAKE_INSTALL_PREFIX}/etc)
endif ()
option (UNBUNDLED "Try find all libraries in system (if fail - use bundled from contrib/)" OFF)
if (UNBUNDLED)
set(NOT_UNBUNDLED 0)

View File

@ -1,15 +1,17 @@
# Adding test output on failure
enable_testing ()
if (CMAKE_CONFIGURATION_TYPES)
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
--force-new-ctest-process --output-on-failure --build-config "$<CONFIGURATION>"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
else ()
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
--force-new-ctest-process --output-on-failure
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif ()
macro (add_check target)
add_test (NAME test_${target} COMMAND ${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
#add_dependencies (check ${target})
add_dependencies (check ${target})
endmacro (add_check)

View File

@ -45,10 +45,3 @@ endif ()
if (NOT AARCH64)
add_subdirectory (libcpuid)
endif ()
if (ENABLE_TESTS)
add_subdirectory (googletest)
# avoid problems with <regexp.h>
target_compile_definitions (gtest INTERFACE -DGTEST_HAS_POSIX_RE=0)
target_include_directories (gtest INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/googletest/include)
endif()

View File

@ -33,7 +33,6 @@ endif ()
find_package (Threads)
add_subdirectory (src)
add_subdirectory (tests)
add_library(string_utils
include/DB/Common/StringUtils.h
@ -174,3 +173,11 @@ target_link_libraries(dbms
target_include_directories (dbms
INTERFACE include
)
if (ENABLE_TESTS)
# attach all dbms gtest sources
grep_gtest_sources(${ClickHouse_SOURCE_DIR}/dbms dbms_gtest_sources)
add_executable(unit_tests_dbms ${dbms_gtest_sources})
target_link_libraries(unit_tests_dbms gtest_main dbms)
add_check(unit_tests_dbms)
endif()

View File

@ -1,8 +1,4 @@
if (NOT ENABLE_TESTS)
return()
endif()
message (STATUS "Tests are enabled")
enable_testing()
# Run tests with "make check"
if (TARGET check)
@ -11,4 +7,15 @@ else ()
include (${ClickHouse_SOURCE_DIR}/cmake/add_check.cmake)
endif ()
add_subdirectory (unit_tests)
# Google Test from sources
add_subdirectory(${ClickHouse_SOURCE_DIR}/contrib/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest)
# avoid problems with <regexp.h>
target_compile_definitions (gtest INTERFACE -DGTEST_HAS_POSIX_RE=0)
target_include_directories (gtest INTERFACE ${ClickHouse_SOURCE_DIR}/contrib/googletest/include)
macro(grep_gtest_sources BASE_DIR DST_VAR)
# not CMake-way
execute_process(COMMAND find "${BASE_DIR}" -path "*/tests/gtest*.cpp" -printf "%p;" OUTPUT_VARIABLE ${DST_VAR})
endmacro()

View File

@ -1,10 +0,0 @@
# Google Test unit tests
# gather all **/gtest*.cpp files with unit tests into single gtest executable. Not CMake-way
execute_process(COMMAND find ${ClickHouse_SOURCE_DIR}/dbms -path "*/tests/gtest*.cpp" -printf "%p;" OUTPUT_VARIABLE sources_with_gtest)
if (ENABLE_TESTS AND sources_with_gtest)
add_executable(unit_tests ${sources_with_gtest})
target_link_libraries(unit_tests gtest_main dbms)
add_test(unit_tests unit_tests)
endif()

View File

@ -6,9 +6,6 @@ add_executable (date_lut3 date_lut3.cpp)
add_executable (date_lut4 date_lut4.cpp)
add_executable (date_lut_default_timezone date_lut_default_timezone.cpp)
add_executable (multi_version multi_version.cpp)
add_executable (json_test json_test.cpp)
add_executable (strong_typedef strong_typedef.cpp)
set(PLATFORM_LIBS ${CMAKE_DL_LIBS})
@ -18,8 +15,8 @@ target_link_libraries (date_lut3 common ${PLATFORM_LIBS})
target_link_libraries (date_lut4 common ${PLATFORM_LIBS})
target_link_libraries (date_lut_default_timezone common ${PLATFORM_LIBS})
target_link_libraries (multi_version dbms ${Boost_SYSTEM_LIBRARY} ${RT_LIBRARIES})
target_link_libraries (json_test dbms ${Boost_SYSTEM_LIBRARY} ${RT_LIBRARIES})
target_link_libraries (strong_typedef common)
add_check (json_test)
add_check (strong_typedef)
add_executable (unit_tests_libcommon gtest_json_test.cpp gtest_strong_typedef.cpp)
target_link_libraries (unit_tests_libcommon gtest_main)
target_link_libraries (unit_tests_libcommon ${Boost_SYSTEM_LIBRARY} ${RT_LIBRARIES} common)
add_check(unit_tests_libcommon)

View File

@ -1,5 +1,3 @@
#define BOOST_TEST_MODULE JSON_MODULE
#include <vector>
#include <string>
#include <exception>
@ -9,7 +7,7 @@
using namespace std::literals::string_literals;
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
enum class ResultType
{
@ -24,7 +22,7 @@ struct GetStringTestRecord
std::string result;
};
void test()
TEST(JSON_Suite, SimpleTest)
{
std::vector<GetStringTestRecord> test_data =
{
@ -645,25 +643,14 @@ void test()
{
JSON j(r.input.c_str(), r.input.c_str() + r.input.size());
BOOST_CHECK_EQUAL(j.getString(), r.result);
BOOST_CHECK(r.result_type == ResultType::Return);
ASSERT_EQ(j.getString(), r.result);
ASSERT_TRUE(r.result_type == ResultType::Return);
}
catch (JSONException & e)
{
BOOST_CHECK(r.result_type == ResultType::Throw);
BOOST_CHECK_EQUAL(e.message(), r.result);
ASSERT_TRUE(r.result_type == ResultType::Throw);
ASSERT_EQ(e.message(), r.result);
}
}
}
}
BOOST_AUTO_TEST_SUITE(JSON_Suite)
BOOST_AUTO_TEST_CASE(SimpleTest)
{
test();
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -6,20 +6,19 @@
#include <memory>
#include <type_traits>
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
BOOST_AUTO_TEST_SUITE(StrongTypedefSuite)
BOOST_AUTO_TEST_CASE(TypedefsOfTheSameType)
TEST(StrongTypedefSuite, TypedefsOfTheSameType)
{
/// check that strong typedefs of same type differ
STRONG_TYPEDEF(int, Int);
STRONG_TYPEDEF(int, AnotherInt);
BOOST_CHECK(!(std::is_same<Int, AnotherInt>::value));
EXPECT_TRUE(!(std::is_same<Int, AnotherInt>::value));
}
BOOST_AUTO_TEST_CASE(Map)
TEST(StrongTypedefSuite, Map)
{
STRONG_TYPEDEF(int, Int);
@ -30,28 +29,28 @@ BOOST_AUTO_TEST_CASE(Map)
int_unorderd_set.insert(Int(2));
}
BOOST_AUTO_TEST_CASE(CopyAndMoveCtor)
TEST(StrongTypedefSuite, CopyAndMoveCtor)
{
STRONG_TYPEDEF(int, Int);
Int a(1);
Int b(2);
a = b;
BOOST_CHECK_EQUAL(a.t, 2);
EXPECT_EQ(a.t, 2);
STRONG_TYPEDEF(std::unique_ptr<int>, IntPtr);
{
IntPtr ptr;
ptr = IntPtr(std::make_unique<int>(3));
BOOST_CHECK_EQUAL(*ptr.t, 3);
EXPECT_EQ(*ptr.t, 3);
}
{
IntPtr ptr(std::make_unique<int>(3));
BOOST_CHECK_EQUAL(*ptr.t, 3);
EXPECT_EQ(*ptr.t, 3);
}
}
BOOST_AUTO_TEST_CASE(NoDefaultCtor)
TEST(StrongTypedefSuite, NoDefaultCtor)
{
struct NoDefaultCtor
{
@ -61,5 +60,3 @@ BOOST_AUTO_TEST_CASE(NoDefaultCtor)
STRONG_TYPEDEF(NoDefaultCtor, MyStruct);
MyStruct m(1);
}
BOOST_AUTO_TEST_SUITE_END()