convey icon indicating copy to clipboard operation
convey copied to clipboard

Provide a replacement for println

Open killercup opened this issue 7 years ago • 0 comments

Add a cargo feature that allows people to optionally pipe all println! (and similar) calls through convey, to make sure that all output is captured by us (to e.g. assert that only valid JSON documents can printed to stdout).

I'm not entirely sure how to best do this. Naively thinking I assume we can overwrite the macro exports from std and supply our own definitions that write to a globally registered convey::Output instance.

So, I'd try to do the following:

  • [ ] Add a cargo feature "println"
  • [ ] Add a .use_for_println() flag to the Output builder
  • [ ] Provide a macro definition for println! that uses format_args! and passes the string to either the globally set Output, or write to stdout directly (so it works like the original macro if you accidentally import our macro but don't have an associated Output)
  • [ ] Fill in the other relevant macros (print!, eprintln!, eprint!)
  • [ ] Test that common uses of the original macros work seamlessly
  • [ ] Test that JSON output works when using our println!

killercup avatar Nov 04 '18 18:11 killercup