Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit testing with Catch2 #36

Merged
merged 15 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions .github/workflows/cmake_build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- name: Setup Workspace
run: ./setup_workspace.sh

- name: Initialize CodeQL
- if: "contains(github.event.head_commit.message, 'codeql')"
name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: cpp
Expand All @@ -47,9 +48,10 @@ jobs:
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE -j $(nproc --all)
run: cmake --build . --target BrickSim BrickSimTests --config $BUILD_TYPE -j $(nproc --all)

- name: Perform CodeQL Analysis
- if: "contains(github.event.head_commit.message, 'codeql')"
name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
with:
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -71,3 +73,51 @@ jobs:
path: |
${{runner.workspace}}/BrickSim/BrickSim.deb
${{runner.workspace}}/BrickSim/README.md

- name: Try to find binary
run: find ${{runner.workspace}} -type f -executable -print

- name: Upload BrickSimTestsLinux
uses: actions/upload-artifact@v2
with:
name: BrickSimTestsLinux
path: ${{runner.workspace}}/build/src/test/BrickSimTests
test:
name: Catch2 Unittests
needs: build
runs-on: ubuntu-latest
steps:
- name: Download test artifact
uses: actions/download-artifact@v2
with:
name: BrickSimTestsLinux
- name: Download libraries
run: sudo apt-get install -y libspdlog1 libzip5
- name: Run tests
run: |
chmod a+x ${{runner.workspace}}/BrickSim/BrickSimTests
${{runner.workspace}}/BrickSim/BrickSimTests -r junit > ${{runner.workspace}}/unitTestReport.xml
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: UnitTestReport
path: ${{runner.workspace}}/unitTestReport.xml
publishTestResults:
name: Publish Catch2 Test Results
needs: test
runs-on: ubuntu-latest
if: success() || failure()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: UnitTestReport
path: artifacts

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: ./**/*.xml
check_name: Catch2 Test Results
comment_title: Catch2 Test Results
6 changes: 4 additions & 2 deletions .github/workflows/cmake_build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ jobs:
CXX: /C/msys64/mingw64/bin/g++.exe
run: |
cmake -G "MinGW Makefiles" . -DCMAKE_PREFIX_PATH=/C/mingw64 -DGIT_COMMIT_HASH:STRING=$(./scripts/get_git_commit_hash.sh) -DGIT_COMMIT_COUNT:STRING=$(./scripts/get_git_commit_count.sh) -DTOTAL_HOURS:STRING=$(./scripts/get_git_total_hours.sh) -DGIT_VERSION_TAG:STRING=$(./scripts/get_git_tag.sh)
cmake --build . --config Release -j $(nproc --all)
cmake --build . --target BrickSim --config Release -j $(nproc --all)

- name: Try to find binary
working-directory: ${{runner.workspace}}
run: find . -name "*.exe"

- name: Upload Binary
- name: Upload BrickSim
uses: actions/upload-artifact@v2
with:
name: BrickSimWindows
# todo include README.md
path: ${{runner.workspace}}\BrickSim\BrickSim.exe


