diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14b7bba..501888f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ permissions: contents: read jobs: - build: + test-msbuild: runs-on: windows-latest steps: @@ -42,4 +42,69 @@ jobs: - name: Run tests working-directory: ${{env.GITHUB_WORKSPACE}} - run: .\Debug\test.exe \ No newline at end of file + run: .\Debug\test.exe + + test-cmake: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ ubuntu-latest, windows-latest ] + build_type: [ Release ] + c_compiler: [ gcc, clang, cl ] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v3 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index db841f2..9df7b2b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ libant.sln.DotSettings.user *.filters packages/ x64/ +cmake-build-debug/ +Debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2499e17 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.26) +project(libant) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +include_directories(.) + +file(GLOB TEST_SOURCES "test/*.cpp") + +add_executable(libant ${TEST_SOURCES}) + +target_link_libraries( + libant + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(libant) diff --git a/automaton/ant/la_ant.h b/automaton/ant/la_ant.h index 6e8107f..e38bcb9 100644 --- a/automaton/ant/la_ant.h +++ b/automaton/ant/la_ant.h @@ -2,7 +2,7 @@ #include #include -#include "../spatial_structure/la_cell.h" +#include constexpr int NORTH_2D[2] = {0, -1}; constexpr int EAST_2D[2] = {1, 0}; diff --git a/automaton/scanning/la_scanning_automaton.h b/automaton/scanning/la_scanning_automaton.h index 6b67cdd..335dd3f 100644 --- a/automaton/scanning/la_scanning_automaton.h +++ b/automaton/scanning/la_scanning_automaton.h @@ -2,7 +2,7 @@ #include #include "../la_automaton.h" -#include "../rule/la_rule.h" +#include "../../rule/la_rule.h" class la_scanning_automaton : public la_automaton { diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..7b69397 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +Debug/ diff --git a/test/fixtures.h b/test/fixtures.h index 4d96ff6..33b4e8e 100644 --- a/test/fixtures.h +++ b/test/fixtures.h @@ -1,6 +1,6 @@ #pragma once #include -#include "../libant.h" +#include class AutomatonTestFixtures : public ::testing::TestWithParam { diff --git a/test/test.vcxproj b/test/test.vcxproj index a96701a..4010056 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -51,6 +51,7 @@ + @@ -67,6 +68,7 @@ MultiThreadedDebugDLL Level3 stdcpp20 + $(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories);..; true diff --git a/test/test_game_of_life.cpp b/test/test_game_of_life.cpp index 720dcee..2314a2a 100644 --- a/test/test_game_of_life.cpp +++ b/test/test_game_of_life.cpp @@ -1,7 +1,6 @@ #pragma once #include "fixtures.h" -#include "../libant.h" class GameOfLifeTest : public AutomatonTestFixtures { // No need for additional setup and teardown here diff --git a/test/test_langtons_ant.cpp b/test/test_langtons_ant.cpp index 7c20ed8..135c43c 100644 --- a/test/test_langtons_ant.cpp +++ b/test/test_langtons_ant.cpp @@ -1,7 +1,4 @@ -#pragma once - -#include "fixtures.h" -#include "../libant.h" +#include "fixtures.h" class LangtonsAntTest : public AutomatonTestFixtures { // No need for additional setup and teardown here @@ -14,7 +11,6 @@ INSTANTIATE_TEST_CASE_P( custom_test_name ); -// TEST_P(LangtonsAntTest, test_langtons_ant_quadtree) TEST_P(LangtonsAntTest, test_langtons_ant) { auto backend = get_backend({3, 3}); diff --git a/test/test_rule.cpp b/test/test_rule.cpp index 44b8c12..cbbbcda 100644 --- a/test/test_rule.cpp +++ b/test/test_rule.cpp @@ -1,7 +1,6 @@ #include #include "fixtures.h" -#include "../libant.h" using namespace libant; diff --git a/test/test_spatial_structure.cpp b/test/test_spatial_structure.cpp index 5b1bd6f..aafc0f1 100644 --- a/test/test_spatial_structure.cpp +++ b/test/test_spatial_structure.cpp @@ -1,5 +1,4 @@ #include "fixtures.h" -#include "../libant.h" class SpatialStructureTest : public AutomatonTestFixtures { // No need for additional setup and teardown here