-
Notifications
You must be signed in to change notification settings - Fork 183
Add a way to run Unit Tests #679
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b91b900
Add googletest as Testing Framework
stefannikolei 6eb16d2
Add Test infrastructure
stefannikolei 09bbcdc
Address Feedback
stefannikolei ac4e3e5
Remove cmake-build-debug from gitignore
stefannikolei 55c46d8
Add a folder in CMake to not pollute the Server project
stefannikolei 5fa9b99
MSBuild: Add test-related projects
twostars 6b9d5f5
Add seperate test folders for client and server in Visual Studio
stefannikolei d2cad3d
tests structure tweaks
twostars d070c2b
Remove tests.vcxproj from ThirdParty.sln
twostars 02fcbf8
CMake: Include build config for multiconfig generators
twostars cec858f
We shouldn't need ${{env.GITHUB_WORKSPACE}} at all
twostars a7a2dad
Workflow fixes
twostars 6ec1806
Former syntax should work, but .\ is expected for Powershell
twostars 0723a05
build_cmake_server.yml: -C not -c
twostars 6213d19
Add GTA.runsettings for faster exposure
twostars 8d5a0b4
Formatter pass over sample test source files
twostars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # This workflow uses actions that are not certified by GitHub. | ||
| # They are provided by a third-party and are governed by | ||
| # separate terms of service, privacy policy, and support | ||
| # documentation. | ||
|
|
||
| name: "Build server (CMake)" | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| paths: | ||
| - '.github/workflows/tests_cmake.yml' | ||
|
|
||
| pull_request: | ||
| branches: | ||
| - master | ||
|
|
||
| paths: | ||
| - '.github/workflows/tests_cmake.yml' | ||
|
|
||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build_windows: | ||
| runs-on: windows-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| BUILD_CONFIGURATION: [Debug, Release] | ||
| BUILD_PLATFORM: [Win32, x64] | ||
|
|
||
| name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.BUILD_PLATFORM }} (Windows)" | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: 'false' | ||
|
|
||
| - uses: lukka/get-cmake@latest | ||
|
|
||
| - name: Configure CMake | ||
| shell: bash | ||
| run: | | ||
| cmake -S . \ | ||
| -B build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \ | ||
| -G "Visual Studio 17 2022" \ | ||
| -A ${{ matrix.BUILD_PLATFORM }} \ | ||
| -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }} | ||
|
|
||
| - name: Build server | ||
| shell: bash | ||
| run: | | ||
| cmake \ | ||
| --build build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \ | ||
| --config ${{ matrix.BUILD_CONFIGURATION }} | ||
|
|
||
| - name: Run tests | ||
| shell: bash | ||
| working-directory: build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} | ||
| run: | | ||
| ctest | ||
|
|
||
| build_linux: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| BUILD_CONFIGURATION: [Debug, Release] | ||
| COMPILER: [gcc, clang, clang-20] | ||
|
|
||
| env: | ||
| clang-latest-version: 20 | ||
|
|
||
| name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.COMPILER }} (Linux)" | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: 'false' | ||
|
|
||
| - name: Install unixODBC | ||
| run: sudo apt-get install unixodbc-dev -y | ||
|
|
||
| - uses: lukka/get-cmake@latest | ||
|
|
||
| - name: Setup compiler | ||
| run: | | ||
| if [ "${{ matrix.COMPILER }}" = "gcc" ]; then | ||
| export CC=gcc | ||
| export CXX=g++ | ||
| elif [ "${{ matrix.COMPILER }}" = "clang" ]; then | ||
| export CC=clang | ||
| export CXX=clang++ | ||
| else | ||
| wget https://apt.llvm.org/llvm.sh | ||
| chmod +x llvm.sh | ||
| sudo ./llvm.sh ${{ env.clang-latest-version }} | ||
| sudo apt-get update | ||
| export CC=clang-${{ env.clang-latest-version }} | ||
| export CXX=clang++-${{ env.clang-latest-version }} | ||
| fi | ||
| echo "CC=$CC" >> $GITHUB_ENV | ||
| echo "CXX=$CXX" >> $GITHUB_ENV | ||
|
|
||
| - name: Configure CMake | ||
| run: | | ||
| cmake -S . \ | ||
| -B build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \ | ||
| -G "Ninja" \ | ||
| -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }} | ||
|
|
||
| - name: Build server | ||
| run: | | ||
| cmake \ | ||
| --build build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \ | ||
| --config ${{ matrix.BUILD_CONFIGURATION }} | ||
|
|
||
| - name: Run tests | ||
| shell: bash | ||
| working-directory: build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} | ||
| run: | | ||
| ctest | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule googletest
added at
065127
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| fetchcontent_declare( | ||
| googletest | ||
| GIT_REPOSITORY "https://github.com/google/googletest.git" | ||
| GIT_TAG "v1.17.0" | ||
| GIT_PROGRESS ON | ||
| GIT_SHALLOW ON | ||
| OVERRIDE_FIND_PACKAGE TRUE | ||
| EXCLUDE_FROM_ALL | ||
| ) | ||
|
|
||
| message(STATUS "OpenKO: [googletest] Checking and fetching...") | ||
|
|
||
| fetchcontent_makeavailable(googletest) | ||
|
|
||
| message(STATUS "OpenKO: [googletest] Up-to-date!") | ||
|
|
||
|
|
||
| ######################################## | ||
| # Testing | ||
| ######################################## | ||
| # Options. Turn on with 'cmake -Dmyvarname=ON'. | ||
| # option(BUILD_TESTS "Build all tests." ON) # Makes boolean 'test' available. | ||
|
|
||
| # google test is a git submodule for the project, and it is also cmake-based | ||
| #add_subdirectory(./deps/googletest) | ||
|
|
||
| enable_testing() | ||
| # | ||
| # Include the gtest library. gtest_SOURCE_DIR is available due to | ||
| # 'project(gtest)' above. | ||
| include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) | ||
stefannikolei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ######################################## | ||
| # Test files | ||
| ######################################## | ||
| file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp) | ||
twostars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ######################################## | ||
| # Unit Tests | ||
| ######################################## | ||
| add_executable(runUnitTests ${TEST_SRC_FILES}) | ||
|
|
||
| ######################################## | ||
| # Standard linking to gtest stuff. | ||
| ######################################## | ||
| target_link_libraries(runUnitTests gtest gtest_main) | ||
|
|
||
| ######################################## | ||
| # Extra linking for the project. | ||
| ######################################## | ||
| #target_link_libraries(runUnitTests project1_lib) | ||
|
|
||
| # This is so you can do 'make test' to see all your tests run, instead of | ||
| # manually running the executable runUnitTests to see those specific tests. | ||
| add_test(UnitTests runUnitTests) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include <gtest/gtest.h> | ||
|
|
||
| // Demonstrate some basic assertions. | ||
| TEST(HelloTest, BasicAssertions) { | ||
| // Expect two strings not to be equal. | ||
| EXPECT_STRNE("hello", "world"); | ||
| // Expect equality. | ||
| EXPECT_EQ(7 * 6, 42); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.