zmatrix 0.4.12

Compile-time dimensional analysis & physics-aware linear algebra for aerospace and robotics
Documentation
name: Rust Coverage

on: [push, pull_request]

jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    # 安装 Rust 和工具链
    - name: Setup Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        components: llvm-tools-preview
        profile: minimal

    # 安装 grcov
    - name: Install grcov
      run: cargo install grcov

    # 生成覆盖率报告(需设置环境变量)
    #
    # 必须跑两次:`constant.rs` 与 `PhysicalQuantity::raw_value` 在
    # `feature = "tmr"` 开与关时是不同的代码路径(前者 RwLock vs const,
    # 后者存在与不存在)。只跑默认配置会让 tmr 那一侧完全不进覆盖率。
    #
    # `cargo test --tests` 不含 doctest,所以 doc 测试单独跑——它是正确性
    # 检查,不参与覆盖率统计(doctest 在 instrument-coverage 下的 profraw
    # 不落在工作目录,收不上来)。
    #
    # `build.rs` 被排除:构建脚本在 `cargo test` 的编译阶段就执行完毕,
    # 测试运行时不会再跑它,所以它生成的 profraw 里从来没有它的记录。
    # 这不是"漏测",是结构性无法覆盖——留着只会让 patch 覆盖率被一段
    # 永远不可能执行到的代码拉低。
    #
    # 它的可测逻辑(解析、校验、生成源码)已经抽到 `build_support.rs`,
    # 由 `src/lib.rs` 在 cfg(test) 下引入并单测(15 个用例)。所以排除
    # `build.rs` 排掉的只是"读环境变量 + 写文件"这几行胶水,不是把校验
    # 逻辑一并跳过。
    - name: Run tests with coverage
      run: |
        export RUSTFLAGS="-Cinstrument-coverage"
        export LLVM_PROFILE_FILE="rust-coverage-%p-%m.profraw"

        # 默认配置:覆盖 not(feature = "tmr") 分支
        cargo test --tests

        # 全量 feature:覆盖 feature = "tmr" 分支
        cargo test --tests --features tmr

        # 文档示例(正确性,不计覆盖率)
        cargo test --doc
        cargo test --doc --features tmr

        mkdir -p ./coverage  # 新增:确保目录存在
        grcov . \
          --binary-path ./target/debug/ \
          -s . \
          --branch \
          --ignore-not-existing \
          --ignore "/*" \
          --ignore "build.rs" \
          --ignore "examples/*" \
          --ignore "benches/*" \
          --ignore "src/tests/*" \
          -t lcov \
          -o ./coverage/lcov.info

    # 上传到 Codecov
    - name: Upload to Codecov
      uses: codecov/codecov-action@v5
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        slug: Treagzhao/zmatrix
        files: ./coverage/lcov.info
        verbose: true