Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
24 changes: 20 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand All @@ -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/
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down