Skip to content

fix(coverage): make coverage analyze fail when tests fail#1397

Draft
peter-jerry-ye wants to merge 1 commit intomainfrom
fix/coverage-analyze-test-failure
Draft

fix(coverage): make coverage analyze fail when tests fail#1397
peter-jerry-ye wants to merge 1 commit intomainfrom
fix/coverage-analyze-test-failure

Conversation

@peter-jerry-ye
Copy link
Contributor

Summary

Fixed the issue where moon coverage analyze would continue to execute the coverage report analysis even when moon test --enable-coverage failed.

Problem

The run_coverage_analyze function was discarding the exit code from run_test using the ? operator, which only propagated errors (not Ok values). This meant that when tests failed (returning exit code 2), the coverage analysis would still proceed, generating reports based on incomplete or invalid coverage data.

Solution

Modified crates/moon/src/cli/coverage.rs to:

  1. Capture the test result exit code instead of discarding it
  2. Check if the result is non-zero and return early with the failure exit code

Changes

  • Fix: crates/moon/src/cli/coverage.rs - Added early return when tests fail
  • Test: Added test_moon_coverage_analyze_fails_on_test_failure regression test
  • Test data: Added test_coverage_fail_test.in test case with a failing test

Verification

  • All 272 moon tests pass (including 3 coverage tests)
  • Clippy shows no warnings
  • Code is properly formatted

@semanticdiff-com
Copy link

semanticdiff-com bot commented Jan 20, 2026

@peter-jerry-ye peter-jerry-ye force-pushed the fix/coverage-analyze-test-failure branch from e7f1deb to d5d0a63 Compare January 20, 2026 07:52
The coverage analyze command now properly propagates test failures while still
generating the coverage report. Previously, it would ignore test failures and
return success if the coverage report was generated successfully.

Behavior:
- Always generate the coverage report (useful for debugging)
- Propagate the test result exit code (2 for test failures)
- Only return an error if the coverage report itself fails

Includes a regression test with a failing test case to prevent future
regressions.
@peter-jerry-ye peter-jerry-ye force-pushed the fix/coverage-analyze-test-failure branch from d5d0a63 to 484e15c Compare January 20, 2026 08:17
@peter-jerry-ye peter-jerry-ye marked this pull request as draft January 28, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant