diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1ee97ab..b93b9c0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,5 @@ name: CI -# Controls when the workflow will run on: # Triggers the workflow on push or pull request events but only for the "master" branch push: @@ -15,32 +14,89 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on - runs-on: ubuntu-latest + 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 represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - # Runs a single command using the runners shell - - name: Get conan - run: | - python -m pip install conan - conan profile detect + - name: Install GCC + uses: egor-tensin/setup-gcc@v1.3 + if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'gcc' + with: + version: 13 + + - name: Install Clang + uses: egor-tensin/setup-clang@v1.4 + if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'clang' + with: + version: 16 + + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: pip + - run: pip install -r requirements.txt + + - 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: Create default Conan profile + run: conan profile detect + - name: Get dependencies - run: | - mkdir build - cd build - conan install .. --build=missing + run: conan install ${{ github.workspace }} --build=missing --output-folder=build --settings compiler.cppstd=20 + + - name: Configure CMake + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DBUILD_TESTING=ON + --toolchain=conan_toolchain.cmake + -S ${{ github.workspace }} + - name: Build project - run: | - cd build - cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON --toolchain=conan_toolchain.cmake - cmake --build . --target all + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel + - name: Run test suite - run: build/tests/cppIni_tests + working-directory: build + run: ctest --build-config ${{ matrix.build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e73b9..b660188 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,12 @@ project(cppIni LANGUAGES CXX VERSION 0.0.0) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(BUILD_TESTING ON "Build test files") option(BUILD_SHARED_LIBS ON "Build shared library files") add_subdirectory(src) -include(CTest) if(BUILD_TESTING) + enable_testing() add_subdirectory(tests) endif() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..45f9eee --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +conan >= 2.0.10 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c61cc8..a067488 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.24) -include(CTest) - -set(TEST_DRIVER_NAME TestDriver) - find_package(doctest REQUIRED) -add_executable(${PROJECT_NAME}_tests constructionTest.cpp) +set(TEST_SOURCES + ConstructionTest.cpp +) + +add_executable(${PROJECT_NAME}_tests ${TEST_SOURCES}) target_link_libraries(${PROJECT_NAME}_tests doctest::doctest cppIni) target_compile_definitions(${PROJECT_NAME}_tests PUBLIC @@ -18,3 +18,11 @@ target_include_directories(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/include ${DOCTEST_INCLUDE_DIR} ) + +find_file(DOCTEST_CMAKE doctest.cmake) +if(NOT DOCTEST_CMAKE) + message(FATAL_ERROR "Could not find doctest.cmake") +else() + include(${DOCTEST_CMAKE}) + doctest_discover_tests(${PROJECT_NAME}_tests) +endif() diff --git a/tests/constructionTest.cpp b/tests/ConstructionTest.cpp similarity index 85% rename from tests/constructionTest.cpp rename to tests/ConstructionTest.cpp index 4a98340..3de5fb3 100644 --- a/tests/constructionTest.cpp +++ b/tests/ConstructionTest.cpp @@ -1,9 +1,9 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include #include +#include TEST_CASE("Construction test") { - CHECK(one() == 1); + CHECK_EQ(one(), 1); }