Skip to content

Commit 12b1e7c

Browse files
Add a way to run Unit Tests (#679)
* Add googletest as Testing Framework * Add test infrastructure; add OPENKO_BUILD_TESTS flag to CMake. * build_cmake_server.yml: Run tests with ctest. * MSBuild: Add test-related projects * build_msbuild_all.yml: Build & run tests. * GitHub workflows: we shouldn't need ${{env.GITHUB_WORKSPACE}} at all; the path is relative to the repository so it should be fine. * Add GTA.runsettings for faster exposure --------- Co-authored-by: twostars <i.am.twostars@gmail.com>
1 parent 43de545 commit 12b1e7c

33 files changed

+1457
-10
lines changed

.github/workflows/build_cmake_server.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ jobs:
8686
--build build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \
8787
--config ${{ matrix.BUILD_CONFIGURATION }}
8888
89+
- name: Run tests
90+
shell: bash
91+
working-directory: build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }}
92+
run: |
93+
ctest -C "${{ matrix.BUILD_CONFIGURATION }}"
94+
8995
build_linux:
9096
runs-on: ubuntu-latest
9197

@@ -140,3 +146,9 @@ jobs:
140146
cmake \
141147
--build build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \
142148
--config ${{ matrix.BUILD_CONFIGURATION }}
149+
150+
- name: Run tests
151+
shell: bash
152+
working-directory: build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }}
153+
run: |
154+
ctest -C "${{ matrix.BUILD_CONFIGURATION }}"

.github/workflows/build_msbuild_all.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,26 @@ jobs:
6464

6565
# NOTE: We could simply run All.sln, but it makes it far more obvious in the Github output when it's broken up across its solutions.
6666
- name: Build third party dependencies
67-
working-directory: ${{env.GITHUB_WORKSPACE}}
6867
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" ThirdParty.sln
6968

7069
- name: Build client
71-
working-directory: ${{env.GITHUB_WORKSPACE}}
7270
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" Client.sln
7371

7472
- name: Build server
75-
working-directory: ${{env.GITHUB_WORKSPACE}}
7673
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" Server.sln
7774

7875
- name: Build tools
79-
working-directory: ${{env.GITHUB_WORKSPACE}}
8076
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" Tools.sln
8177

8278
- name: Build client tools
83-
working-directory: ${{env.GITHUB_WORKSPACE}}
8479
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" ClientTools.sln
80+
81+
- name: Build tests
82+
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" Tests.sln
83+
84+
- name: Run tests
85+
shell: pwsh
86+
working-directory: "bin/${{matrix.BUILD_PLATFORM}}/${{matrix.BUILD_CONFIGURATION}}"
87+
run: |
88+
.\client-tests.exe
89+
.\server-tests.exe

.github/workflows/build_msbuild_client_tools.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ jobs:
4343
uses: microsoft/setup-msbuild@v2
4444

4545
- name: Build tools
46-
working-directory: ${{env.GITHUB_WORKSPACE}}
4746
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" ClientTools.sln

.github/workflows/build_msbuild_server.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ jobs:
4242
uses: microsoft/setup-msbuild@v2
4343

4444
- name: Build server
45-
working-directory: ${{env.GITHUB_WORKSPACE}}
4645
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" Server.sln

.github/workflows/build_msbuild_tools.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ jobs:
4242
uses: microsoft/setup-msbuild@v2
4343

4444
- name: Build tools
45-
working-directory: ${{env.GITHUB_WORKSPACE}}
4645
run: msbuild /p:Configuration="${{matrix.BUILD_CONFIGURATION}}" /p:Platform="${{matrix.BUILD_PLATFORM}}" Tools.sln

.github/workflows/codeql.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jobs:
4242
# as needed from within All.sln; this ensures they're built first so they won't build again during
4343
# CodeQL monitoring.
4444
- name: Build third party dependencies
45-
working-directory: ${{env.GITHUB_WORKSPACE}}
4645
run: msbuild /p:Configuration="${{env.BUILD_CONFIGURATION}}" /p:Platform="${{env.BUILD_PLATFORM}}" ThirdParty.sln
4746

4847
# Initializes the CodeQL tools for scanning.
@@ -53,7 +52,6 @@ jobs:
5352
build-mode: manual
5453

