Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
124 changes: 124 additions & 0 deletions .github/workflows/tests_cmake.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ build/

# Do not ignore CMakeLists.txt
!CMakeLists.txt
cmake-build-debug
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@
path = deps/argparse
url = https://github.com/p-ranav/argparse
shallow = true
[submodule "deps/googletest"]
path = deps/googletest
url = https://github.com/google/googletest.git
shallow = true
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ if(OPENKO_BUILD_SERVERS)
add_subdirectory(Server/ItemManager)
add_subdirectory(Server/VersionManager)
endif()

add_subdirectory(deps/googletest-cmake)
1 change: 1 addition & 0 deletions deps/googletest
Submodule googletest added at 065127
55 changes: 55 additions & 0 deletions deps/googletest-cmake/CMakeLists.txt
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})

########################################
# Test files
########################################
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp)

########################################
# 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)
9 changes: 9 additions & 0 deletions tests/hello_test.cpp
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);
}