Skip to content

Commit

Permalink
Switch to Google Test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMax committed Dec 28, 2023
1 parent e952ce9 commit 0767df5
Show file tree
Hide file tree
Showing 12 changed files with 820 additions and 836 deletions.
42 changes: 22 additions & 20 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ include(FindSanitizers)

# Catch2
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
include(CTest)
include(Catch)
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

set(TEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/test_bufreader.cpp"
Expand All @@ -29,32 +29,34 @@ set(TEST_SOURCES
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h")

# Test suite.
add_executable(test ${TEST_SOURCES})
target_include_directories(test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(test PRIVATE lexio Catch2::Catch2WithMain)
catch_discover_tests(test)
add_executable(lexio_test ${TEST_SOURCES})
target_include_directories(lexio_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(lexio_test PRIVATE lexio GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(lexio_test)

# Only use clang-tidy with Clang.
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT MSVC)
find_program(CLANG_TIDY_EXE clang-tidy)
if(CLANG_TIDY_EXE)
set_target_properties(test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
set_target_properties(lexio_test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
endif()

check_compiler_flag(CXX -Wmost W_MOST)
if(W_MOST)
target_compile_options(test PRIVATE "-Wmost")
target_compile_options(lexio_test PRIVATE "-Wmost")
endif()

check_compiler_flag(CXX -Werror=c++17-extensions WERROR_CXX17_EXTENSIONS)
if(WERROR_CXX17_EXTENSIONS)
target_compile_options(test PRIVATE "-Werror=c++17-extensions")
target_compile_options(lexio_test PRIVATE "-Werror=c++17-extensions")
endif()

check_compiler_flag(CXX -Werror=c++20-extensions WERROR_CXX20_EXTENSIONS)
if(WERROR_CXX20_EXTENSIONS)
target_compile_options(test PRIVATE "-Werror=c++20-extensions")
target_compile_options(lexio_test PRIVATE "-Werror=c++20-extensions")
endif()

add_sanitizers(Catch2)
Expand All @@ -64,18 +66,18 @@ if(MSVC AND SANITIZE_ADDRESS)
endif()

if(MSVC)
target_compile_options(test PUBLIC /W4 /D_DISABLE_VECTOR_ANNOTATION)
target_compile_options(lexio_test PUBLIC /W4 /D_DISABLE_VECTOR_ANNOTATION)
else()
target_compile_options(test PUBLIC -Wall -Wextra -Wno-unknown-pragmas)
target_compile_options(lexio_test PUBLIC -Wall -Wextra -Wno-unknown-pragmas)
endif()

option(CODE_COVERAGE "Enable code coverage on test suite" OFF)
if(CODE_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags_to_target(test)
append_coverage_compiler_flags_to_target(lexio_test)
setup_target_for_coverage_lcov(
NAME test_coverage
EXECUTABLE test
DEPENDENCIES test
EXECUTABLE lexio_test
DEPENDENCIES lexio_test
EXCLUDE "build/*" "tests" "/usr/include/*")
endif()
2 changes: 2 additions & 0 deletions tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "lexio/lexio.hpp"

#include <gtest/gtest.h>

using VectorBufReader = LexIO::GenericBufReader<LexIO::VectorStream>;

template <typename T, std::size_t N>
Expand Down
Loading

0 comments on commit 0767df5

Please sign in to comment.