5554
- name: Build all
56-
working-directory: ${{env.GITHUB_WORKSPACE}}
5755
run: msbuild /p:Configuration="${{env.BUILD_CONFIGURATION}}" /p:Platform="${{env.BUILD_PLATFORM}}" /p:NO_CLIENT_ASSETS="1" All.sln
5856

5957
- name: Perform CodeQL Analysis

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@
6363
path = deps/argparse
6464
url = https://github.com/p-ranav/argparse
6565
shallow = true
66+
[submodule "deps/googletest"]
67+
path = deps/googletest
68+
url = https://github.com/google/googletest
69+
shallow = true

All.sln

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_deps", "_deps", "{E91CF97D
239239
EndProject
240240
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fetch-argparse", "deps\fetch-and-build-wrappers\fetch-argparse.vcxproj", "{61A124FB-035E-4560-8499-198C6299B7DA}"
241241
EndProject
242+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fetch-googletest", "deps\fetch-and-build-wrappers\fetch-googletest.vcxproj", "{D4F3D338-A7EF-430C-AD99-2FC6A591A711}"
243+
ProjectSection(ProjectDependencies) = postProject
244+
{1F14357D-E06A-48A1-B39A-74082F381FC0} = {1F14357D-E06A-48A1-B39A-74082F381FC0}
245+
EndProjectSection
246+
EndProject
247+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client-tests", "Client\tests\client-tests.vcxproj", "{F1626769-3D40-4524-912E-4B0780393B37}"
248+
ProjectSection(ProjectDependencies) = postProject
249+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711} = {D4F3D338-A7EF-430C-AD99-2FC6A591A711}
250+
EndProjectSection
251+
EndProject
252+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4E7D8CAB-AF8E-4790-96EF-F3715830E3CF}"
253+
EndProject
254+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server-tests", "Server\tests\server-tests.vcxproj", "{642EEED1-6C69-4888-9EC6-BEC40A46080B}"
255+
ProjectSection(ProjectDependencies) = postProject
256+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711} = {D4F3D338-A7EF-430C-AD99-2FC6A591A711}
257+
EndProjectSection
258+
EndProject
242259
Global
243260
GlobalSection(SolutionConfigurationPlatforms) = preSolution
244261
Debug|Win32 = Debug|Win32
@@ -565,6 +582,30 @@ Global
565582
{61A124FB-035E-4560-8499-198C6299B7DA}.Release|Win32.Build.0 = Release|Win32
566583
{61A124FB-035E-4560-8499-198C6299B7DA}.Release|x64.ActiveCfg = Release|x64
567584
{61A124FB-035E-4560-8499-198C6299B7DA}.Release|x64.Build.0 = Release|x64
585+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Debug|Win32.ActiveCfg = Debug|Win32
586+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Debug|Win32.Build.0 = Debug|Win32
587+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Debug|x64.ActiveCfg = Debug|x64
588+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Debug|x64.Build.0 = Debug|x64
589+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Release|Win32.ActiveCfg = Release|Win32
590+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Release|Win32.Build.0 = Release|Win32
591+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Release|x64.ActiveCfg = Release|x64
592+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711}.Release|x64.Build.0 = Release|x64
593+
{F1626769-3D40-4524-912E-4B0780393B37}.Debug|Win32.ActiveCfg = Debug|Win32
594+
{F1626769-3D40-4524-912E-4B0780393B37}.Debug|Win32.Build.0 = Debug|Win32
595+
{F1626769-3D40-4524-912E-4B0780393B37}.Debug|x64.ActiveCfg = Debug|x64
596+
{F1626769-3D40-4524-912E-4B0780393B37}.Debug|x64.Build.0 = Debug|x64
597+
{F1626769-3D40-4524-912E-4B0780393B37}.Release|Win32.ActiveCfg = Release|Win32
598+
{F1626769-3D40-4524-912E-4B0780393B37}.Release|Win32.Build.0 = Release|Win32
599+
{F1626769-3D40-4524-912E-4B0780393B37}.Release|x64.ActiveCfg = Release|x64
600+
{F1626769-3D40-4524-912E-4B0780393B37}.Release|x64.Build.0 = Release|x64
601+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Debug|Win32.ActiveCfg = Debug|Win32
602+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Debug|Win32.Build.0 = Debug|Win32
603+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Debug|x64.ActiveCfg = Debug|x64
604+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Debug|x64.Build.0 = Debug|x64
605+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Release|Win32.ActiveCfg = Release|Win32
606+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Release|Win32.Build.0 = Release|Win32
607+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Release|x64.ActiveCfg = Release|x64
608+
{642EEED1-6C69-4888-9EC6-BEC40A46080B}.Release|x64.Build.0 = Release|x64
568609
EndGlobalSection
569610
GlobalSection(SolutionProperties) = preSolution
570611
HideSolutionNode = FALSE
@@ -614,6 +655,9 @@ Global
614655
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {74CB367B-7B41-43B6-9DEE-D4070362E0F8}
615656
{E91CF97D-F613-4B2E-9DEE-0A90C6A6EB5A} = {C8016DCD-4286-4BD2-9C78-F1E6D9D0555B}
616657
{61A124FB-035E-4560-8499-198C6299B7DA} = {6EEB718D-CCE4-446E-A0BE-172669B7BC98}
658+
{D4F3D338-A7EF-430C-AD99-2FC6A591A711} = {6EEB718D-CCE4-446E-A0BE-172669B7BC98}
659+
{F1626769-3D40-4524-912E-4B0780393B37} = {4E7D8CAB-AF8E-4790-96EF-F3715830E3CF}
660+
{642EEED1-6C69-4888-9EC6-BEC40A46080B} = {4E7D8CAB-AF8E-4790-96EF-F3715830E3CF}
617661
EndGlobalSection
618662
GlobalSection(ExtensibilityGlobals) = postSolution
619663
SolutionGuid = {D9937074-3E07-4102-9EF1-BE6E87CF35E4}

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(CXX_SCAN_FOR_MODULES OFF)
1818
# Config
1919
option(OPENKO_BUILD_SERVERS "Build the server projects (default on)" ON)
2020
option(OPENKO_COMPILE_WARNINGS_AS_ERROR "Enable treating warnings as errors (default on)" ON)
21+
option(OPENKO_BUILD_TESTS "Build the test projects (default on)" ON)
2122

