Fix test-framework failure accounting for runtime errors - #596
Conversation
The TestBlock error handler in the interpreter had two bugs in how it recorded and counted test failures: 1. A test that failed with a runtime error (anything other than a failed `expect`) was pushed to the failures list but never incremented `failed_tests`, which is only bumped by ExpectStatement. The summary printed "Failed: 0" and the process exited 0, so a crashing test looked green to CI. 2. A failing assertion was recorded twice. The guard meant to skip already-recorded assertion failures compared the RuntimeError Display string (prefixed with "Runtime error at line ...:") against "Assertion failed:", so it never matched and every assertion failure was pushed to the failures list a second time. Fix: inspect the raw RuntimeError.message field (which does begin with "Assertion failed:") instead of the Display string, and increment failed_tests when recording a non-assertion runtime error. Now total == passed + failed, each failure is listed once, and the exit code is 1 whenever any test fails. Adds tests/test_framework_counting_test.rs covering runtime-error counting, single assertion recording, mixed suites, and first-failure short-circuiting, plus a Dev Diary entry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EcnZgma17a36Wc7VazYWG2
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughTest mode now counts runtime errors as failed tests, avoids duplicating assertion failures, stops failed test bodies, and adds regression tests and documentation for the resulting accounting behavior. ChangesTest mode failure accounting
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/interpreter/mod.rs (1)
7126-7138: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTrack assertion failures by kind, not by message prefix.
RuntimeErroralready hasErrorKind; taggingExpectStatementfailures asErrorKind::AssertionFailureand checkinge.kindhere would avoid relying on"Assertion failed:"and remove the collision risk.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/interpreter/mod.rs` around lines 7126 - 7138, Replace the message-prefix check in the test failure handling block with an ErrorKind-based check: ensure ExpectStatement-generated RuntimeErrors are tagged as ErrorKind::AssertionFailure, then use e.kind to exclude assertion failures in this logic. Update the relevant RuntimeError construction and the conditional near TestFailure creation, preserving existing failure tracking behavior for other error kinds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/interpreter/mod.rs`:
- Around line 7126-7138: Replace the message-prefix check in the test failure
handling block with an ErrorKind-based check: ensure ExpectStatement-generated
RuntimeErrors are tagged as ErrorKind::AssertionFailure, then use e.kind to
exclude assertion failures in this logic. Update the relevant RuntimeError
construction and the conditional near TestFailure creation, preserving existing
failure tracking behavior for other error kinds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: de1cc4c5-a3e2-450f-90c8-b2732634647d
📒 Files selected for processing (3)
Dev diary/2026-07-10-test-mode-failure-accounting.mdsrc/interpreter/mod.rstests/test_framework_counting_test.rs
Summary
Fixed two bugs in the
wfl --testtest-framework result accounting that caused runtime errors to be silently treated as passing tests and assertion failures to be double-reported in the failures list.Key Changes
Bug 1 — Runtime errors now count as failures: When a test body failed with a runtime error (e.g., undefined variable), the failure was recorded but
failed_testswas never incremented. This caused the summary to showFailed: 0and the process to exit 0, making crashing tests appear green to CI. Now runtime errors incrementfailed_testsalongside being recorded in the failures list.Bug 2 — Assertion failures no longer double-reported: The guard to skip already-recorded assertion failures compared the
Displaystring (which is prefixed with"Runtime error at line ...:") against"Assertion failed:", which never matched. Now the guard inspects the rawRuntimeError::messagefield, which correctly begins with"Assertion failed:"for assertion failures, preventing duplicate entries.Implementation Details
In
src/interpreter/mod.rs, theTestBlockerror handler now:e.message(the raw error message) instead ofe.to_string()(the Display form with line/column prefix) to correctly identify assertion failuresresults.failed_testswhen recording non-assertion runtime errors, ensuring the failure count is accurateDisplaystring in the failure record so line/column information is still visible to usersTesting
Added comprehensive regression tests in
tests/test_framework_counting_test.rs:total == passed + failedAll existing
.test.wflprograms and test-framework validation continue to pass.https://claude.ai/code/session_01EcnZgma17a36Wc7VazYWG2
Summary by CodeRabbit
Bug Fixes
Documentation