diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4a4bc003..85f43796 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -45,12 +45,17 @@ jobs: CC: ${{ steps.vars.outputs.cc }} CXX: ${{ steps.vars.outputs.cxx }} run: | - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build + cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build - name: Build Dethrace run: | cmake --build build -- -j 4 + - name: Run unit tests + run: | + cd build + ctest + - name: Create archives run: | mkdir artifact diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 47e7575c..01d08f97 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -25,12 +25,17 @@ jobs: - name: Configure Dethrace run: | - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build + cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build - name: Build Dethrace run: | cmake --build build -- -j 4 + - name: Run unit tests + run: | + cd build + ctest + - name: Create archives run: | mkdir artifact diff --git a/CMakeLists.txt b/CMakeLists.txt index f3010b5e..164bc4f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ project(dethrace C) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +option(BUILD_TESTS "Build unit tests." OFF) + find_package(SDL2 REQUIRED) add_subdirectory(lib/libsmacker) @@ -19,3 +21,8 @@ add_subdirectory(lib/glad) add_subdirectory(src/harness) add_subdirectory(src/BRSRC13) add_subdirectory(src/DETHRACE) + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(test) +endif() diff --git a/src/DETHRACE/CMakeLists.txt b/src/DETHRACE/CMakeLists.txt index 0f7e793e..4c8305fe 100644 --- a/src/DETHRACE/CMakeLists.txt +++ b/src/DETHRACE/CMakeLists.txt @@ -1,6 +1,7 @@ -add_executable(dethrace) +# Create object files so we can link them into the main binary and into tests without building twice. +add_library(dethrace_obj OBJECT) -target_include_directories(dethrace PRIVATE +target_include_directories(dethrace_obj PUBLIC . common pc-dos @@ -9,32 +10,24 @@ target_include_directories(dethrace PRIVATE ${CMAKE_SOURCE_DIR}/src/BRSRC13 ) -target_link_libraries(dethrace PRIVATE smacker harness brender miniposix SDL2::SDL2 glad) +target_link_libraries(dethrace_obj PUBLIC miniposix SDL2::SDL2 smacker harness brender) if(NOT MSVC) - target_compile_options(dethrace PRIVATE + target_compile_options(dethrace_obj PRIVATE -g -Wno-return-type -Wno-missing-declarations -Werror=implicit-function-declaration ) - - if(APPLE) - target_link_libraries(dethrace PRIVATE "-framework OpenGL") - else() - target_link_libraries(dethrace PRIVATE GL) - endif() else() - target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED) - target_compile_options(dethrace PRIVATE + target_compile_definitions(dethrace_obj PRIVATE -D_CRT_SECURE_NO_WARNINGS) + target_compile_options(dethrace_obj PRIVATE /wd4101 /wd4996 ) - target_link_libraries(dethrace PRIVATE dbghelp) - target_link_options(dethrace PRIVATE /subsystem:windows /ENTRY:mainCRTStartup) endif() -target_sources(dethrace PRIVATE +target_sources(dethrace_obj PRIVATE common/brucetrk.c common/brucetrk.h common/car.c @@ -139,11 +132,27 @@ target_sources(dethrace PRIVATE common/world.h constants.h dr_types.h - main.c pc-dos/dosnet.c pc-dos/dosnet.h pc-dos/dossys.c pc-dos/dossys.h watcom_functions.c watcom_functions.h -) \ No newline at end of file +) + +# Create our main game binary. +add_executable(dethrace) +target_link_libraries(dethrace PRIVATE glad dethrace_obj) +target_sources(dethrace PRIVATE main.c) + +if(NOT MSVC) + if(APPLE) + target_link_libraries(dethrace PRIVATE "-framework OpenGL") + else() + target_link_libraries(dethrace PRIVATE GL) + endif() +else() + target_link_libraries(dethrace PRIVATE dbghelp) + target_link_options(dethrace PRIVATE /subsystem:windows /ENTRY:mainCRTStartup) + target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..14db3673 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,56 @@ +add_executable(dethrace_test) +add_test(NAME teat_dethrace COMMAND dethrace_test) + +target_link_libraries(dethrace_test PRIVATE glad dethrace_obj) + +target_include_directories(dethrace_test PRIVATE + . + ${CMAKE_SOURCE_DIR}/lib + ${CMAKE_SOURCE_DIR}/src/harness + ${CMAKE_SOURCE_DIR}/src/BRSRC13 + ${CMAKE_SOURCE_DIR}/src/DETHRACE + ${CMAKE_SOURCE_DIR}/src/DETHRACE/common + ${CMAKE_SOURCE_DIR}/src/DETHRACE/pc-dos +) + +if(NOT MSVC) + if(APPLE) + target_link_libraries(dethrace_test PRIVATE "-framework OpenGL") + else() + target_link_libraries(dethrace_test PRIVATE GL) + endif() +else() + target_compile_definitions(dethrace_test PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED) + target_link_libraries(dethrace_test PRIVATE dbghelp) +endif() + +target_sources(dethrace_test PRIVATE + BRSRC13/test_actsupt.c + BRSRC13/test_brlists.c + BRSRC13/test_datafile.c + BRSRC13/test_fwsetup.c + BRSRC13/test_genclip.c + BRSRC13/test_pattern.c + BRSRC13/test_pmfile.c + BRSRC13/test_register.c + BRSRC13/test_regsupt.c + BRSRC13/test_resource.c + BRSRC13/test_resreg.c + BRSRC13/test_v1dbfile.c + DETHRACE/test_controls.c + DETHRACE/test_dossys.c + DETHRACE/test_errors.c + DETHRACE/test_flicplay.c + DETHRACE/test_graphics.c + DETHRACE/test_init.c + DETHRACE/test_input.c + DETHRACE/test_loading.c + DETHRACE/test_powerup.c + DETHRACE/test_utility.c + framework/unity.c + framework/unity.h + framework/unity_internals.h + framework + main.c + tests.h +) \ No newline at end of file