Include diffs in JSON listings and mutants.json
- [x] Analyze the repository structure and understand the issue
- [x] Understand how mutant JSON serialization currently works
- [x] Identify that diffs are only included in JSON when --diff flag is used
- [x] Modify list_mutants to always include diff in JSON output
- [x] Update test snapshots to reflect the new behavior
- [x] Run cargo fmt and cargo test
- [x] Verify the change works correctly with manual testing
- [x] Update documentation (book/src/list.md and NEWS.md)
- [x] Include diffs in mutants.out/mutants.json written during test runs
- [x] Add test to verify mutants.out/mutants.json includes diffs
- [x] Refactor common code into Mutant::to_json() and mutants_to_json_string()
- [x] Fold test logic into existing uncaught_mutant_in_factorial test
Summary
Changed the JSON output behavior to always include diffs in:
-
--list --jsonoutput -
mutants.out/mutants.jsonwritten during test runs
This makes the JSON output more complete and useful for programmatic consumers.
Final Changes:
- Added
Mutant::to_json()method that includes the diff field - Added
mutants_to_json_string()helper function insrc/list.rs - Refactored both
list_mutants()andwrite_mutants_list()to use the common code - Folded test validation into existing
uncaught_mutant_in_factorialtest to save test time - Updated test snapshots to reflect the new behavior
- Updated documentation in
book/src/list.mdandNEWS.md
Testing:
- All existing tests pass (24 list tests, 50 main tests)
- Diff validation now part of existing test that runs on the factorial tree
- Manual testing confirms JSON output includes diffs by default
- Text output behavior remains unchanged (still requires --diff flag)
Original prompt
This section details on the original issue you should resolve
<issue_title>Include the diff as a text field within the json representation of mutants</issue_title> <issue_description></issue_description>
Comments on the Issue (you are @copilot in this section)
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
@copilot Please check that the diff is also included in mutants.out/mutants.json written when running the mutant tests. It looks like it's only in the list output. Add one test to check that it's in there too.
@copilot Please check that the diff is also included in
mutants.out/mutants.jsonwritten when running the mutant tests. It looks like it's only in the list output. Add one test to check that it's in...
Done! The diff is now included in mutants.out/mutants.json. I've:
- Modified
write_mutants_list()insrc/output.rsto include diffs when serializing mutants - Added test
mutants_json_includes_diffsthat verifies all mutants inmutants.out/mutants.jsonhave a diff field with valid unified diff content - Updated the snapshot for the existing
uncaught_mutant_in_factorialtest to reflect the new format
Commit: 9b0ac85