diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61fafa9..038f617 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: needs: generate-data strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm64] + os: [ubuntu-latest, macos-latest, windows-latest] ujson_use_rapidjson: ["OFF", "ON"] runs-on: ${{ matrix.os }} name: build-test (${{ matrix.os }}, RapidJSON=${{ matrix.ujson_use_rapidjson }}) @@ -61,18 +61,34 @@ jobs: - name: Configure run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release -DUJSON_USE_RAPIDJSON=${{ matrix.ujson_use_rapidjson }} + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON -DUJSON_USE_RAPIDJSON=${{ matrix.ujson_use_rapidjson }} - name: Build run: | - cmake --build build --config Release -j 4 + cmake --build build --config Debug -j 4 - name: Run Tests shell: bash run: | cd build if [[ "${{ runner.os }}" == "Windows" ]]; then - ./Release/test_main + ./Debug/test_main else ./test_main fi + + - name: Collect Coverage (Linux/Mac) + if: runner.os != 'Windows' + run: | + # 创建覆盖率存放目录 + mkdir -p coverage_data + # 查找所有生成的 .gcda 和 .gcno 文件并复制(保持目录结构平铺或打包) + find build -name "*.gcda" -exec cp {} coverage_data/ \; + find build -name "*.gcno" -exec cp {} coverage_data/ \; + + - name: Upload Coverage Artifacts + if: runner.os != 'Windows' + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.os }}-${{ matrix.ujson_use_rapidjson }} + path: coverage_data/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4edc28e..5ebfbd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,14 @@ project(tokenizer LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(ENABLE_COVERAGE "Enable code coverage" OFF) +if(ENABLE_COVERAGE) + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + add_compile_options(--coverage) + add_link_options(--coverage) + endif() +endif() + # Include directories include_directories(include) include_directories(third_party)