4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
[submodule "src/lib/IconFontCppHeaders"]
path = src/lib/IconFontCppHeaders
url = https://github.com/juliettef/IconFontCppHeaders
[submodule "src/lib/Catch2"]
path = src/lib/Catch2
url = https://github.com/catchorg/Catch2.git
branch = v2.x
8 changes: 7 additions & 1 deletion .idea/BrickSim.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 44 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ foreach(SDKPATH IN LISTS /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk /Ap
set(CMAKE_OSX_SYSROOT ${SDKPATH})
endif()
endforeach()
project(BrickSim)
project(BrickSimProject)

file(LOCK ${CMAKE_SOURCE_DIR} DIRECTORY GUARD FILE)#prevent profiles from loading in parallel, causes problems with submodules

add_executable(BrickSim)
#add_library(BrickSimLib OBJECT EXCLUDE_FROM_ALL)
add_library(BrickSimLib STATIC)

#add_executable(BrickSim $<TARGET_OBJECTS:BrickSimLib> src/main.cpp)
add_executable(BrickSim src/main.cpp)
target_link_libraries(BrickSim PRIVATE BrickSimLib)
add_dependencies(BrickSim BrickSimLib)

# OpenGL
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
target_link_libraries(BrickSim ${OPENGL_LIBRARIES})
target_link_libraries(BrickSimLib ${OPENGL_LIBRARIES})
if (UNIX)
if (APPLE)
target_link_libraries(BrickSim "-framework Cocoa")
target_link_libraries(BrickSim "-framework IOKit")
target_link_libraries(BrickSim "-framework CoreVideo")
target_link_libraries(BrickSimLib "-framework Cocoa")
target_link_libraries(BrickSimLib "-framework IOKit")
target_link_libraries(BrickSimLib "-framework CoreVideo")
endif ()
endif ()

Expand All @@ -31,20 +37,20 @@ set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(src/lib/glfw src/lib/glfw/bin)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(BrickSim glfw)
target_link_libraries(BrickSim ${GLFW_LIBRARIES})
target_link_libraries(BrickSimLib glfw)
target_link_libraries(BrickSimLib ${GLFW_LIBRARIES})
if (UNIX)# todo check if this is necessary
if (NOT APPLE)
find_package(X11 REQUIRED)
target_link_libraries(BrickSim ${X11_LIBRARIES})
target_link_libraries(BrickSimLib ${X11_LIBRARIES})
endif ()
endif ()
target_compile_definitions(BrickSim PUBLIC GLFW_INCLUDE_NONE)
target_compile_definitions(BrickSimLib PUBLIC GLFW_INCLUDE_NONE)

# GLUT
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
target_link_libraries(BrickSim ${GLUT_LIBRARY})
target_link_libraries(BrickSimLib ${GLUT_LIBRARY})

# threads
if (WIN32)
Expand All @@ -55,7 +61,7 @@ add_compile_options("-lphread")
if (UNIX)
if (NOT APPLE)
find_package(Threads REQUIRED)
target_link_libraries(BrickSim ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(BrickSimLib ${CMAKE_THREAD_LIBS_INIT})
endif ()
endif ()

Expand All @@ -67,38 +73,41 @@ message("LIBZIP_INCLUDE_DIRS = ${LIBZIP_INCLUDE_DIRS}")
include_directories(zip)
if (UNIX)
if (APPLE)
target_link_libraries(BrickSim /usr/local/Cellar/libzip/1.7.3/lib/libzip.5.3.dylib)
target_link_libraries(BrickSimLib /usr/local/Cellar/libzip/1.7.3/lib/libzip.5.3.dylib)
else()
target_link_libraries(BrickSim libzip.so.5)
target_link_libraries(BrickSimLib libzip.so.5)
endif()
else ()
find_library(LIBZIP_LIBRARY_LOCATION libzip)
target_link_libraries(BrickSim ${LIBZIP_LIBRARY_LOCATION})
target_link_libraries(BrickSimLib ${LIBZIP_LIBRARY_LOCATION})
endif ()

# SqliteCpp
add_subdirectory(src/lib/SQLiteCpp)
include_directories(src/lib/SQLiteCpp/include)
target_link_libraries(BrickSim SQLiteCpp)
target_link_libraries(BrickSim sqlite3)
target_link_libraries(BrickSimLib SQLiteCpp)
target_link_libraries(BrickSimLib sqlite3)

# cURL
set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(BrickSim ${CURL_LIBRARIES})
target_link_libraries(BrickSimLib ${CURL_LIBRARIES})

# spdlog
find_package(spdlog REQUIRED)
target_link_libraries(BrickSim spdlog::spdlog)
target_link_libraries(BrickSimLib spdlog::spdlog)

#Catch2
add_subdirectory(src/lib/Catch2)

add_subdirectory(src)

if (WIN32)
target_link_libraries(BrickSim -lssp) # stack smashing protection
target_link_libraries(BrickSim -lImm32)
target_link_libraries(BrickSimLib -lssp) # stack smashing protection
target_link_libraries(BrickSimLib -lImm32)
elseif (UNIX AND NOT APPLE)
target_link_libraries(BrickSim -ltbb)
target_link_libraries(BrickSimLib -ltbb)
endif ()

#set(CMAKE_VERBOSE_MAKEFILE ON) # useful for fixing build errors
Expand All @@ -112,11 +121,16 @@ if (USE_RENDERDOC)
add_compile_definitions(BRICKSIM_USE_RENDERDOC)
endif ()

target_include_directories(BrickSim PUBLIC
option(BRICKSIM_USE_OPTIMIZED_VARIANTS "Use optimized variants of certain functions (to use SSE2 or similar things which make it faster)" ON)
if(BRICKSIM_USE_OPTIMIZED_VARIANTS)
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_USE_OPTIMIZED_VARIANTS)
endif()

target_include_directories(BrickSimLib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
src/lib/include
$<INSTALL_INTERFACE:include>)
target_link_libraries(BrickSim ${CMAKE_DL_LIBS})
target_link_libraries(BrickSimLib ${CMAKE_DL_LIBS})

#bash executable
if (EXISTS "C:\\msys64\\usr\\bin\\bash.exe")
Expand All @@ -140,7 +154,7 @@ if (NOT DEFINED GIT_COMMIT_HASH)
endif()
endif ()

target_compile_definitions(BrickSim PUBLIC BRICKSIM_GIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_GIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
message(STATUS "BRICKSIM_GIT_COMMIT_HASH=${GIT_COMMIT_HASH}")

if(NOT DEFINED GIT_COMMIT_COUNT)
Expand All @@ -151,7 +165,7 @@ if(NOT DEFINED GIT_COMMIT_COUNT)
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
target_compile_definitions(BrickSim PUBLIC BRICKSIM_GIT_COMMIT_COUNT=${GIT_COMMIT_COUNT})
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_GIT_COMMIT_COUNT=${GIT_COMMIT_COUNT})
message(STATUS "BRICKSIM_GIT_COMMIT_COUNT=${GIT_COMMIT_COUNT}")

if(NOT DEFINED TOTAL_HOURS)
Expand All @@ -162,7 +176,7 @@ if(NOT DEFINED TOTAL_HOURS)
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
target_compile_definitions(BrickSim PUBLIC BRICKSIM_TOTAL_HOURS=${TOTAL_HOURS})
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_TOTAL_HOURS=${TOTAL_HOURS})
message(STATUS "BRICKSIM_TOTAL_HOURS=${TOTAL_HOURS}")

#version
Expand All @@ -182,9 +196,9 @@ list(GET VERSION_LIST 0 BRICKSIM_VERSION_MAJOR)
list(GET VERSION_LIST 1 BRICKSIM_VERSION_MINOR)
list(GET VERSION_LIST 2 BRICKSIM_VERSION_PATCH)

target_compile_definitions(BrickSim PUBLIC BRICKSIM_VERSION_MAJOR=${BRICKSIM_VERSION_MAJOR})
target_compile_definitions(BrickSim PUBLIC BRICKSIM_VERSION_MINOR=${BRICKSIM_VERSION_MINOR})
target_compile_definitions(BrickSim PUBLIC BRICKSIM_VERSION_PATCH=${BRICKSIM_VERSION_PATCH})
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_VERSION_MAJOR=${BRICKSIM_VERSION_MAJOR})
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_VERSION_MINOR=${BRICKSIM_VERSION_MINOR})
target_compile_definitions(BrickSimLib PUBLIC BRICKSIM_VERSION_PATCH=${BRICKSIM_VERSION_PATCH})

