Skip to content

Commit

Permalink
feat: Setup unit tests with boost::ut
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrossi committed Aug 20, 2023
1 parent 9c28c05 commit cdf5a0f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 17,733 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ jobs:
with:
configurePreset: ${{ matrix.buildtype }}
buildPreset: ${{ matrix.buildtype }}
configurePresetAdditionalArgs: "['-DBUILD_TESTS=ON']"

- name: Create and Upload Artifact
uses: actions/upload-artifact@main
with:
name: canary-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }}
path: |
${{ github.workspace }}/build/${{ matrix.buildtype }}/bin/
- name: Unit tests
run: |
chmod +x ${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/canary_ut
${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/canary_ut
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
include(MessageColors)
include(LoggingHelper)


# *****************************************************************************
# Options
# *****************************************************************************
Expand Down Expand Up @@ -95,9 +94,14 @@ else()
log_option_disabled("ipo")
endif()

option(BUILD_TESTS "Build tests" OFF) # By default, tests will not be built

# *****************************************************************************
# Add project
# *****************************************************************************
add_subdirectory(src/protobuf)
add_subdirectory(src)

if(BUILD_TESTS)
add_subdirectory(tests)
endif()
4 changes: 1 addition & 3 deletions src/otserv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "pch.hpp"
#include "canary_server.hpp"

#ifndef UNIT_TESTING
int main() {
return inject<CanaryServer>().run();
}
#endif
}
26 changes: 5 additions & 21 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
find_package(Catch2 REQUIRED)
# include_directories(BEFORE ${PROJECT_SOURCE_DIR})
include_directories(SYSTEM ${MYSQL_INCLUDE_DIR} ${LUA_INCLUDE_DIR}
${Boost_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR}
${CRYPTOPP_INCLUDE_DIR})
find_package(ut CONFIG REQUIRED)

project(canary_unittest)
set(CMAKE_CXX_FLAGS "-pipe -O0 -g -std=c++11 -lstdc++ -lpthread -ldl")

set(CMAKE_CXX_FLAGS "-pipe -O0 -g -Wno-everything -std=c++11 -lstdc++ -lpthread -ldl")
add_executable(canary_ut main.cpp test1.cpp test2.cpp)

add_executable(canary_unittest
main.cpp
account_test.cpp)

target_compile_definitions(canary_unittest PUBLIC -DUNIT_TESTING -DDEBUG_LOG)

target_link_libraries(canary_unittest Catch2::Catch2 canary_lib ${MYSQL_CLIENT_LIBS} ${LUA_LIBRARIES}
${Boost_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY}
${PUGIXML_LIBRARIES} ${CRYPTOPP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})

include(CTest)
include(Catch)
catch_discover_tests(canary_unittest)
target_compile_definitions(canary_ut PUBLIC -DDEBUG_LOG)
target_link_libraries(canary_ut PRIVATE Boost::ut ${PROJECT_NAME}_lib)
Loading

0 comments on commit cdf5a0f

Please sign in to comment.