2223
# Define the bin directory; defaults to repo/bin
2324
set(OPENKO_BIN_DIR "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Directory for final binaries")
@@ -31,6 +32,7 @@ endif()
3132
message(STATUS "OpenKO feature: OPENKO_BUILD_SERVERS - ${OPENKO_BUILD_SERVERS}")
3233
message(STATUS "OpenKO feature: OPENKO_COMPILE_WARNINGS_AS_ERROR - ${OPENKO_COMPILE_WARNINGS_AS_ERROR}")
3334
message(STATUS "OpenKO feature: OPENKO_BIN_DIR - ${OPENKO_BIN_DIR}")
35+
message(STATUS "OpenKO feature: OPENKO_BUILD_TESTS - ${OPENKO_BUILD_TESTS}")
3436

3537
if(WIN32)
3638
message(STATUS "OpenKO feature: _WIN32_WINNT - ${_WIN32_WINNT}")
@@ -114,3 +116,18 @@ if(OPENKO_BUILD_SERVERS)
114116
add_subdirectory(Server/ItemManager)
115117
add_subdirectory(Server/VersionManager)
116118
endif()
119+
120+
if(OPENKO_BUILD_TESTS)
121+
include(CTest)
122+
123+
set(CMAKE_FOLDER "Tests/_deps")
124+
add_subdirectory(deps/googletest-cmake)
125+
126+
set(CMAKE_FOLDER "Tests")
127+
add_subdirectory(Server/tests)
128+
129+
# TODO: Client builds via CMake (even just for MSVC for now)
130+
#if(MSVC)
131+
# add_subdirectory(Client/tests)
132+
#endif()
133+
endif()

Client/tests/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# NOTE: Unused - no CMake client builds currently.
2+
add_executable(client-tests
3+
hello_test.cpp)
4+
5+
target_link_libraries(client-tests PRIVATE
6+
gtest
7+
gtest_main)
8+
9+
add_test(
10+
NAME ClientTests
11+
COMMAND client-tests)

0 commit comments

Comments
 (0)