cargo-mutants icon indicating copy to clipboard operation
cargo-mutants copied to clipboard

Include mutant string names in json representation

Open sourcefrog opened this issue 11 months ago • 3 comments

sourcefrog avatar Jan 04 '25 17:01 sourcefrog

Hi, I’d be interested in taking this on if it’s still open.

My understanding is that you’d like the same human-readable mutant name string that cargo mutants --list prints (and that --re / --exclude-re match against) to be included as a field in the JSON representation – i.e., in the --list --json output and in mutants.out/mutants.json.

A couple of quick scoping questions:

  • Do you have any preference for the field name? I’d default to something simple like name.
  • Should this name string live only in the mutant definition JSON (--list --json + mutants.json), with tools joining that to outcomes.json as needed, or would you also like it duplicated in each entry in outcomes.json for convenience when post-processing results?

If this matches your intent, I’m happy to work on a PR.

0xLoopTheory avatar Nov 29 '25 08:11 0xLoopTheory

Yes, that all sounds good. I'd like it in both mutants and outcomes.

WIP PR https://github.com/sourcefrog/cargo-mutants/pull/564/files is adding dynamically generated fields to the generated JSON and shows a place they could be added.

sourcefrog avatar Nov 29 '25 21:11 sourcefrog

Thanks for the pointer to #564, that helps a lot.

Would you prefer that I:

  • help with #564 (tests/wiring/docs) to get it over the line first, and then add the name field on top of that,
    or
  • go ahead with this issue now, following the same pattern as in #564, and rebase/adjust once it’s merged?

Happy to do whichever is more useful for you. 🙂

0xLoopTheory avatar Nov 30 '25 19:11 0xLoopTheory

Actually I think we could just store the name string into the object when it's constructed, and let it be serialized by serde.

Message ID: @.***>

sourcefrog avatar Dec 05 '25 01:12 sourcefrog

Got it, that sounds good.

I’ll add a name: String field to Mutant and populate it when mutants are constructed, reusing the same formatting as the current --list output. That way serde will include it automatically in --list --json and mutants.json, and I can also reuse the stored name when building outcomes.json entries.

I’ll open a PR once that’s implemented and the tests are passing.

0xLoopTheory avatar Dec 05 '25 05:12 0xLoopTheory