defmt icon indicating copy to clipboard operation
defmt copied to clipboard

Allow std-level unit testing of the formatting itself

Open nyurik opened this issue 7 months ago • 2 comments

In my crate, I have many enums declared with #[derive(defmt::Format)].

I would like to check that the format output is what I expect without requiring real hardware or an emulator. defmt has internal encoding tests in the https://github.com/knurling-rs/defmt/blob/main/defmt/tests/encode.rs , but the write_format fn uses private function _format_data to do some magical formatting. Is there a way to have a well defined API I can use in the regular std environment to check the format trait output? Perhaps introduce some test helper that simply returns a String?

nyurik avatar May 08 '25 05:05 nyurik

https://github.com/gibbz00/redefmt/blob/4750be6195578456c75667487d4d446ba375f932/crates/pretty_printer/src/lib.rs#L333-L352 👀

WIP though, hope to share more very soon.

gibbz00 avatar Jun 02 '25 12:06 gibbz00

I think this use case ~~is~~ will be handled by https://github.com/knurling-rs/defmt/issues/969?

jonathanpallant avatar Jun 03 '25 14:06 jonathanpallant