From ca17984d98c38e3bcd81d2c2f499183a959fadc5 Mon Sep 17 00:00:00 2001 From: Ryan Walters Date: Sat, 6 Sep 2025 14:51:23 -0500 Subject: [PATCH] feat: use cfg-based coverage exclusion to replace 'ignore-filename-regex' option, setup coveralls & nightly-based coverage --- .github/workflows/coverage.yaml | 15 +++++++-------- Cargo.toml | 3 +++ Justfile | 28 ++++++---------------------- src/bin/aspect_demo.rs | 3 +++ src/bin/timing_demo.rs | 3 +++ src/lib.rs | 14 +++++++++++--- src/main.rs | 16 ++++++++++++---- src/systems/debug.rs | 6 ++++-- src/systems/mod.rs | 4 ++++ 9 files changed, 53 insertions(+), 39 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 59d1993..f9be691 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -4,7 +4,7 @@ on: ["push", "pull_request"] env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: 1.86.0 + RUST_TOOLCHAIN: nightly jobs: coverage: @@ -46,12 +46,11 @@ jobs: - name: Generate coverage report run: | - just coverage-codecov + just coverage-lcov - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 + - name: Coveralls upload + uses: coverallsapp/github-action@v2 with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./codecov.json - disable_search: true - verbose: true + github-token: ${{ secrets.COVERALLS_REPO_TOKEN }} + path-to-lcov: lcov.info + debug: true diff --git a/Cargo.toml b/Cargo.toml index 869c717..08f0f37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,3 +98,6 @@ x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md" } x86_64-unknown-linux-gnu = { triplet = "x64-linux" } x86_64-apple-darwin = { triplet = "x64-osx" } aarch64-apple-darwin = { triplet = "arm64-osx" } + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage,coverage_nightly)'] } diff --git a/Justfile b/Justfile index 96cf89a..fcf6626 100644 --- a/Justfile +++ b/Justfile @@ -1,9 +1,6 @@ set shell := ["bash", "-c"] set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] -# Regex to exclude files from coverage report, double escapes for Justfile + CLI -# You can use src/..., but the filename alone is acceptable too -coverage_exclude_pattern := "src/app\\.rs|audio\\.rs|src/error\\.rs|platform/emscripten\\.rs|bin/.+\\.rs|main\\.rs|platform/desktop\\.rs|platform/tracing_buffer\\.rs|platform/buffered_writer\\.rs|systems/debug\\.rs|systems/profiling\\.rs" binary_extension := if os() == "windows" { ".exe" } else { "" } @@ -11,39 +8,26 @@ binary_extension := if os() == "windows" { ".exe" } else { "" } # !!! --remap-path-prefix prevents the absolute path from being used in the generated report # Generate HTML report (for humans, source line inspection) -html: coverage-lcov +html: coverage cargo llvm-cov report \ --remap-path-prefix \ - --ignore-filename-regex "{{ coverage_exclude_pattern }}" \ --html \ --open # Display report (for humans) -report-coverage: coverage-lcov - cargo llvm-cov report \ - --remap-path-prefix \ - --ignore-filename-regex "{{ coverage_exclude_pattern }}" +report-coverage: coverage + cargo llvm-cov report --remap-path-prefix # Run & generate LCOV report (as base report) -coverage-lcov: - cargo llvm-cov \ +coverage: + cargo +nightly llvm-cov \ --lcov \ --remap-path-prefix \ - --ignore-filename-regex "{{ coverage_exclude_pattern }}" \ + --workspace \ --output-path lcov.info \ --profile coverage \ --no-fail-fast nextest -# Run & generate Codecov report (for CI) -coverage-codecov: - cargo llvm-cov \ - --codecov \ - --remap-path-prefix \ - --ignore-filename-regex "{{ coverage_exclude_pattern }}" \ - --output-path codecov.json \ - --profile coverage \ - --no-fail-fast nextest - # Profile the project using 'samply' samply: cargo build --profile profile diff --git a/src/bin/aspect_demo.rs b/src/bin/aspect_demo.rs index 53fa6b7..137370e 100644 --- a/src/bin/aspect_demo.rs +++ b/src/bin/aspect_demo.rs @@ -1,3 +1,6 @@ +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] +#![cfg_attr(coverage_nightly, coverage(off))] + use std::time::{Duration, Instant}; use sdl2::event::Event; diff --git a/src/bin/timing_demo.rs b/src/bin/timing_demo.rs index ad6101d..68cf2fd 100644 --- a/src/bin/timing_demo.rs +++ b/src/bin/timing_demo.rs @@ -1,3 +1,6 @@ +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] +#![cfg_attr(coverage_nightly, coverage(off))] + use circular_buffer::CircularBuffer; use pacman::constants::CANVAS_SIZE; use sdl2::event::Event; diff --git a/src/lib.rs b/src/lib.rs index b849806..607286b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,22 @@ //! Pac-Man game library crate. +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] +#[cfg_attr(coverage_nightly, coverage(off))] pub mod app; -pub mod asset; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod audio; -pub mod constants; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod error; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod events; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod formatter; +#[cfg_attr(coverage_nightly, coverage(off))] +pub mod platform; + +pub mod asset; +pub mod constants; pub mod game; pub mod map; -pub mod platform; pub mod systems; pub mod texture; diff --git a/src/main.rs b/src/main.rs index 715fbc1..1a9153f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,27 @@ // Note: This disables the console window on Windows. We manually re-attach to the parent terminal or process later on. #![windows_subsystem = "windows"] +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] use crate::{app::App, constants::LOOP_TIME}; use tracing::info; +#[cfg_attr(coverage_nightly, coverage(off))] mod app; -mod asset; +#[cfg_attr(coverage_nightly, coverage(off))] mod audio; -mod constants; - +#[cfg_attr(coverage_nightly, coverage(off))] mod error; +#[cfg_attr(coverage_nightly, coverage(off))] mod events; +#[cfg_attr(coverage_nightly, coverage(off))] mod formatter; +#[cfg_attr(coverage_nightly, coverage(off))] +mod platform; + +mod asset; +mod constants; mod game; mod map; -mod platform; mod systems; mod texture; @@ -22,6 +29,7 @@ mod texture; /// /// This function initializes SDL, the window, the game state, and then enters /// the main game loop. +#[cfg_attr(coverage_nightly, coverage(off))] pub fn main() { // On Windows, this connects output streams to the console dynamically // On Emscripten, this connects the subscriber to the browser console diff --git a/src/systems/debug.rs b/src/systems/debug.rs index 75e9dbd..01109ff 100644 --- a/src/systems/debug.rs +++ b/src/systems/debug.rs @@ -1,6 +1,5 @@ //! Debug rendering system -use std::cmp::Ordering; - +#[cfg_attr(coverage_nightly, feature(coverage_attribute))] use crate::constants::{self, BOARD_PIXEL_OFFSET}; use crate::map::builder::Map; use crate::systems::{Collider, CursorPosition, NodeId, Position, SystemTimings}; @@ -13,6 +12,7 @@ use sdl2::rect::{Point, Rect}; use sdl2::render::{Canvas, Texture}; use sdl2::video::Window; use smallvec::SmallVec; +use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; use tracing::warn; @@ -149,6 +149,7 @@ fn transform_position_with_offset(pos: Vec2, scale: f32) -> IVec2 { } /// Renders timing information in the top-left corner of the screen using the debug text atlas +#[cfg_attr(coverage_nightly, coverage(off))] fn render_timing_display( canvas: &mut Canvas, timings: &SystemTimings, @@ -203,6 +204,7 @@ fn render_timing_display( } #[allow(clippy::too_many_arguments)] +#[cfg_attr(coverage_nightly, coverage(off))] pub fn debug_render_system( canvas: &mut Canvas, ttf_atlas: &mut TtfAtlasResource, diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 7ddff9f..63d89dc 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -3,17 +3,21 @@ //! This module contains all the ECS-related logic, including components, systems, //! and resources. +#[cfg_attr(coverage_nightly, coverage(off))] pub mod audio; pub mod blinking; pub mod collision; pub mod components; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod debug; pub mod ghost; pub mod input; pub mod item; pub mod movement; pub mod player; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod profiling; +#[cfg_attr(coverage_nightly, coverage(off))] pub mod render; pub mod stage;