message(STATUS "BrickSim Version: ${BRICKSIM_VERSION_MAJOR}.${BRICKSIM_VERSION_MINOR}.${BRICKSIM_VERSION_PATCH}")

Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target_sources(BrickSim PUBLIC
target_sources(BrickSimLib PUBLIC
camera.cpp
camera.h
config.cpp
Expand All @@ -13,7 +13,6 @@ target_sources(BrickSim PUBLIC
keyboard_shortcut_manager.h
latest_log_messages_tank.cpp
latest_log_messages_tank.h
main.cpp
mesh.cpp
mesh.h
mesh_collection.cpp
Expand Down Expand Up @@ -48,4 +47,5 @@ add_subdirectory(helpers)
add_subdirectory(info_providers)
add_subdirectory(ldr_files)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(tools)
add_subdirectory(test)
2 changes: 1 addition & 1 deletion src/constant_data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target_sources(BrickSim PUBLIC
target_sources(BrickSimLib PUBLIC
constants.cpp
constants.h
resources.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target_sources(BrickSim PUBLIC
target_sources(BrickSimLib PUBLIC
gui.cpp
gui.h
gui_internal.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target_sources(BrickSim PUBLIC
target_sources(BrickSimLib PUBLIC
color.cpp
color.h
fraction.cpp
Expand Down
Loading